-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
31 lines (28 loc) · 1.35 KB
/
Copy pathbackground.js
File metadata and controls
31 lines (28 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Capability snapshots live in chrome.storage.session (a per-browser-session
// performance hint). Content scripts run in untrusted contexts, so the worker
// must grant them access explicitly on every startup.
if (chrome.storage.session?.setAccessLevel) {
chrome.storage.session.setAccessLevel({ accessLevel: "TRUSTED_AND_UNTRUSTED_CONTEXTS" });
}
chrome.runtime.onInstalled.addListener(({ reason }) => {
// Preserve the user's enabled/disabled choice across extension updates.
if (reason === "install") chrome.storage.local.set({ shikiDocsSkinEnabled: true });
// Capability snapshots describe third-party DOM and model labels, so they are
// release-scoped. Never carry an older scan into a newer Shiki build. The
// local-area removal also migrates pre-1.6 installs that cached there.
if (reason === "install" || reason === "update") {
chrome.storage.local.remove("shikiDetectedCapabilities");
chrome.storage.session?.remove("shikiDetectedCapabilities");
}
});
async function toggleStoredState() {
const key = "shikiDocsSkinEnabled";
const current = await chrome.storage.local.get({ [key]: true });
const enabled = !Boolean(current[key]);
await chrome.storage.local.set({ [key]: enabled });
return enabled;
}
chrome.commands.onCommand.addListener(async (command) => {
if (command !== "toggle-skin") return;
await toggleStoredState();
});