Fix Monaco

This commit is contained in:
thororen1234 2024-06-22 09:59:51 -04:00
commit a40ef29b3a
6 changed files with 74 additions and 40 deletions

View file

@ -2,23 +2,22 @@ if (typeof browser === "undefined") {
var browser = chrome; 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"); const style = document.createElement("link");
style.type = "text/css"; style.type = "text/css";
style.rel = "stylesheet"; style.rel = "stylesheet";
style.href = browser.runtime.getURL("dist/Vencord.css"); style.href = browser.runtime.getURL("dist/Vencord.css");
document.documentElement.append(script);
document.addEventListener( document.addEventListener(
"DOMContentLoaded", "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 } { once: true }
); );

View file

@ -18,13 +18,17 @@
"content_scripts": [ "content_scripts": [
{ {
"run_at": "document_start", "run_at": "document_start",
"matches": [ "matches": ["*://*.discord.com/*"],
"*://*.discord.com/*" "js": ["content.js"],
], "all_frames": true,
"js": [ "world": "ISOLATED"
"content.js" },
], {
"all_frames": true "run_at": "document_start",
"matches": ["*://*.discord.com/*"],
"js": ["dist/Vencord.js"],
"all_frames": true,
"world": "MAIN"
} }
], ],
"web_accessible_resources": [ "web_accessible_resources": [

View file

@ -17,13 +17,17 @@
"content_scripts": [ "content_scripts": [
{ {
"run_at": "document_start", "run_at": "document_start",
"matches": [ "matches": ["*://*.discord.com/*"],
"*://*.discord.com/*" "js": ["content.js"],
], "all_frames": true,
"js": [ "world": "ISOLATED"
"content.js" },
], {
"all_frames": true "run_at": "document_start",
"matches": ["*://*.discord.com/*"],
"js": ["dist/Vencord.js"],
"all_frames": true,
"world": "MAIN"
} }
], ],
"background": { "background": {

View file

@ -1,7 +1,7 @@
{ {
"name": "vencord", "name": "vencord",
"private": "true", "private": "true",
"version": "1.9.0", "version": "1.9.1",
"description": "The other cutest Discord client mod", "description": "The other cutest Discord client mod",
"homepage": "https://github.com/Equicord/Equicord#readme", "homepage": "https://github.com/Equicord/Equicord#readme",
"bugs": { "bugs": {

View file

@ -4,6 +4,9 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>Equicord QuickCSS Editor</title> <title>Equicord QuickCSS Editor</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monaco-editor@0.50.0/min/vs/editor/editor.main.css"
integrity="sha256-tiJPQ2O04z/pZ/AwdyIghrOMzewf+PIvEl1YKbQvsZk=" crossorigin="anonymous"
referrerpolicy="no-referrer" />
<style> <style>
html, html,
body, body,
@ -22,17 +25,36 @@
<body> <body>
<div id="container"></div> <div id="container"></div>
<script src="https://cdn.jsdelivr.net/npm/monaco-editor@0.50.0/min/vs/loader.js"
integrity="sha256-KcU48TGr84r7unF7J5IgBo95aeVrEbrGe04S7TcFUjs=" crossorigin="anonymous"
referrerpolicy="no-referrer"></script>
<script> <script>
const script = document.createElement("script"); require.config({
script.src = new URL("/dist/monaco/index.js", baseUrl); paths: {
vs: "https://cdn.jsdelivr.net/npm/monaco-editor@0.50.0/min/vs",
},
});
const style = document.createElement("link"); require(["vs/editor/editor.main"], () => {
style.type = "text/css"; getCurrentCss().then((css) => {
style.rel = "stylesheet"; var editor = monaco.editor.create(
style.href = new URL("/dist/monaco/index.css", baseUrl); document.getElementById("container"),
{
document.body.append(style, script); value: css,
language: "css",
theme: getTheme(),
}
);
editor.onDidChangeModelContent(() =>
setCss(editor.getValue())
);
window.addEventListener("resize", () => {
// make monaco re-layout
editor.layout();
});
});
});
</script> </script>
</body> </body>

View file

@ -8,7 +8,12 @@ export let EXTENSION_BASE_URL: string;
export let EXTENSION_VERSION: string; export let EXTENSION_VERSION: string;
if (IS_EXTENSION) { if (IS_EXTENSION) {
const script = document.querySelector("#vencord-script") as HTMLScriptElement; const listener = (e: MessageEvent) => {
EXTENSION_BASE_URL = script.dataset.extensionBaseUrl!; if (e.data?.type === "vencord:meta") {
EXTENSION_VERSION = script.dataset.version!; ({ EXTENSION_BASE_URL, EXTENSION_VERSION } = e.data.meta);
window.removeEventListener("message", listener);
}
};
window.addEventListener("message", listener);
} }