From 41866cc6d382bd063cfecac7bbfac5625b6e2f40 Mon Sep 17 00:00:00 2001 From: Jitdor Date: Sat, 3 Oct 2026 07:53:49 +0800 Subject: [PATCH] Fix literal hashes in tile paths and release 6.10.1 --- CHANGELOG.md | 7 +++ javstore-full-layout-cleanup.user.js | 26 +++++++++- tests/links.test.mjs | 77 ++++++++++++++++++++++++++++ worker/src/worker.mjs | 2 +- 4 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 tests/links.test.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index 397c58a..73bafb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 6.10.1 + +- Fix: tile links with a literal `#` inside an item filename now encode it as `%23`, so the server receives the complete path instead of returning a 404. This applies to existing tiles and dynamically added or changed tiles, including links opened through the browser's context menu. +- The repair is limited to incomplete JavStore item paths whose fragment contains the missing `-pn.html` ending. Complete page links, legitimate fragments, query strings, existing escapes, and links to other hosts are preserved. +- Existing history stored under the correct URL still marks repaired tiles as visited. Older history truncated at `#` is not migrated because the missing portion cannot be recovered reliably. +- The worker version moves to 6.10.1 with the userscript, as required by the project; worker behavior is unchanged. + ## 6.10.0 - Change: no device can delete visited history from the sync worker any more. The worker used to apply every removal a device sent, and delete the rows outright: one **Clear visited history**, one retention setting above 0, or one import of an older backup on any device wiped those visits from the worker and from every other device, with no way back short of an exported backup. Now the worker only ever adds visits. Clearing history, retention pruning, unmarking a card with `V`, and the entries an import leaves out all apply to the device they happen on, and the worker and the other devices keep their copies. The clear confirmation says so when sync is on. diff --git a/javstore-full-layout-cleanup.user.js b/javstore-full-layout-cleanup.user.js index f216d10..d9893c5 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.10.0 +// @version 6.10.1 // @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.10.0'; + const SCRIPT_VERSION = '6.10.1'; // 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'; @@ -1955,7 +1955,29 @@ return true; } + function repairCardUrl(card) { + try { + const url = new URL(card.href); + // A raw # in an item title can hide the rest of the filename from the + // server. Only recover incomplete JavStore item paths, never anchors + // on complete pages or hashes belonging to query values. + if (!/^https?:$/.test(url.protocol) || url.hostname !== 'javstore.net' + || url.search || !/^\/\d+-[^/]+$/.test(url.pathname) + || /\.html$/i.test(url.pathname)) return; + const match = url.hash.match(/^#([^?]*?-pn\.html)(?=[?#]|$)(.*)$/i); + if (!match || match[1].includes('/')) return; + // Preserve existing escapes and any real query/fragment after the + // recovered filename. Assignment is conditional to avoid observer loops. + url.pathname += `%23${match[1].replace(/#/g, '%23')}`; + url.hash = ''; + card.href = url.href + match[2]; + } catch (error) { + // Leave malformed or unsupported links untouched. + } + } + function processCard(card) { + repairCardUrl(card); card.classList.add('jvs-card'); card.classList.remove('jvs-card-match', 'jvs-mode-tint', 'jvs-mode-blur', 'jvs-mode-hide', 'jvs-filtered-out'); const thumbnail = card.querySelector('.aspect-video'); diff --git a/tests/links.test.mjs b/tests/links.test.mjs new file mode 100644 index 0000000..2be453a --- /dev/null +++ b/tests/links.test.mjs @@ -0,0 +1,77 @@ +import test, { afterEach } from 'node:test'; +import assert from 'node:assert/strict'; +import { + makeStore, openTab, closeTabs, listingHtml, settle, clickCard, visitedUrls, + openInNewTabFromContextMenu, +} from './harness.mjs'; + +afterEach(closeTabs); + +test('repairs item-title hashes without double encoding or losing URL suffixes', async () => { + const cases = [ + ['/590733-Title(23)#6-example-pn.html', '/590733-Title(23)%236-example-pn.html'], + ['590733-%E6%96%B0(23)#6-pn.html', '/590733-%E6%96%B0(23)%236-pn.html'], + ['https://javstore.net/590733-Title#6-pn.html', '/590733-Title%236-pn.html'], + ['//javstore.net/590733-Title#6#7-pn.html', '/590733-Title%236%237-pn.html'], + ['/590733-Title#6-pn.html?mode=full#comments', '/590733-Title%236-pn.html?mode=full#comments'], + ['/590733-Title#6-pn.html#comments', '/590733-Title%236-pn.html#comments'], + ]; + const tab = await openTab(makeStore(), { html: listingHtml(cases.map(([url]) => [url, 'Item'])) }); + const links = [...tab.window.document.querySelectorAll('main .grid a')]; + assert.deepEqual(links.map(link => link.href), cases.map(([, expected]) => `https://javstore.net${expected}`)); + await settle(); + assert.deepEqual(links.map(link => link.href), cases.map(([, expected]) => `https://javstore.net${expected}`)); + assert.equal(openInNewTabFromContextMenu(tab.window, links[0].getAttribute('href')).hash, ''); +}); + +test('preserves legitimate fragments, encoded paths, unrelated hosts and ambiguous links', async () => { + const urls = [ + '/590733-Title-pn.html#comments', '/590733-Title-pn.html#other-pn.html', + '/590733-Title%236-pn.html?x=1#comments', '#comments', + '/590733-Title#comments', '/590733-Title#6.html', + '/590733-Title?next=x#6-pn.html', '/search#6-pn.html', + '/folder/590733-Title#6-pn.html', '/590733-Title#folder/file-pn.html', + 'https://example.com/590733-Title#6-pn.html', + 'https://javstore.net.example.com/590733-Title#6-pn.html', + 'ftp://javstore.net/590733-Title#6-pn.html', + ]; + const tab = await openTab(makeStore(), { html: listingHtml(urls.map(url => [url, 'Item'])) }); + assert.deepEqual([...tab.window.document.querySelectorAll('main .grid a')].map(link => link.getAttribute('href')), urls); +}); + +test('repairs added and changed tiles and records the repaired destination in history', async () => { + const store = makeStore(); + const tab = await openTab(store); + const grid = tab.window.document.querySelector('main .grid'); + grid.innerHTML = '

