52 lines
2.0 KiB
JavaScript
52 lines
2.0 KiB
JavaScript
import {
|
|
t
|
|
} from './index-2879cf47.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("pKEWqxalXsGqbmDU")) || void 0 === t ? void 0 : t.getAttribute("pKEWqxalXsGqbmDU");
|
|
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))
|
|
},
|
|
s = window.setInterval((async () => {
|
|
n.value = e(await this.getStorage(t));
|
|
}), 1e3);
|
|
return n.interval = s, 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 = s => {
|
|
var o, a, i;
|
|
s.source === window && (null === (o = s.data) || void 0 === o ? void 0 : o.id) === this.extensionId && (null === (a = s.data) || void 0 === a ? void 0 : a.nonce) === n && "response" === (null === (i = s.data) || void 0 === i ? void 0 : i.type) && (t(s.data.data), window.removeEventListener("message", e));
|
|
};
|
|
window.addEventListener("message", e);
|
|
}))
|
|
}
|
|
}
|
|
|
|
export {
|
|
e
|
|
}; |