18 lines
623 B
JavaScript
18 lines
623 B
JavaScript
(() => {
|
|
const KEY = "__cab";
|
|
const host = location.hostname;
|
|
if (!host) return;
|
|
chrome.runtime.sendMessage({ cmd: "page", host, top: window === window.top }).then(res => {
|
|
if (!res) return;
|
|
const s = res.scriptlets && res.scriptlets.length ? JSON.stringify(res.scriptlets) : "";
|
|
let prev = null;
|
|
try { prev = localStorage.getItem(KEY); } catch (e) {}
|
|
if (s === (prev || "")) return;
|
|
try {
|
|
if (s) localStorage.setItem(KEY, s);
|
|
else localStorage.removeItem(KEY);
|
|
} catch (e) {}
|
|
if (s) window.dispatchEvent(new CustomEvent(KEY, { detail: s }));
|
|
}).catch(() => {});
|
|
})();
|