Bundle dependencies with extensions for webstore rule compliance (#1740)
parent
efb88a4df8
commit
41f5d71e38
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2023 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import "./patch-worker";
|
||||
|
||||
import * as monaco from "monaco-editor/esm/vs/editor/editor.main.js";
|
||||
|
||||
declare global {
|
||||
const baseUrl: string;
|
||||
const getCurrentCss: () => Promise<string>;
|
||||
const setCss: (css: string) => void;
|
||||
const getTheme: () => string;
|
||||
}
|
||||
|
||||
const BASE = "/dist/monaco/vs";
|
||||
|
||||
self.MonacoEnvironment = {
|
||||
getWorkerUrl(_moduleId: unknown, label: string) {
|
||||
const path = label === "css" ? "/language/css/css.worker.js" : "/editor/editor.worker.js";
|
||||
return new URL(BASE + path, baseUrl).toString();
|
||||
}
|
||||
};
|
||||
|
||||
getCurrentCss().then(css => {
|
||||
const editor = monaco.editor.create(
|
||||
document.getElementById("container")!,
|
||||
{
|
||||
value: css,
|
||||
language: "css",
|
||||
theme: getTheme(),
|
||||
}
|
||||
);
|
||||
editor.onDidChangeModelContent(() =>
|
||||
setCss(editor.getValue())
|
||||
);
|
||||
window.addEventListener("resize", () => {
|
||||
// make monaco re-layout
|
||||
editor.layout();
|
||||
});
|
||||
});
|
@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Vencord QuickCSS Editor</title>
|
||||
<style>
|
||||
html,
|
||||
body,
|
||||
#container {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="container"></div>
|
||||
|
||||
<script>
|
||||
const script = document.createElement("script");
|
||||
script.src = new URL("/dist/monaco/index.js", baseUrl);
|
||||
|
||||
const style = document.createElement("link");
|
||||
style.type = "text/css";
|
||||
style.rel = "stylesheet";
|
||||
style.href = new URL("/dist/monaco/index.css", baseUrl);
|
||||
|
||||
document.body.append(style, script);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
Copyright 2013 Rob Wu <gwnRob@gmail.com>
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
// Target: Chrome 20+
|
||||
|
||||
// W3-compliant Worker proxy.
|
||||
// This module replaces the global Worker object.
|
||||
// When invoked, the default Worker object is called.
|
||||
// If this call fails with SECURITY_ERR, the script is fetched
|
||||
// using async XHR, and transparently proxies all calls and
|
||||
// setters/getters to the new Worker object.
|
||||
// Note: This script does not magically circumvent the Same origin policy.
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var Worker_ = window.Worker;
|
||||
var URL = window.URL || window.webkitURL;
|
||||
// Create dummy worker for the following purposes:
|
||||
// 1. Don't override the global Worker object if the fallback isn't
|
||||
// going to work (future API changes?)
|
||||
// 2. Use it to trigger early validation of postMessage calls
|
||||
// Note: Blob constructor is supported since Chrome 20, but since
|
||||
// some of the used Chrome APIs are only supported as of Chrome 20,
|
||||
// I don't bother adding a BlobBuilder fallback.
|
||||
var dummyWorker = new Worker_(
|
||||
URL.createObjectURL(new Blob([], { type: 'text/javascript' })));
|
||||
window.Worker = function Worker(scriptURL) {
|
||||
if (arguments.length === 0) {
|
||||
throw new TypeError('Not enough arguments');
|
||||
}
|
||||
try {
|
||||
return new Worker_(scriptURL);
|
||||
} catch (e) {
|
||||
if (e.code === 18/*DOMException.SECURITY_ERR*/) {
|
||||
return new WorkerXHR(scriptURL);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
// Bind events and replay queued messages
|
||||
function bindWorker(worker, workerURL) {
|
||||
if (worker._terminated) {
|
||||
return;
|
||||
}
|
||||
worker.Worker = new Worker_(workerURL);
|
||||
worker.Worker.onerror = worker._onerror;
|
||||
worker.Worker.onmessage = worker._onmessage;
|
||||
var o;
|
||||
while ((o = worker._replayQueue.shift())) {
|
||||
worker.Worker[o.method].apply(worker.Worker, o.arguments);
|
||||
}
|
||||
while ((o = worker._messageQueue.shift())) {
|
||||
worker.Worker.postMessage.apply(worker.Worker, o);
|
||||
}
|
||||
}
|
||||
function WorkerXHR(scriptURL) {
|
||||
var worker = this;
|
||||
var x = new XMLHttpRequest();
|
||||
x.responseType = 'blob';
|
||||
x.onload = function () {
|
||||
// http://stackoverflow.com/a/10372280/938089
|
||||
var workerURL = URL.createObjectURL(x.response);
|
||||
bindWorker(worker, workerURL);
|
||||
};
|
||||
x.open('GET', scriptURL);
|
||||
x.send();
|
||||
worker._replayQueue = [];
|
||||
worker._messageQueue = [];
|
||||
}
|
||||
WorkerXHR.prototype = {
|
||||
constructor: Worker_,
|
||||
terminate: function () {
|
||||
if (!this._terminated) {
|
||||
this._terminated = true;
|
||||
if (this.Worker)
|
||||
this.Worker.terminate();
|
||||
}
|
||||
},
|
||||
postMessage: function (message, transfer) {
|
||||
if (!(this instanceof WorkerXHR))
|
||||
throw new TypeError('Illegal invocation');
|
||||
if (this.Worker) {
|
||||
this.Worker.postMessage.apply(this.Worker, arguments);
|
||||
} else {
|
||||
// Trigger validation:
|
||||
dummyWorker.postMessage(message);
|
||||
// Alright, push the valid message to the queue.
|
||||
this._messageQueue.push(arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
// Implement the EventTarget interface
|
||||
[
|
||||
'addEventListener',
|
||||
'removeEventListener',
|
||||
'dispatchEvent'
|
||||
].forEach(function (method) {
|
||||
WorkerXHR.prototype[method] = function () {
|
||||
if (!(this instanceof WorkerXHR)) {
|
||||
throw new TypeError('Illegal invocation');
|
||||
}
|
||||
if (this.Worker) {
|
||||
this.Worker[method].apply(this.Worker, arguments);
|
||||
} else {
|
||||
this._replayQueue.push({ method: method, arguments: arguments });
|
||||
}
|
||||
};
|
||||
});
|
||||
Object.defineProperties(WorkerXHR.prototype, {
|
||||
onmessage: {
|
||||
get: function () { return this._onmessage || null; },
|
||||
set: function (func) {
|
||||
this._onmessage = typeof func === 'function' ? func : null;
|
||||
}
|
||||
},
|
||||
onerror: {
|
||||
get: function () { return this._onerror || null; },
|
||||
set: function (func) {
|
||||
this._onerror = typeof func === 'function' ? func : null;
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 翠 / green
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2023 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
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!;
|
||||
}
|
Loading…
Reference in new issue