feat(dictionary): add Hachidori backend support

- Add backend selection, setup gating, Anki integration, and external host support
- Add launcher flags, documentation, packaging, and focused tests
- Open on-demand overlay modals on the first attempt
This commit is contained in:
2026-09-22 00:21:19 -07:00
parent 1508863dbb
commit d9fdc7ef6d
446 changed files with 109060 additions and 244 deletions
+32
View File
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: GPL-3.0-or-later
const SCRIPT_ID = "hachidori-custom-javascript";
let application = Promise.resolve();
// Chrome MV3 `userScripts` registration. Firefox MV2 has no `userScripts`
// with a USER_SCRIPT world, so the saved code stays inert there and Settings
// hides the editor through HOST_CAPABILITIES.customJavaScript.
async function apply(browser, code) {
let scripts;
try {
scripts = browser.userScripts;
await scripts.getScripts({ ids: [SCRIPT_ID] });
} catch {
return { supported: false, registered: false };
}
await scripts.unregister({ ids: [SCRIPT_ID] }).catch(() => {});
if (code === "") return { supported: true, registered: false };
await scripts.register([{
id: SCRIPT_ID,
matches: ["<all_urls>"],
js: [{ code }],
runAt: "document_idle",
world: "USER_SCRIPT",
}]);
return { supported: true, registered: true };
}
export function applyCustomJavaScript(browser, code) {
application = application.catch(() => {}).then(() => apply(browser, code));
return application;
}