diff options
| -rw-r--r-- | src/features/messages.js | 26 | ||||
| -rw-r--r-- | src/style.css | 4 | ||||
| -rw-r--r-- | tools/feed-when-test.js | 11 |
3 files changed, 29 insertions, 12 deletions
diff --git a/src/features/messages.js b/src/features/messages.js index 6b3ff4c..72707a5 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -5445,7 +5445,7 @@ export function messagesFeature(ctx) { } // How far back you've scrolled: while the feed (or a profile's posts) // moves, a small chip under the top bar says when the post at the top of - // the screen was written, and fades a moment after the scrolling stops + // the screen was written, and goes the moment the scrolling stops // ("some sort of little counter that shows the date and time of posts // where I'm in the timeline", Adam, 2026-11-17). Painted straight into the // DOM, outside render(): it changes every frame of a fling. @@ -5476,13 +5476,22 @@ export function messagesFeature(ctx) { const head = document.querySelector('.brand-header'); const top = head ? Math.max(0, head.getBoundingClientRect().bottom) : 0; // the post at the top of the screen, below the bar - let key = null, box = null; - for (const r of rows) { - const b = r.getBoundingClientRect(); - if (b.bottom > top + 12) { key = r.getAttribute('data-key'); box = r.parentElement.getBoundingClientRect(); break; } + let key = null, box = null, frac = 0, nextKey = null; + for (let i = 0; i < rows.length; i++) { + const b = rows[i].getBoundingClientRect(); + if (b.bottom <= top + 12) continue; + key = rows[i].getAttribute('data-key'); + box = rows[i].parentElement.getBoundingClientRect(); + // how far through this post the top of the screen is, to blend its + // time toward the next post's: the clock rolls with the scroll + // instead of jumping post to post ("I'm good with blending", Adam) + frac = b.height > 0 ? Math.min(1, Math.max(0, (top + 12 - b.top) / b.height)) : 0; + nextKey = rows[i + 1]?.getAttribute('data-key'); + break; } if (whenIdx.list !== list) whenIdx = { list, map: list ? new Map(list.map((e) => [e.id, e])) : null }; const ev = key && whenIdx.map?.get(key); + const next = nextKey && whenIdx.map?.get(nextKey); // only once you're past the first screenful: at the top the posts' own times say it if (!ev || (window.scrollY || 0) < window.innerHeight * 0.75) { if (whenEl) whenEl.classList.remove('on'); return; } if (!whenEl) { @@ -5491,13 +5500,16 @@ export function messagesFeature(ctx) { whenEl.setAttribute('aria-hidden', 'true'); document.body.appendChild(whenEl); } - const label = whenLabel(ev.created_at); + const label = whenLabel(next ? ev.created_at + (next.created_at - ev.created_at) * frac : ev.created_at); if (whenEl.textContent !== label) whenEl.textContent = label; whenEl.style.top = (top + 8) + 'px'; whenEl.style.left = (box.left + box.width / 2) + 'px'; whenEl.classList.add('on'); clearTimeout(whenHide); - whenHide = setTimeout(() => whenEl && whenEl.classList.remove('on'), 1200); + // gone as soon as you stop to read ("I want it gone as soon as I'm + // stopped to look at something", Adam): a coast keeps sending scroll + // events, so this only fires once the page is still + whenHide = setTimeout(() => whenEl && whenEl.classList.remove('on'), 250); }); } async function loadOlderNotes(pk) { diff --git a/src/style.css b/src/style.css index 633d7f6..4024f3b 100644 --- a/src/style.css +++ b/src/style.css @@ -2208,6 +2208,6 @@ html:has(.call-overlay:not(.call-min)) { overflow: hidden; scrollbar-gutter: aut border: 1px solid var(--line-strong); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: 0 2px 10px rgba(0, 0, 0, .14); - pointer-events: none; opacity: 0; transition: opacity .25s, transform .25s; + pointer-events: none; opacity: 0; transition: opacity .12s, transform .12s; } -.feed-when.on { opacity: 1; transform: translate(-50%, 0); } +.feed-when.on { opacity: 1; transform: translate(-50%, 0); transition-duration: .08s; } diff --git a/tools/feed-when-test.js b/tools/feed-when-test.js index d9baa50..38be4ef 100644 --- a/tools/feed-when-test.js +++ b/tools/feed-when-test.js @@ -119,11 +119,16 @@ try { }); const ev = shown && seeded.find((e) => e.id === shown.key); check('the chip shows while scrolling, under the top bar', !!shown && shown.y >= shown.head, JSON.stringify(shown)); - const want = ev && await page.evaluate((s) => new Date(s * 1000).toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }), ev.created_at); - check('...with the time of the post at the top of the screen', !!want && shown.text.includes(want), shown?.text + ' / ' + want); + // seeded posts are two hours apart: the chip's minute is one of those between this post and the next + const between = ev && await page.evaluate((s) => Array.from({ length: 121 }, (_, m) => new Date((s - m * 60) * 1000).toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' })), ev.created_at); + check('...with a time between the top post and the next', !!between && between.some((x) => shown.text.includes(x)), shown?.text); check('...and how long ago', /ago|yesterday/i.test(shown?.text || ''), shown?.text); if (process.env.SHOT) await page.screenshot({ path: process.env.SHOT }); - await sleep(1700); + // the clock rolls between posts: a few px down the same post moves it on + const at = (y) => page.evaluate(async (y) => { scrollBy(0, y); await new Promise((r) => setTimeout(r, 60)); return document.querySelector('.feed-when')?.textContent; }, y); + const a = await at(1), b = await at(60); + check('the time blends between posts as you scroll', !!a && !!b && a !== b, a + ' → ' + b); + await sleep(450); check('it fades once the scrolling stops', !(await page.$('.feed-when.on'))); check('no page errors', !errors.length, errors.join('; ')); } finally { |
