Repository navigation
Show visited markers and tinting earlier (6.10.2) #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import test, { afterEach } from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { makeStore, openTab, closeTabs, listingHtml, waitFor } from './harness.mjs'; | ||
|
|
||
| afterEach(closeTabs); | ||
| const url = 'https://javstore.net/590733-Item-pn.html'; | ||
| const html = listingHtml([[url, 'Item']]); | ||
|
|
||
| function seededStore() { | ||
| const store = makeStore(); | ||
| store.write('javstore_cleanup_state_v2', { | ||
| visited: { [url]: Date.now() - 1000 }, | ||
| settings: { keywords: ['Item'], mode: 'tint' }, | ||
| }); | ||
| return store; | ||
| } | ||
|
|
||
| for (const blocked of ['config', 'journals']) { | ||
| test(`paints local tiles while ${blocked} storage is pending, then reconciles recovery`, async () => { | ||
| const store = seededStore(); | ||
| const at = Date.now(); | ||
| store.write('javstore_journal_v1_startup', { | ||
| visited: { 'https://javstore.net/recovered.html': at }, | ||
| settings: { keywords: ['Different'], mode: 'tint' }, | ||
| settingsUpdatedAt: at, | ||
| }); | ||
| let release; | ||
| const gate = new Promise(resolve => { release = resolve; }); | ||
| const get = store.get.bind(store); | ||
| const list = store.list.bind(store); | ||
| if (blocked === 'config') store.get = async (key, fallback) => { | ||
| if (key === 'javstore_sync_config_v1') await gate; | ||
| return get(key, fallback); | ||
| }; | ||
| else store.list = async () => { await gate; return list(); }; | ||
| let writes = 0; | ||
| const set = store.set.bind(store); | ||
| store.set = (...args) => { writes++; return set(...args); }; | ||
| try { | ||
| const tab = await openTab(store, { html }); | ||
| const tile = tab.window.document.querySelector('main .grid a'); | ||
| await waitFor(() => tile.classList.contains('jvs-mode-tint')); | ||
| assert.ok(tile.classList.contains('jvs-visited')); | ||
| assert.equal(writes, 0, 'preview must not write before recovery is read'); | ||
| release(); | ||
| await waitFor(() => !tile.classList.contains('jvs-mode-tint')); | ||
| await waitFor(() => store.state()?.visited?.['https://javstore.net/recovered.html']); | ||
| } finally { release(); } | ||
| }); | ||
| } | ||
|
|
||
| test('processes visible and newly inserted tiles before DOMContentLoaded', async () => { | ||
| const tab = await openTab(seededStore(), { | ||
| html, | ||
| beforeRun(window) { | ||
| Object.defineProperty(window.document, 'readyState', { configurable: true, get: () => 'loading' }); | ||
| }, | ||
| }); | ||
| const tile = tab.window.document.querySelector('main .grid a'); | ||
| await waitFor(() => tile.classList.contains('jvs-visited')); | ||
| assert.ok(tile.classList.contains('jvs-mode-tint')); | ||
| const added = tile.cloneNode(true); | ||
| added.className = ''; | ||
| tile.parentElement.append(added); | ||
| await waitFor(() => added.classList.contains('jvs-visited')); | ||
| assert.ok(added.classList.contains('jvs-mode-tint')); | ||
| tab.window.document.dispatchEvent(new tab.window.Event('DOMContentLoaded')); | ||
| await waitFor(() => tab.window.document.getElementById('jvs-controls-host')); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this userscript runs at
document-start, a manager with synchronous GM storage APIs can finish both startup reads before the parser has created either<html>or<body>. In that case this expression yieldsnull, the function returns without installing an observer, and nothing invokes it again untilonReady()afterDOMContentLoaded; consequently the new early tile painting does not work in that environment. Observedocumentitself or arrange to retry as soon as the root element appears.Useful? React with 👍 / 👎.