web extension: fix vencord sometimes breaking after reloading
Co-Authored-By: vee <vendicated+git@riseup.net>
This commit is contained in:
parent
3d46f19025
commit
87d3e30ebf
|
@ -2,23 +2,22 @@ if (typeof browser === "undefined") {
|
|||
var browser = chrome;
|
||||
}
|
||||
|
||||
const script = document.createElement("script");
|
||||
script.src = browser.runtime.getURL("dist/Vencord.js");
|
||||
script.id = "vencord-script";
|
||||
Object.assign(script.dataset, {
|
||||
extensionBaseUrl: browser.runtime.getURL(""),
|
||||
version: browser.runtime.getManifest().version
|
||||
});
|
||||
|
||||
const style = document.createElement("link");
|
||||
style.type = "text/css";
|
||||
style.rel = "stylesheet";
|
||||
style.href = browser.runtime.getURL("dist/Vencord.css");
|
||||
|
||||
document.documentElement.append(script);
|
||||
|
||||
document.addEventListener(
|
||||
"DOMContentLoaded",
|
||||
() => document.documentElement.append(style),
|
||||
() => {
|
||||
document.documentElement.append(style);
|
||||
window.postMessage({
|
||||
type: "vencord:meta",
|
||||
meta: {
|
||||
EXTENSION_VERSION: browser.runtime.getManifest().version,
|
||||
EXTENSION_BASE_URL: browser.runtime.getURL(""),
|
||||
}
|
||||
});
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
|
|
|
@ -22,7 +22,15 @@
|
|||
"run_at": "document_start",
|
||||
"matches": ["*://*.discord.com/*"],
|
||||
"js": ["content.js"],
|
||||
"all_frames": true
|
||||
"all_frames": true,
|
||||
"world": "ISOLATED"
|
||||
},
|
||||
{
|
||||
"run_at": "document_start",
|
||||
"matches": ["*://*.discord.com/*"],
|
||||
"js": ["dist/Vencord.js"],
|
||||
"all_frames": true,
|
||||
"world": "MAIN"
|
||||
}
|
||||
],
|
||||
|
||||
|
|
|
@ -22,7 +22,15 @@
|
|||
"run_at": "document_start",
|
||||
"matches": ["*://*.discord.com/*"],
|
||||
"js": ["content.js"],
|
||||
"all_frames": true
|
||||
"all_frames": true,
|
||||
"world": "ISOLATED"
|
||||
},
|
||||
{
|
||||
"run_at": "document_start",
|
||||
"matches": ["*://*.discord.com/*"],
|
||||
"js": ["dist/Vencord.js"],
|
||||
"all_frames": true,
|
||||
"world": "MAIN"
|
||||
}
|
||||
],
|
||||
|
||||
|
|
|
@ -8,7 +8,12 @@ export let EXTENSION_BASE_URL: string;
|
|||
export let EXTENSION_VERSION: string;
|
||||
|
||||
if (IS_EXTENSION) {
|
||||
const script = document.querySelector("#vencord-script") as HTMLScriptElement;
|
||||
EXTENSION_BASE_URL = script.dataset.extensionBaseUrl!;
|
||||
EXTENSION_VERSION = script.dataset.version!;
|
||||
const listener = (e: MessageEvent) => {
|
||||
if (e.data?.type === "vencord:meta") {
|
||||
({ EXTENSION_BASE_URL, EXTENSION_VERSION } = e.data.meta);
|
||||
window.removeEventListener("message", listener);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("message", listener);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue