firefox: Fix csp (QuickCss, themes, some plugins) (#554)
parent
76e74b3e40
commit
5305447f44
@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* @template T
|
||||||
|
* @param {T[]} arr
|
||||||
|
* @param {(v: T) => boolean} predicate
|
||||||
|
*/
|
||||||
|
function removeFirst(arr, predicate) {
|
||||||
|
const idx = arr.findIndex(predicate);
|
||||||
|
if (idx !== -1) arr.splice(idx, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
chrome.webRequest.onHeadersReceived.addListener(
|
||||||
|
({ responseHeaders, type, url }) => {
|
||||||
|
if (!responseHeaders) return;
|
||||||
|
|
||||||
|
if (type === "main_frame") {
|
||||||
|
// In main frame requests, the CSP needs to be removed to enable fetching of custom css
|
||||||
|
// as desired by the user
|
||||||
|
removeFirst(responseHeaders, h => h.name.toLowerCase() === "content-security-policy");
|
||||||
|
} else if (type === "stylesheet" && url.startsWith("https://raw.githubusercontent.com")) {
|
||||||
|
// Most users will load css from GitHub, but GitHub doesn't set the correct content type,
|
||||||
|
// so we fix it here
|
||||||
|
removeFirst(responseHeaders, h => h.name.toLowerCase() === "content-type");
|
||||||
|
responseHeaders.push({
|
||||||
|
name: "Content-Type",
|
||||||
|
value: "text/css"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return { responseHeaders };
|
||||||
|
},
|
||||||
|
{ urls: ["https://raw.githubusercontent.com/*", "*://*.discord.com/*"], types: ["main_frame", "stylesheet"] },
|
||||||
|
["blocking", "responseHeaders"]
|
||||||
|
);
|
@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"manifest_version": 2,
|
||||||
|
"minimum_chrome_version": "91",
|
||||||
|
|
||||||
|
"name": "Vencord Web",
|
||||||
|
"description": "The cutest Discord mod now in your browser",
|
||||||
|
"author": "Vendicated",
|
||||||
|
"homepage_url": "https://github.com/Vendicated/Vencord",
|
||||||
|
"icons": {
|
||||||
|
"128": "icon.png"
|
||||||
|
},
|
||||||
|
|
||||||
|
"permissions": [
|
||||||
|
"webRequest",
|
||||||
|
"webRequestBlocking",
|
||||||
|
"*://*.discord.com/*",
|
||||||
|
"https://raw.githubusercontent.com/*"
|
||||||
|
],
|
||||||
|
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"run_at": "document_start",
|
||||||
|
"matches": ["*://*.discord.com/*"],
|
||||||
|
"js": ["content.js"],
|
||||||
|
"all_frames": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
"background": {
|
||||||
|
"scripts": ["background.js"]
|
||||||
|
},
|
||||||
|
|
||||||
|
"web_accessible_resources": ["dist/Vencord.js", "dist/Vencord.css"],
|
||||||
|
|
||||||
|
"browser_specific_settings": {
|
||||||
|
"gecko": {
|
||||||
|
"id": "vencord-firefox@vendicated.dev",
|
||||||
|
"strict_min_version": "91.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue