aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-11-16 16:23:52 +0100
committerVendicated <vendicated@riseup.net>2022-11-16 16:23:52 +0100
commita788813383213ac1257d47f0e9f566dc72750bcb (patch)
treef763f98466400401389b73619a719841631d7cdd
parente1de6f88fe1db5276cee3df2ef4feeca7fcab850 (diff)
downloadVencord-a788813383213ac1257d47f0e9f566dc72750bcb.tar.gz
Vencord-a788813383213ac1257d47f0e9f566dc72750bcb.tar.bz2
Vencord-a788813383213ac1257d47f0e9f566dc72750bcb.zip
VencordWeb: Migrate to manifest v3
-rw-r--r--browser/background.js24
-rw-r--r--browser/manifest.json46
-rw-r--r--browser/modifyResponseHeaders.json38
-rwxr-xr-xscripts/build/buildWeb.mjs2
4 files changed, 66 insertions, 44 deletions
diff --git a/browser/background.js b/browser/background.js
deleted file mode 100644
index dbe664c..0000000
--- a/browser/background.js
+++ /dev/null
@@ -1,24 +0,0 @@
-if (typeof browser === "undefined") {
- var browser = chrome;
-}
-
-browser.webRequest.onHeadersReceived.addListener(({ responseHeaders, url }) => {
- const cspIdx = responseHeaders.findIndex(h => h.name === "content-security-policy");
- if (cspIdx !== -1)
- responseHeaders.splice(cspIdx, 1);
-
- if (url.endsWith(".css")) {
- const contentType = responseHeaders.find(h => h.name === "content-type");
- if (contentType)
- contentType.value = "text/css";
- else
- responseHeaders.push({
- name: "content-type",
- value: "text/css"
- });
- }
-
- return {
- responseHeaders
- };
-}, { urls: ["*://*.discord.com/*"] }, ["blocking", "responseHeaders"]);
diff --git a/browser/manifest.json b/browser/manifest.json
index 2988ba9..ea79d12 100644
--- a/browser/manifest.json
+++ b/browser/manifest.json
@@ -1,32 +1,40 @@
{
- "manifest_version": 2,
+ "manifest_version": 3,
"name": "Vencord Web",
"description": "Yeee",
"version": "1.0.0",
"author": "Vendicated",
"homepage_url": "https://github.com/Vendicated/Vencord",
- "background": {
- "scripts": [
- "background.js"
- ]
- },
+
+ "host_permissions": [
+ "*://*.discord.com/*",
+ "https://raw.githubusercontent.com/*"
+ ],
+
+ "permissions": ["declarativeNetRequest"],
+
"content_scripts": [
{
"run_at": "document_start",
- "matches": [
- "*://*.discord.com/*"
- ],
- "js": [
- "content.js"
- ]
+ "matches": ["*://*.discord.com/*"],
+ "js": ["content.js"]
}
],
- "permissions": [
- "*://*.discord.com/*",
- "webRequest",
- "webRequestBlocking"
- ],
+
"web_accessible_resources": [
- "dist/Vencord.js"
- ]
+ {
+ "resources": ["dist/Vencord.js"],
+ "matches": ["*://*.discord.com/*"]
+ }
+ ],
+
+ "declarative_net_request": {
+ "rule_resources": [
+ {
+ "id": "modifyResponseHeaders",
+ "enabled": true,
+ "path": "modifyResponseHeaders.json"
+ }
+ ]
+ }
}
diff --git a/browser/modifyResponseHeaders.json b/browser/modifyResponseHeaders.json
new file mode 100644
index 0000000..ed39075
--- /dev/null
+++ b/browser/modifyResponseHeaders.json
@@ -0,0 +1,38 @@
+[
+ {
+ "id": 1,
+ "action": {
+ "type": "modifyHeaders",
+ "responseHeaders": [
+ {
+ "header": "content-security-policy",
+ "operation": "remove"
+ },
+ {
+ "header": "content-security-policy-report-only",
+ "operation": "remove"
+ }
+ ]
+ },
+ "condition": {
+ "resourceTypes": ["main_frame"]
+ }
+ },
+ {
+ "id": 2,
+ "action": {
+ "type": "modifyHeaders",
+ "responseHeaders": [
+ {
+ "header": "content-type",
+ "operation": "set",
+ "value": "text/css"
+ }
+ ]
+ },
+ "condition": {
+ "resourceTypes": ["stylesheet"],
+ "urlFilter": "https://raw.githubusercontent.com/*"
+ }
+ }
+]
diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs
index 1efdd8f..f5be651 100755
--- a/scripts/build/buildWeb.mjs
+++ b/scripts/build/buildWeb.mjs
@@ -76,7 +76,7 @@ zip({
dist: {
"Vencord.js": readFileSync("dist/browser.js")
},
- ...Object.fromEntries(await Promise.all(["background.js", "content.js", "manifest.json"].map(async f => [
+ ...Object.fromEntries(await Promise.all(["modifyResponseHeaders.json", "content.js", "manifest.json"].map(async f => [
f,
await readFile(join("browser", f))
]))),