Skip to content

Commit dccb00b

Browse files
jitdorclaude
andauthored
Flag a worker behind the script on the page itself (6.9.0) (#17)
* Flag a worker behind the script on the page itself (6.9.0) The redeploy warning lived only inside the Cloud sync panel, so a worker left on 6.6.0 went unnoticed. A "Redeploy worker" pill now appears in the on-page dock; tapping it shows both versions and the deploy command. Longer toasts stay up long enough to read. Document that nothing in the repository deploys the worker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KtBArBFtPSqnpnrUyAopd8 * Point the redeploy warning at the worker's Cloudflare build The worker deploys from main through Cloudflare's Git integration, not by hand, so the warning and docs no longer tell you to run wrangler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KtBArBFtPSqnpnrUyAopd8 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 65ce135 commit dccb00b

5 files changed

Lines changed: 54 additions & 14 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 6.9.0
4+
5+
- Change: a worker behind the userscript is now flagged on the page itself with a **⚠ Redeploy worker** button next to the JavStore controls, instead of only in the Cloud sync panel, where it was easy to miss. Tapping it shows both versions and points to the worker's Cloudflare build. The panel still lists the worker version.
6+
37
## 6.8.1
48

59
- Fix: on the Userscripts app for Safari (iPhone, iPad and Mac), nothing was ever saved. Pasting a sync link, or saving the sync settings by hand, showed "Sync settings could not be saved", and visited history was gone after every reload. That app offers only the dotted GM4 API (`GM.getValue`, `GM.setValue`, …) and no `GM_*` functions, so every storage call failed. The script now uses whichever of the two forms the userscript manager provides, and requests the `GM.*` grants too. After updating, paste the sync link again and save.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Once it is deployed, open the `JVS` panel → **Cloud sync**, enter the worker U
3838
- The worker applies the same rules as the local merge—newest timestamp wins per URL, tombstones and the clear/retention horizons outrank stale entries—so a device that has been offline for a week cannot overwrite what the others recorded, and clearing history on one device clears it everywhere instead of being undone. A device that pushes a stale entry is handed the winning one back.
3939
- Because a Durable Object is single-threaded, each sync's read-merge-write is serialized and strongly consistent: two devices syncing in the same second queue behind one another rather than racing.
4040
- Settings sync too, including the match and excluded terms, and they merge setting by setting: each one goes to the device that changed it last. A setting a device has never changed carries no timestamp and cannot win, so a new install picks up your keywords from the worker instead of pushing its defaults over them, even if you changed something else on it first. **Restore defaults** and a backup import set every setting on purpose, so they win everywhere.
41-
- The Cloud sync panel shows the worker version from the worker's last answer, and warns when the worker is behind the userscript and needs redeploying. 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.
41+
- 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.
4242
- 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.
4343
- 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.
4444
- 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.

‎javstore-full-layout-cleanup.user.js‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name JavStore Full Layout Cleanup - No Sidebars + Mosaic Overlay
33
// @namespace http://tampermonkey.net/
4-
// @version 6.8.1
4+
// @version 6.9.0
55
// @description Clean up JavStore's layout, filter keyword-matched thumbnails, and track visited items with private, configurable controls.
66
// @homepageURL https://github.com/jitdor/userscript-javstore
77
// @supportURL https://github.com/jitdor/userscript-javstore/issues
@@ -29,7 +29,7 @@
2929
(function () {
3030
'use strict';
3131

32-
const SCRIPT_VERSION = '6.8.1';
32+
const SCRIPT_VERSION = '6.9.0';
3333
// The same address as @downloadURL: opening it hands the newest release to the
3434
// userscript manager, which offers to install it.
3535
const INSTALL_URL = 'https://github.com/jitdor/userscript-javstore/releases/latest/download/javstore-full-layout-cleanup.user.js';
@@ -1617,14 +1617,21 @@
16171617
return 0;
16181618
}
16191619

1620+
// A worker that only says it is "older than" some version is behind by definition.
1621+
function workerBehindScript() {
1622+
if (!syncConfigured() || !remoteWorkerVersion) return false;
1623+
return !/^\d+(\.\d+)*$/.test(remoteWorkerVersion)
1624+
|| compareVersions(remoteWorkerVersion, SCRIPT_VERSION) < 0;
1625+
}
1626+
16201627
function describeWorkerVersion() {
16211628
if (!syncConfigured()) return '';
16221629
if (!remoteWorkerVersion) return 'Worker version: not known until the first sync on this page.';
1623-
const known = /^\d+(\.\d+)*$/.test(remoteWorkerVersion);
1624-
const behind = !known || compareVersions(remoteWorkerVersion, SCRIPT_VERSION) < 0;
1625-
return behind
1626-
? `Worker version: ${remoteWorkerVersion}, behind this script (${SCRIPT_VERSION}). Redeploy the worker.`
1627-
: `Worker version: ${remoteWorkerVersion}.`;
1630+
return `Worker version: ${remoteWorkerVersion}.`;
1631+
}
1632+
1633+
function describeWorkerBehind() {
1634+
return `Your sync worker is ${remoteWorkerVersion}, behind this script (${SCRIPT_VERSION}). The worker redeploys from main through Cloudflare, so check its latest build in the Cloudflare dashboard.`;
16281635
}
16291636

16301637
// The worker deploys from the same commit the release is cut from, so a worker ahead of
@@ -2126,6 +2133,9 @@
21262133
const workerVersion = describeWorkerVersion();
21272134
ui.workerVersion.textContent = workerVersion;
21282135
ui.workerVersion.hidden = !workerVersion;
2136+
const workerBehind = workerBehindScript();
2137+
ui.redeployButton.hidden = !workerBehind;
2138+
if (workerBehind) ui.redeployButton.title = describeWorkerBehind();
21292139
const behind = scriptBehindWorker();
21302140
ui.updateButton.hidden = !behind;
21312141
ui.updateWarning.hidden = !behind;
@@ -2143,7 +2153,7 @@
21432153
ui.toast.classList.toggle('error', isError);
21442154
ui.toast.classList.add('show');
21452155
window.clearTimeout(ui.toastTimer);
2146-
ui.toastTimer = window.setTimeout(() => ui?.toast.classList.remove('show'), 2800);
2156+
ui.toastTimer = window.setTimeout(() => ui?.toast.classList.remove('show'), Math.max(2800, message.length * 60));
21472157
}
21482158

21492159
function splitTerms(value) {
@@ -2394,8 +2404,8 @@
23942404
.muted { color: #9ca3af; font-size: 12px; }
23952405
.warning { padding: 8px; border-radius: 8px; color: #fecaca; background: #7f1d1d; }
23962406
.warning a { color: #fff; }
2397-
.pill.update { border-color: #fca5a5; background: #991b1b; }
2398-
.pill.update:hover { background: #7f1d1d; }
2407+
.pill.update, .pill.redeploy { border-color: #fca5a5; background: #991b1b; }
2408+
.pill.update:hover, .pill.redeploy:hover { background: #7f1d1d; }
23992409
.pill[hidden], .warning[hidden] { display: none; }
24002410
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
24012411
.full { grid-column: 1 / -1; }
@@ -2435,6 +2445,7 @@
24352445
</style>
24362446
<div class="dock" aria-label="JavStore cleanup controls">
24372447
<button class="pill update" type="button" hidden>⚠ Update script</button>
2448+
<button class="pill redeploy" type="button" hidden>⚠ Redeploy worker</button>
24382449
<button class="pill lift" type="button">Reveal all</button>
24392450
<button class="pill summary" type="button" aria-expanded="false">JavStore controls</button>
24402451
</div>
@@ -2523,6 +2534,7 @@
25232534
workerVersion: shadow.querySelector('.worker-version'),
25242535
storageWarning: shadow.querySelector('.storage-warning'),
25252536
updateButton: shadow.querySelector('.update'),
2537+
redeployButton: shadow.querySelector('.redeploy'),
25262538
updateWarning: shadow.querySelector('.update-warning'),
25272539
updateVersions: shadow.querySelector('.update-versions'),
25282540
selectedTitle: shadow.querySelector('.selected-title'),
@@ -2546,6 +2558,7 @@
25462558
shadow.querySelector('.close').addEventListener('click', () => setPanelOpen(false));
25472559
liftButton.addEventListener('click', toggleOverlays);
25482560
shadow.querySelector('.update').addEventListener('click', () => setPanelOpen(true));
2561+
shadow.querySelector('.redeploy').addEventListener('click', () => showToast(describeWorkerBehind(), true));
25492562
form.addEventListener('submit', event => {
25502563
event.preventDefault();
25512564
applySettings(readSettingsForm());

‎tests/sync.test.mjs‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,16 @@ test('an older worker is named from its answer and flagged for redeploying', asy
899899
};
900900
const tab = await openDevice(remote);
901901
await syncNow(tab);
902-
assert.match(workerVersionText(tab).textContent, new RegExp(`^Worker version: ${expected}, behind this script`));
903-
assert.match(workerVersionText(tab).textContent, /Redeploy the worker/);
902+
assert.equal(workerVersionText(tab).textContent, `Worker version: ${expected}.`);
903+
// The warning sits on the page, not inside the settings panel.
904+
const pill = tab.shadow().querySelector('.dock .redeploy');
905+
assert.equal(pill.hidden, false);
906+
assert.equal(tab.shadow().querySelector('.panel').hidden, true);
907+
pill.click();
908+
await settle();
909+
const toast = tab.shadow().querySelector('.toast');
910+
assert.match(toast.textContent, new RegExp(`^Your sync worker is ${expected}, behind this script`));
911+
assert.match(toast.textContent, /Cloudflare/);
904912
closeTabs();
905913
}
906914
});
@@ -947,6 +955,21 @@ test('a script level with or ahead of its worker shows no update warning', async
947955
}
948956
});
949957

958+
test('a worker level with or ahead of the script shows no redeploy warning', async () => {
959+
for (const reported of [WORKER_VERSION, '99.0.0']) {
960+
const remote = makeRemote();
961+
const reach = remote.handle;
962+
remote.handle = async request => {
963+
const response = await reach(request);
964+
return { ...response, text: JSON.stringify({ ...JSON.parse(response.text), worker: reported }) };
965+
};
966+
const tab = await openDevice(remote);
967+
await syncNow(tab);
968+
assert.equal(tab.shadow().querySelector('.redeploy').hidden, true, `worker ${reported}`);
969+
closeTabs();
970+
}
971+
});
972+
950973
// AdGuard for Android clears a userscript's storage when it installs an update, so the panel
951974
// hands out one link that sets sync up again.
952975
async function copyLink(tab) {

‎worker/src/worker.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
const STORAGE_VERSION = 3;
1818
// Reported in every answer so the userscript can show which worker it is talking to. It
1919
// moves in step with the userscript's own version; a test holds the two together.
20-
export const WORKER_VERSION = '6.8.1';
20+
export const WORKER_VERSION = '6.9.0';
2121
const OBJECT_NAME = 'default';
2222
const MAX_BODY_BYTES = 8 * 1024 * 1024;
2323
const MAX_PAGE_ROWS = 2000;

0 commit comments

Comments
 (0)