diff options
-rw-r--r-- | browser/background.js | 28 | ||||
-rw-r--r-- | browser/manifestv2.json | 35 | ||||
-rw-r--r-- | browser/manifestv3.json (renamed from browser/manifest.json) | 0 | ||||
-rwxr-xr-x | scripts/build/buildWeb.mjs | 40 |
4 files changed, 86 insertions, 17 deletions
diff --git a/browser/background.js b/browser/background.js new file mode 100644 index 0000000..9c5ed96 --- /dev/null +++ b/browser/background.js @@ -0,0 +1,28 @@ + +function setContentTypeOnStylesheets(details) { + if (details.type === 'stylesheet') { + details.responseHeaders.push({name: 'Content-Type', value: 'text/css'}) + } + return {responseHeaders: details.responseHeaders } +} + +var cspHeaders = [ + 'content-security-policy', + 'content-security-policy-report-only', +] + +function removeCSPHeaders(details) { + return {responseHeaders: details.responseHeaders.filter(header => + !cspHeaders.includes(header.name.toLowerCase()))} +} + + + + +browser.webRequest.onHeadersReceived.addListener( + setContentTypeOnStylesheets, {urls: ["https://raw.githubusercontent.com/*"]}, ['blocking'] +) + +browser.webRequest.onHeadersReceived.addListener( + removeCSPHeaders, {urls: ["https://raw.githubusercontent.com/*", "*://*.discord.com/*"]}, ['blocking', 'responseHeaders'] +) diff --git a/browser/manifestv2.json b/browser/manifestv2.json new file mode 100644 index 0000000..f18443c --- /dev/null +++ b/browser/manifestv2.json @@ -0,0 +1,35 @@ +{ + "manifest_version": 2, + "name": "Vencord Web", + "description": "Yeee", + "version": "1.0.0", + "author": "Vendicated", + "homepage_url": "https://github.com/Vendicated/Vencord", + "host_permissions": [ + "*://*.discord.com/*", + "https://raw.githubusercontent.com/*" + ], + "permissions": [ + "webRequest", + "webRequestBlocking" + ], + "content_scripts": [ + { + "run_at": "document_start", + "matches": [ + "*://*.discord.com/*" + ], + "js": [ + "content.js" + ] + } + ], + "web_accessible_resources": [ + "dist/Vencord.js" + ], + "background": { + "scripts": [ + "background.js" + ] + } +} diff --git a/browser/manifest.json b/browser/manifestv3.json index ea79d12..ea79d12 100644 --- a/browser/manifest.json +++ b/browser/manifestv3.json diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs index a4ad87f..74f0857 100755 --- a/scripts/build/buildWeb.mjs +++ b/scripts/build/buildWeb.mjs @@ -72,20 +72,26 @@ await Promise.all( ] ); -zip({ - dist: { - "Vencord.js": readFileSync("dist/browser.js") - }, - ...Object.fromEntries(await Promise.all(["modifyResponseHeaders.json", "content.js", "manifest.json"].map(async f => [ - f, - await readFile(join("browser", f)) - ]))), -}, {}, (err, data) => { - if (err) { - console.error(err); - process.exitCode = 1; - } else { - writeFileSync("dist/extension.zip", data); - console.info("Extension written to dist/extension.zip"); - } -}); +async function buildPluginZip(target, files) { + zip({ + dist: { + "Vencord.js": readFileSync("dist/browser.js") + }, + ...Object.fromEntries(await Promise.all(files.map(async f => [ + (f.startsWith("manifest") ? "manifest.json" : f), + await readFile(join("browser", f)) + ]))), + }, {}, (err, data) => { + if (err) { + console.error(err); + process.exitCode = 1; + } else { + writeFileSync("dist/" + target, data); + console.info("Extension written to dist/" + target); + } + }); +} + +await buildPluginZip("extension-v3.zip", ["modifyResponseHeaders.json", "content.js", "manifestv3.json"]); +await buildPluginZip("extension-v2.xpi", ["background.js", "content.js", "manifestv2.json"]); + |