Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
26 changes: 24 additions & 2 deletions javstore-full-layout-cleanup.user.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand Down
77 changes: 77 additions & 0 deletions tests/links.test.mjs
Original file line number Diff line number Diff line change
@@ -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 = '<a href="/590733-Title#6-pn.html"><div class="aspect-video"><img></div><h3>Item</h3></a>';
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',
]);
});
2 changes: 1 addition & 1 deletion worker/src/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading