From fb803e45328095e706ccb40df91da28523a436b1 Mon Sep 17 00:00:00 2001 From: Loren McIntyre Date: Mon, 15 Jun 2026 04:37:00 -0700 Subject: [PATCH] feat(tampermonkey): load nav-popups on MediaWiki sites (domain + /wiki/ match) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Broaden the nav-popups registry entry's @match from wikipedia.org only to the Wikimedia family (wiktionary/wikidata/wikisource/wikibooks/wikiquote/wikinews/ wikiversity/wikivoyage/wikimedia/mediawiki.org) by domain — so it loads on edit/ history/special pages too, not just /wiki/ article views — plus a *://*/wiki/* catch-all for self-hosted MediaWiki on any domain. This is the coarse first pass ("by domain, or url /wiki/"); content-detection (detect MediaWiki via mw.config / generator meta) is the planned refinement to avoid false positives on non-MW /wiki/ paths — added to the spec roadmap. - test/nav-popups-match.test.js: matches Wikimedia (incl. non-/wiki/ paths) and self-hosted /wiki/; rejects non-wiki pages. 34/34 pass. - regenerated registry.embedded.js + build/ via build.sh. Co-Authored-By: Claude Opus 4.8 (1M context) --- ...06-15-tampermonkey-script-loader-design.md | 6 ++++ tampermonkey/registry.embedded.js | 17 +++++++++-- tampermonkey/registry.json | 17 +++++++++-- tampermonkey/test/nav-popups-match.test.js | 29 +++++++++++++++++++ 4 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 tampermonkey/test/nav-popups-match.test.js diff --git a/docs/superpowers/specs/2026-06-15-tampermonkey-script-loader-design.md b/docs/superpowers/specs/2026-06-15-tampermonkey-script-loader-design.md index 032c9fd..81ddc64 100644 --- a/docs/superpowers/specs/2026-06-15-tampermonkey-script-loader-design.md +++ b/docs/superpowers/specs/2026-06-15-tampermonkey-script-loader-design.md @@ -199,6 +199,12 @@ the *inclusion* mechanics through the console first. the version/update report; sign it (age / gpg) so a relayed/"gossiped" update notice is verifiable against the registry pubkey. Needs dev signing keys (generate; cache/store the *public* half in-source, never the private). +- **Content detection** to refine matching — beyond `match` globs, detect a wiki/app + at runtime (e.g. MediaWiki via `mw`/`mw.config`, ``, + `/w/api.php`) so an entry auto-loads on *any* MediaWiki without enumerating + domains, and the coarse `*/wiki/*` catch-all stops false-positiving on non-MW + sites that happen to use a `/wiki/` path. Schema would gain an optional `detect` + hook; matching becomes "glob match AND (no detector OR detector passes)". - SRI *enforcement by default*; GitHub-API auto-discovery; the cross-repo "suggest diff-bump" tooling (mw roadmap); storage-size limiting (§5). diff --git a/tampermonkey/registry.embedded.js b/tampermonkey/registry.embedded.js index a744368..4b1bca4 100644 --- a/tampermonkey/registry.embedded.js +++ b/tampermonkey/registry.embedded.js @@ -5,10 +5,23 @@ const EMBEDDED_REGISTRY_JSON = [ "repo": "mcint/userscripts", "path": "mw/nav-popups/popups.js", "ref": "main", - "match": ["*://*.wikipedia.org/*"], + "match": [ + "*://*.wikipedia.org/*", + "*://*.wiktionary.org/*", + "*://*.wikimedia.org/*", + "*://*.wikidata.org/*", + "*://*.wikisource.org/*", + "*://*.wikibooks.org/*", + "*://*.wikiquote.org/*", + "*://*.wikinews.org/*", + "*://*.wikiversity.org/*", + "*://*.wikivoyage.org/*", + "*://*.mediawiki.org/*", + "*://*/wiki/*" + ], "runAt": "document-idle", "grant": [], "integrity": null, - "desc": "Wikipedia hover previews (maintained fork)" + "desc": "Navigation popups (maintained fork) — MediaWiki hover previews. Matches Wikimedia family by domain + any */wiki/* path (coarse; content-detection planned)." } ]; diff --git a/tampermonkey/registry.json b/tampermonkey/registry.json index 2994bb7..e123b8b 100644 --- a/tampermonkey/registry.json +++ b/tampermonkey/registry.json @@ -5,10 +5,23 @@ "repo": "mcint/userscripts", "path": "mw/nav-popups/popups.js", "ref": "main", - "match": ["*://*.wikipedia.org/*"], + "match": [ + "*://*.wikipedia.org/*", + "*://*.wiktionary.org/*", + "*://*.wikimedia.org/*", + "*://*.wikidata.org/*", + "*://*.wikisource.org/*", + "*://*.wikibooks.org/*", + "*://*.wikiquote.org/*", + "*://*.wikinews.org/*", + "*://*.wikiversity.org/*", + "*://*.wikivoyage.org/*", + "*://*.mediawiki.org/*", + "*://*/wiki/*" + ], "runAt": "document-idle", "grant": [], "integrity": null, - "desc": "Wikipedia hover previews (maintained fork)" + "desc": "Navigation popups (maintained fork) — MediaWiki hover previews. Matches Wikimedia family by domain + any */wiki/* path (coarse; content-detection planned)." } ] diff --git a/tampermonkey/test/nav-popups-match.test.js b/tampermonkey/test/nav-popups-match.test.js new file mode 100644 index 0000000..c68f304 --- /dev/null +++ b/tampermonkey/test/nav-popups-match.test.js @@ -0,0 +1,29 @@ +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('node:fs'); +const path = require('node:path'); +const L = require('../loader.user.js'); + +function navPopups() { + const text = fs.readFileSync(path.join(__dirname, '..', 'registry.json'), 'utf8'); + return L.parseRegistry(text).find((e) => e.id === 'nav-popups'); +} + +test('nav-popups matches Wikimedia by domain — incl. non-/wiki/ paths', () => { + const m = navPopups().match; + assert.ok(L.matchUrl(m, 'https://en.wikipedia.org/wiki/Cat')); + assert.ok(L.matchUrl(m, 'https://en.wikipedia.org/w/index.php?title=Cat&action=history')); + assert.ok(L.matchUrl(m, 'https://en.wiktionary.org/wiki/cat')); + assert.ok(L.matchUrl(m, 'https://www.mediawiki.org/wiki/Manual:Contents')); +}); + +test('nav-popups matches self-hosted MediaWiki by /wiki/ path catch-all', () => { + const m = navPopups().match; + assert.ok(L.matchUrl(m, 'https://some-wiki.example.org/wiki/Page')); +}); + +test('nav-popups does not match non-wiki pages', () => { + const m = navPopups().match; + assert.strictEqual(L.matchUrl(m, 'https://example.com/'), false); + assert.strictEqual(L.matchUrl(m, 'https://github.com/mcint/userscripts'), false); +}); -- knotmirror 0.0.1