From 0485c5ae5b595539a9d141bad7dcc98902016ff0 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 20:26:28 +0000 Subject: [PATCH 1/2] Show live sync status next to the JavStore controls (6.13.0) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A tab opened during a long sync starts from the history as it was before it, and on AdGuard downloads the whole history again itself. A status pill now shows when to wait: - "Downloading history… N visits" / "Syncing… N visits" while this tab's exchange runs longer than a moment (quick syncs show nothing); - "Waiting for another tab to sync…" while this tab's sync is queued on the shared Web Lock; - "Another tab is syncing…" in the tab in view, found by asking the browser whether the sync lock is held (navigator.locks.query, every 2 s, only while visible); AdGuard tabs cannot read each other's storage, but they do share Web Locks; - "Sync complete" for a few seconds afterwards. The test harness's Web Locks stand-in now answers query(). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VCuhK4TQqcEbLXdmxLjggy --- CHANGELOG.md | 12 +++ README.md | 1 + javstore-full-layout-cleanup.user.js | 145 ++++++++++++++++++++++++++- tests/harness.mjs | 16 ++- tests/review-lifecycle.test.mjs | 6 +- tests/sync-status.test.mjs | 95 ++++++++++++++++++ worker/src/worker.mjs | 2 +- 7 files changed, 267 insertions(+), 10 deletions(-) create mode 100644 tests/sync-status.test.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index b9dc4b2..24085c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## 6.13.0 + +- Add: a live sync status next to the JavStore controls, so you can tell when a sync is still running and wait before opening new tabs. A tab opened during a long sync starts from the history as it was before the sync, and on AdGuard it then downloads the whole history again itself. + - **Downloading history… N visits** while this tab downloads a large history, such as the first sync after an update, with the count so far. + - **Syncing… N visits** while a longer sync runs. A quick sync shows nothing. + - **Waiting for another tab to sync…** while this tab's sync waits for another tab's to finish. + - **Another tab is syncing…** in the tab you are looking at, while any other JavStore tab syncs. + - **Sync complete** for a few seconds once a sync you could see finishes: new tabs opened from then on start from the downloaded history. +- How it works: AdGuard does not let a tab read what another tab saved, but every JavStore tab shares the sync's Web Lock, and the browser can say whether that lock is held. Only the tab in view asks, every two seconds, and nothing is stored or sent anywhere. Browsers without Web Locks show only the tab's own sync. +- Tapping the status opens the settings panel. Hover over it for why waiting helps. +- The worker version moves to 6.13.0 with the userscript; the worker is unchanged. + ## 6.12.0 A review of the whole history and sync design against how AdGuard actually stores userscript data. AdGuard for Mac, Windows and Android give each tab the stored values as they were when the tab loaded, and a tab never sees what other tabs save after that. The script had been designed as if every tab read the same, current storage. With many tabs left open, that broke in several ways, each now covered by a test that reproduces it. diff --git a/README.md b/README.md index 13933f9..d15795f 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Once it is deployed, open the `JVS` panel → **Cloud sync**, enter the worker U - The Cloud sync panel shows the worker version from the worker's last answer. When the worker is behind the userscript, a **⚠ Redeploy worker** button appears on screen next to the JavStore controls; tap it for the versions. The worker redeploys through Cloudflare whenever `main` changes, so a lasting warning means its Cloudflare build did not go through. When the worker is ahead instead, an **⚠ Update script** button appears on screen and links to the latest release, because the userscript manager has not installed it yet. - AdGuard for Android clears a userscript's storage whenever it installs an update. After setting sync up, press **Copy sync link** and keep the link somewhere private, such as a password manager. After a wipe, open it on JavStore, or paste it into the endpoint box and save, to set everything up again. The link carries your token, so treat it like a password. - The endpoint and token live only on the device they were entered on. They are never written into the synced document, never appear in an exported backup, and are not left in the page: the token box stays empty once a token is stored and only reports that one exists. +- A status next to the JavStore controls shows a sync that is still running: **Downloading history…** with the number of visits so far, **Waiting for another tab to sync…**, **Another tab is syncing…** (found through the sync's shared Web Lock, which needs no storage), and **Sync complete** when it is done. A tab opened during a long download starts without what it downloads and fetches it again itself, so it is worth waiting for **Sync complete** before opening many tabs, especially after an update. - A worker that is unreachable does not affect anything locally: history is still saved to the userscript manager, and the next sync picks it up. Failed or incomplete restoration is not marked complete. If local history is actually lost, recovery bypasses the session marker and downloads it again; **Restored … visited URLs** reports that recovery, not ordinary page navigation. A history that is merely behind catches up on the difference without the note. - Current browsers coordinate cloud work with Web Locks, and no tab holds them for more than five minutes. Managers that notify tabs of each other's writes fall back to a userscript-storage lease where Web Locks are missing; elsewhere tabs sync side by side, which costs at most a duplicate request. Session metadata stays in userscript-manager storage; credentials and history are not placed in page `localStorage`. - **Sync now** reports both directions—what went up and what came down—so a device that is failing to push is not mistaken for one with nothing to push. diff --git a/javstore-full-layout-cleanup.user.js b/javstore-full-layout-cleanup.user.js index aefc20d..b0bd0e4 100644 --- a/javstore-full-layout-cleanup.user.js +++ b/javstore-full-layout-cleanup.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name JavStore Full Layout Cleanup - No Sidebars + Mosaic Overlay // @namespace http://tampermonkey.net/ -// @version 6.12.0 +// @version 6.13.0 // @description Clean up JavStore's layout, filter keyword-matched thumbnails, and track visited items with private, configurable controls. // @homepageURL https://github.com/jitdor/userscript-javstore // @supportURL https://github.com/jitdor/userscript-javstore/issues @@ -29,7 +29,7 @@ (function () { 'use strict'; - const SCRIPT_VERSION = '6.12.0'; + const SCRIPT_VERSION = '6.13.0'; // The same address as @downloadURL: opening it hands the newest release to the // userscript manager, which offers to install it. const INSTALL_URL = 'https://github.com/jitdor/userscript-javstore/releases/latest/download/javstore-full-layout-cleanup.user.js'; @@ -69,6 +69,7 @@ const SYNC_LEASE_KEY = 'javstore_sync_lease_v1'; const SYNC_SESSION_IDLE_MS = 30 * 60000; const SYNC_LEASE_MS = 90000; + const SYNC_LOCK_NAME = 'javstore-cloud-sync-v1'; // The longest one exchange may hold the sync lock. Its requests time out long before; // this is for whatever else could hang, so one stuck tab cannot stop every tab syncing. const SYNC_HOLD_MS = 5 * 60000; @@ -196,6 +197,21 @@ let remoteWorkerVersion = ''; let lastRemoteError = ''; let remoteSyncRunning = false; + // What the on-page sync status shows. A tab cannot read another tab's progress from + // storage on AdGuard, but every tab of the site shares the sync's Web Lock, and asking + // the browser whether it is held needs no storage at all. + const syncView = { + waitingSince: 0, // this tab's sync is queued behind another tab's + exchangeSince: 0, // this tab is talking to the worker + rows: 0, // rows this exchange has downloaded so far + downloading: false, // more of the history is still to come + otherTab: false, // another tab holds the sync lock + heldPolls: 0, + shown: false, + doneUntil: 0, + timer: 0, + pollTimer: 0, + }; let applyingRemoteState = false; // A merge can absorb protective metadata—a tombstone, a newer `resetAt`, `prunedBefore` // or `settingsUpdatedAt`—without removing anything that is on screen, so @@ -1855,7 +1871,18 @@ // Syncs are queued for the same reason writes are: two overlapping merge cycles would // each build on a snapshot the other has already moved past. function queueSync(options = {}) { - const run = () => withSyncLock(() => runSync(options)); + const run = () => { + const queuedAt = Date.now(); + syncView.waitingSince = queuedAt; + refreshLiveSync(); + return withSyncLock(() => { + syncView.waitingSince = 0; + return runSync(options); + }).finally(() => { + if (syncView.waitingSince === queuedAt) syncView.waitingSince = 0; + refreshLiveSync(); + }); + }; remoteQueue = remoteQueue.then(run, run).catch(error => { lastRemoteError = String(error?.message || 'sync failed'); if (options.manual) showToast(`Sync failed: ${lastRemoteError}`, true); @@ -1877,7 +1904,7 @@ // cannot stop every other tab from syncing. Its requests time out well before. const bounded = () => withTimeout(action(), SYNC_HOLD_MS, 'the sync took too long'); if (navigator.locks?.request) { - return navigator.locks.request('javstore-cloud-sync-v1', async () => { + return navigator.locks.request(SYNC_LOCK_NAME, async () => { if (pageClosed) return false; return bounded(); }); @@ -2013,6 +2040,10 @@ let downloadComplete = false; let uploadedMeta = ''; let restarted = false; + syncView.exchangeSince = Date.now(); + syncView.rows = 0; + syncView.downloading = reconciling; + refreshLiveSync(); for (let page = 0; page < MAX_SYNC_PAGES; page += 1) { const batch = outgoing.slice(0, REMOTE_PAGE_ROWS); @@ -2089,6 +2120,9 @@ if (lastMergeAdopted) absorbed = true; applyingRemoteState = false; downloadComplete = !answer.more; + syncView.rows += Array.isArray(answer.changes) ? answer.changes.length : 0; + syncView.downloading = Boolean(answer.more); + refreshLiveSync(); if (reconciling && downloadComplete) { reconciling = false; outgoing = reconcileWith(pulledAt, tag); @@ -2147,6 +2181,14 @@ if (manual) showToast(`Sync failed: ${lastRemoteError}`, true); return false; } finally { + if (syncView.exchangeSince) { + syncView.exchangeSince = 0; + syncView.downloading = false; + // A sync the user saw running says when it is over, so they know new tabs + // will start from the downloaded history. + if (syncView.shown) syncView.doneUntil = Date.now() + 3000; + refreshLiveSync(); + } applyingRemoteState = false; remoteSyncRunning = false; if (deferredRemotePush) { @@ -2243,6 +2285,82 @@ return `synced at ${new Date(lastRemoteSyncAt).toLocaleTimeString()}`; } + // Shown only once a sync has taken longer than a moment, so quick syncs do not flicker. + const LIVE_SYNC_DELAY_MS = 600; + + function describeLiveSync(now = Date.now()) { + if (!syncConfigured()) return null; + const rows = syncView.rows ? ` ${syncView.rows.toLocaleString()} visits` : ''; + if (syncView.exchangeSince && now - syncView.exchangeSince >= LIVE_SYNC_DELAY_MS) { + return syncView.downloading + ? { text: `Downloading history…${rows}`, busy: true, hint: true } + : { text: `Syncing…${rows}`, busy: true, hint: false }; + } + if (syncView.waitingSince && now - syncView.waitingSince >= LIVE_SYNC_DELAY_MS) { + return { text: 'Waiting for another tab to sync…', busy: true, hint: true }; + } + if (syncView.otherTab) return { text: 'Another tab is syncing…', busy: true, hint: true }; + if (syncView.doneUntil > now) return { text: 'Sync complete', busy: false, hint: false }; + return null; + } + + function renderLiveSync() { + if (!ui?.syncStatus) return; + const now = Date.now(); + const status = describeLiveSync(now); + syncView.shown = Boolean(status?.busy); + ui.syncStatus.hidden = !status; + if (!status) return; + ui.syncStatus.textContent = status.text; + ui.syncStatus.classList.toggle('busy', status.busy); + ui.syncStatus.title = status.hint + ? 'Tabs opened before this finishes start without what it downloads, and download it again themselves. Wait for "Sync complete" before opening new tabs.' + : ''; + } + + // Renders now, and again once the delay has passed or the "complete" note has run out. + function refreshLiveSync() { + renderLiveSync(); + window.clearTimeout(syncView.timer); + const now = Date.now(); + const pending = [ + syncView.exchangeSince && syncView.exchangeSince + LIVE_SYNC_DELAY_MS, + syncView.waitingSince && syncView.waitingSince + LIVE_SYNC_DELAY_MS, + syncView.doneUntil, + ].filter(at => at && at > now); + if (pending.length) syncView.timer = window.setTimeout(refreshLiveSync, Math.min(...pending) - now + 20); + } + + // Whether another tab holds the sync lock, asked of the browser every couple of seconds + // while this tab is in view. A lock held for a moment is an ordinary quick sync, so it + // only counts once two checks in a row find it held. + async function pollOtherTabSync() { + if (!syncConfigured() || document.visibilityState === 'hidden' || typeof navigator.locks?.query !== 'function') { + syncView.heldPolls = 0; + } else { + try { + const { held = [] } = await navigator.locks.query(); + const ours = remoteSyncRunning || syncView.waitingSince; + const heldElsewhere = !ours && held.some(lock => lock.name === SYNC_LOCK_NAME); + syncView.heldPolls = heldElsewhere ? syncView.heldPolls + 1 : 0; + } catch (error) { + syncView.heldPolls = 0; + } + } + const otherTab = syncView.heldPolls >= 2; + if (otherTab !== syncView.otherTab) { + if (syncView.otherTab && !otherTab) syncView.doneUntil = Date.now() + 3000; + syncView.otherTab = otherTab; + refreshLiveSync(); + } + } + + function startOtherTabPolling() { + window.clearInterval(syncView.pollTimer); + if (typeof navigator.locks?.query !== 'function') return; + syncView.pollTimer = window.setInterval(pollOtherTabSync, 2000); + } + settings = sanitizeSettings(); visited = new Map(); overrides = new Map(); @@ -3034,6 +3152,14 @@ .warning { padding: 8px; border-radius: 8px; color: #fecaca; background: #7f1d1d; } .warning a { color: #fff; } .pill.update, .pill.redeploy { border-color: #fca5a5; background: #991b1b; } + .pill.sync-status { border-color: #86efac; background: #166534; } + .pill.sync-status.busy { border-color: #93c5fd; background: #1e3a8a; } + .pill.sync-status.busy::before { + content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 8px; + border: 2px solid #bfdbfe; border-right-color: transparent; border-radius: 50%; + vertical-align: -1px; animation: jvs-spin .8s linear infinite; + } + @keyframes jvs-spin { to { transform: rotate(360deg); } } .pill.update:hover, .pill.redeploy:hover { background: #7f1d1d; } .pill[hidden], .warning[hidden] { display: none; } .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } @@ -3070,11 +3196,15 @@ .grid { grid-template-columns: 1fr; } .full { grid-column: auto; } } - @media (prefers-reduced-motion: reduce) { .toast { transition: none; } } + @media (prefers-reduced-motion: reduce) { + .toast { transition: none; } + .pill.sync-status.busy::before { animation: none; } + }
+
@@ -3164,6 +3294,7 @@ storageWarning: shadow.querySelector('.storage-warning'), updateButton: shadow.querySelector('.update'), redeployButton: shadow.querySelector('.redeploy'), + syncStatus: shadow.querySelector('.sync-status'), updateWarning: shadow.querySelector('.update-warning'), updateVersions: shadow.querySelector('.update-versions'), selectedTitle: shadow.querySelector('.selected-title'), @@ -3188,6 +3319,7 @@ liftButton.addEventListener('click', toggleOverlays); shadow.querySelector('.update').addEventListener('click', () => setPanelOpen(true)); shadow.querySelector('.redeploy').addEventListener('click', () => showToast(describeWorkerBehind(), true)); + shadow.querySelector('.sync-status').addEventListener('click', () => setPanelOpen(true)); form.addEventListener('submit', event => { event.preventDefault(); applySettings(readSettingsForm()); @@ -3352,15 +3484,18 @@ } restartSyncTimer(); + startOtherTabPolling(); window.addEventListener('pagehide', () => { pageClosed = true; window.clearInterval(remotePollTimer); window.clearTimeout(remotePushTimer); + window.clearInterval(syncView.pollTimer); }); window.addEventListener('pageshow', event => { if (!event.persisted) return; pageClosed = false; restartSyncTimer(); + startOtherTabPolling(); if (!liveSync) syncTimer = window.setInterval(refreshFromStorage, SYNC_POLL_MS); queueSync({ reason: 'startup' }); }); diff --git a/tests/harness.mjs b/tests/harness.mjs index b13654c..f44222a 100644 --- a/tests/harness.mjs +++ b/tests/harness.mjs @@ -218,6 +218,7 @@ export function openInNewTabFromContextMenu(window, href) { } const deviceLocks = new WeakMap(); +const deviceLocksHeld = new WeakMap(); export async function openTab(store, { html = listingHtml([]), @@ -245,10 +246,23 @@ export async function openTab(store, { Object.defineProperty(window.navigator, 'locks', { value: { request(name, callback) { const pending = deviceLocks.get(store) || Promise.resolve(); - const next = pending.then(callback, callback); + const run = async () => { + deviceLocksHeld.set(store, name); + try { + return await callback(); + } finally { + deviceLocksHeld.delete(store); + } + }; + const next = pending.then(run, run); deviceLocks.set(store, next.catch(() => {})); return next; }, + // Like the real one, it says which locks any tab of the device holds. + async query() { + const name = deviceLocksHeld.get(store); + return { held: name ? [{ name, mode: 'exclusive' }] : [], pending: [] }; + }, } }); } diff --git a/tests/review-lifecycle.test.mjs b/tests/review-lifecycle.test.mjs index a21ea28..51c3c3a 100644 --- a/tests/review-lifecycle.test.mjs +++ b/tests/review-lifecycle.test.mjs @@ -416,13 +416,13 @@ test('a page restored from the back/forward cache syncs again and keeps its poll window.clearInterval = id => { intervals.delete(id); clearInterval(id); }; } }); await waitFor(() => store.read(SESSION_KEY)?.completedAt); - assert.equal(intervals.size, 2, 'storage poll and remote poll'); + assert.equal(intervals.size, 3, 'storage poll, remote poll and the other-tab sync check'); tab.window.dispatchEvent(new tab.window.Event('pagehide')); - assert.equal(intervals.size, 0, 'both timers stop on pagehide'); + assert.equal(intervals.size, 0, 'every timer stops on pagehide'); const restored = new tab.window.Event('pageshow'); Object.defineProperty(restored, 'persisted', { value: true }); tab.window.dispatchEvent(restored); - assert.equal(intervals.size, 2, 'both timers come back'); + assert.equal(intervals.size, 3, 'every timer comes back'); clickCard(tab.window, '/a.html'); await waitFor(() => remote.visited().includes(abs('/a.html')), { timeout: 9000 }); }); diff --git a/tests/sync-status.test.mjs b/tests/sync-status.test.mjs new file mode 100644 index 0000000..6b3f9f6 --- /dev/null +++ b/tests/sync-status.test.mjs @@ -0,0 +1,95 @@ +// The on-page sync status: a sync that takes more than a moment says so, a tab whose sync +// waits on another tab's says that, and a tab in view sees another tab's sync through the +// shared Web Lock—the one thing AdGuard's tabs can see of each other. +import test, { afterEach } from 'node:test'; +import assert from 'node:assert/strict'; +import { + makeStore, makeRemote, enableSync, openTab, closeTabs, settle, waitFor, listingHtml, +} from './harness.mjs'; + +const SESSION_KEY = 'javstore_sync_session_v1'; +const listing = () => listingHtml([['/a.html', 'Alpha']]); +afterEach(closeTabs); + +const status = tab => { + const pill = tab.shadow().querySelector('.sync-status'); + return pill.hidden ? '' : pill.textContent; +}; + +// A worker whose answers can be held back, so a sync stays in progress while the test looks. +function slowRemote(rows = 1500) { + const remote = makeRemote(); + const at = Date.now() - 60000; + remote.store.sync({ cursor: 0, changes: Array.from({ length: rows }, (_, i) => ({ + kind: 'v', key: `https://javstore.net/v-${i}.html`, at: at + i, + })) }); + const handle = remote.handle.bind(remote); + remote.gate = null; + remote.handle = async request => { + if (remote.gate) await remote.gate.promise; + return handle(request); + }; + remote.hold = () => { + let release; + remote.gate = { promise: new Promise(resolve => { release = resolve; }) }; + remote.gate.release = () => { remote.gate = null; release(); }; + return remote.gate; + }; + return remote; +} + +test('a first download shows its progress, then says when it is complete', async () => { + const remote = slowRemote(); + const store = makeStore(); + enableSync(store, remote); + const gate = remote.hold(); + const tab = await openTab(store, { html: listing(), remote }); + await waitFor(() => /Downloading history/.test(status(tab))); + assert.match(tab.shadow().querySelector('.sync-status').title, /Wait for "Sync complete"/); + gate.release(); + await waitFor(() => status(tab) === 'Sync complete'); + await waitFor(() => status(tab) === '', { timeout: 5000 }); +}); + +test('a quick sync shows nothing', async () => { + const remote = makeRemote(); + const store = makeStore(); + enableSync(store, remote); + const tab = await openTab(store, { html: listing(), remote }); + let seen = ''; + const watch = setInterval(() => { seen = seen || status(tab); }, 5); + await waitFor(() => store.read(SESSION_KEY)?.completedAt); + await settle(100); + clearInterval(watch); + assert.equal(seen, ''); +}); + +test('a tab whose sync waits on another tab\'s says so until that one finishes', async () => { + const remote = slowRemote(); + const store = makeStore({ snapshotPerTab: true }); + enableSync(store, remote); + const gate = remote.hold(); + const first = await openTab(store, { html: listing(), remote }); + await waitFor(() => /Downloading history/.test(status(first))); + // Opened while the first tab is still downloading: its own sync queues behind it. + const second = await openTab(store, { html: listing(), remote }); + await waitFor(() => /Waiting for another tab to sync/.test(status(second))); + gate.release(); + await waitFor(() => !/Waiting/.test(status(second)), { timeout: 5000 }); +}); + +test('a tab with nothing of its own to sync shows another tab\'s sync through the lock', async () => { + const remote = slowRemote(); + const store = makeStore(); + enableSync(store, remote); + const settled = await openTab(store, { html: listing(), remote }); + await waitFor(() => store.read(SESSION_KEY)?.completedAt, { timeout: 10000 }); + await waitFor(() => status(settled) === '', { timeout: 5000 }); + // Another tab starts a long manual sync; this tab, idle, only sees the lock held. + const gate = remote.hold(); + const busy = await openTab(store, { html: listing(), remote }); + busy.shadow().querySelector('.sync-now').click(); + await waitFor(() => /Another tab is syncing/.test(status(settled)), { timeout: 8000 }); + gate.release(); + await waitFor(() => status(settled) === 'Sync complete' || status(settled) === '', { timeout: 8000 }); +}); diff --git a/worker/src/worker.mjs b/worker/src/worker.mjs index 3f5c58a..f8ced5e 100644 --- a/worker/src/worker.mjs +++ b/worker/src/worker.mjs @@ -23,7 +23,7 @@ const STORAGE_VERSION = 3; // Reported in every answer so the userscript can show which worker it is talking to. It // moves in step with the userscript's own version; a test holds the two together. -export const WORKER_VERSION = '6.12.0'; +export const WORKER_VERSION = '6.13.0'; const OBJECT_NAME = 'default'; const MAX_BODY_BYTES = 8 * 1024 * 1024; const MAX_PAGE_ROWS = 2000; From fa11b1350059806e74d8bc805b017fd2b3109723 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 20:25:06 +0000 Subject: [PATCH 2/2] Keep the sync status readable on phone-width screens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At 520 px and below the dock wraps and the sync status takes a full-width row of its own above the other controls, so a long label such as "Downloading history… 3,000 visits" can neither squeeze the pills onto two lines nor push the dock off-screen. Pills keep their labels on one line. The dock spans the width there, so its empty part lets taps through to the page. Reported by the Codex review on the pull request. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VCuhK4TQqcEbLXdmxLjggy --- javstore-full-layout-cleanup.user.js | 11 +++++++++-- tests/sync-status.test.mjs | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/javstore-full-layout-cleanup.user.js b/javstore-full-layout-cleanup.user.js index b0bd0e4..dbb426f 100644 --- a/javstore-full-layout-cleanup.user.js +++ b/javstore-full-layout-cleanup.user.js @@ -3130,7 +3130,7 @@ min-height: 40px; border: 1px solid rgba(255,255,255,.2); border-radius: 999px; color: #fff; background: #111827; box-shadow: 0 8px 24px rgba(0,0,0,.28); } - .pill { padding: 8px 14px; } + .pill { padding: 8px 14px; white-space: nowrap; } .icon-button { width: 40px; padding: 0; font-size: 18px; } button:hover { background: #1f2937; } button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { @@ -3191,7 +3191,14 @@ .toast.error { background: #991b1b; } .toast.show { opacity: 1; transform: translateY(0); } @media (max-width: 520px) { - .dock { right: 10px; bottom: 10px; } + /* On a phone the controls wrap rather than run off the left edge, and the + sync status takes a row of its own above them so it is always readable. */ + .dock { + right: 10px; bottom: 10px; left: 10px; flex-wrap: wrap; justify-content: flex-end; + pointer-events: none; + } + .dock > * { pointer-events: auto; } + .pill.sync-status { order: -1; flex: 1 0 100%; text-align: center; } .panel { right: 10px; bottom: 62px; width: calc(100vw - 20px); max-height: calc(100vh - 76px); } .grid { grid-template-columns: 1fr; } .full { grid-column: auto; } diff --git a/tests/sync-status.test.mjs b/tests/sync-status.test.mjs index 6b3f9f6..44e8bd2 100644 --- a/tests/sync-status.test.mjs +++ b/tests/sync-status.test.mjs @@ -93,3 +93,18 @@ test('a tab with nothing of its own to sync shows another tab\'s sync through th gate.release(); await waitFor(() => status(settled) === 'Sync complete' || status(settled) === '', { timeout: 8000 }); }); + +// On a phone the dock wraps, and the status takes a row of its own above the other +// controls, so a long label cannot push them, or itself, off the screen. The dock spans the +// width there, so its empty part must let taps through to the page. +test('on narrow screens the dock wraps, puts the status first, and lets taps through', async () => { + const store = makeStore(); + const tab = await openTab(store, { html: listing() }); + const css = tab.shadow().querySelector('style').textContent; + const narrow = css.slice(css.indexOf('@media (max-width: 520px)')); + assert.match(narrow, /\.dock\s*\{[^}]*flex-wrap:\s*wrap/); + assert.match(narrow, /\.dock\s*\{[^}]*pointer-events:\s*none/); + assert.match(narrow, /\.dock > \*\s*\{\s*pointer-events:\s*auto/); + assert.match(narrow, /\.pill\.sync-status\s*\{[^}]*order:\s*-1[^}]*flex:\s*1 0 100%/); + assert.match(css, /\.pill\s*\{[^}]*white-space:\s*nowrap/); +});