Item

'; + await settle(); + const link = grid.querySelector('a'); + assert.equal(link.href, 'https://javstore.net/590733-Title%236-pn.html'); + link.setAttribute('href', '/590733-Title#7-pn.html?view=full#comments'); + await settle(); + assert.equal(link.href, 'https://javstore.net/590733-Title%237-pn.html?view=full#comments'); + clickCard(tab.window, link.getAttribute('href')); + await settle(); + assert.deepEqual(visitedUrls(store), ['https://javstore.net/590733-Title%237-pn.html']); +}); + +test('existing visits to the correct URL still mark repaired tiles as visited', async () => { + const store = makeStore(); + const first = await openTab(store, { html: listingHtml([ + ['/590733-Title%236-pn.html', 'Item'], + ['/590734-Other-pn.html#comments', 'Other'], + ]) }); + clickCard(first.window, '/590733-Title%236-pn.html'); + clickCard(first.window, '/590734-Other-pn.html#comments'); + await settle(); + const reloaded = await openTab(store, { html: listingHtml([ + ['/590733-Title#6-pn.html', 'Item'], + ['/590734-Other-pn.html#comments', 'Other'], + ]) }); + const links = [...reloaded.window.document.querySelectorAll('main .grid a')]; + assert.ok(links.every(link => link.classList.contains('jvs-visited'))); + assert.deepEqual(visitedUrls(store), [ + 'https://javstore.net/590733-Title%236-pn.html', + 'https://javstore.net/590734-Other-pn.html', + ]); +}); diff --git a/worker/src/worker.mjs b/worker/src/worker.mjs index 6b92754..e77a635 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.10.0'; +export const WORKER_VERSION = '6.10.1'; const OBJECT_NAME = 'default'; const MAX_BODY_BYTES = 8 * 1024 * 1024; const MAX_PAGE_ROWS = 2000;