70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
import { t } from "./index-6137f488.js";
|
|
|
|
class e extends t {
|
|
constructor() {
|
|
super();
|
|
this.fetch = async (t, e) => this.sendToContentScript("fetch", [t, e]);
|
|
this.extensionId = (function () {
|
|
var t;
|
|
const e =
|
|
null === (t = document.getElementById("XQpBuigyZWZGIjvE")) ||
|
|
void 0 === t
|
|
? void 0
|
|
: t.getAttribute("XQpBuigyZWZGIjvE");
|
|
if (!e)
|
|
throw new Error("Could not resolve extension ID from injected script");
|
|
return e;
|
|
})();
|
|
window.addEventListener("message", (t) => {
|
|
var e, n;
|
|
t.source === window &&
|
|
(null === (e = t.data) || void 0 === e ? void 0 : e.id) ===
|
|
this.extensionId &&
|
|
"event" === (null === (n = t.data) || void 0 === n ? void 0 : n.type) &&
|
|
this.onMessage(t.data.data);
|
|
});
|
|
}
|
|
async onMessage(t) {}
|
|
async getStorage(t) {
|
|
return await this.sendToContentScript("storage.get", t);
|
|
}
|
|
async getLiveStorageValue(t, e = (t) => t) {
|
|
const n = {
|
|
value: e(await this.getStorage(t)),
|
|
},
|
|
o = window.setInterval(async () => {
|
|
n.value = e(await this.getStorage(t));
|
|
}, 1e3);
|
|
return (n.interval = o), n;
|
|
}
|
|
async setStorage(t, e) {
|
|
return this.sendToContentScript("storage.set", [t, e]);
|
|
}
|
|
async sendToContentScript(t, e) {
|
|
const n = Math.random().toString();
|
|
return (
|
|
window.postMessage({
|
|
id: this.extensionId,
|
|
nonce: n,
|
|
type: t,
|
|
data: e,
|
|
}),
|
|
new Promise((t) => {
|
|
const e = (o) => {
|
|
var s, a, i;
|
|
o.source === window &&
|
|
(null === (s = o.data) || void 0 === s ? void 0 : s.id) ===
|
|
this.extensionId &&
|
|
(null === (a = o.data) || void 0 === a ? void 0 : a.nonce) === n &&
|
|
"response" ===
|
|
(null === (i = o.data) || void 0 === i ? void 0 : i.type) &&
|
|
(t(o.data.data), window.removeEventListener("message", e));
|
|
};
|
|
window.addEventListener("message", e);
|
|
})
|
|
);
|
|
}
|
|
}
|
|
|
|
export { e };
|