Browse Source

Make PEE not crash and burn on FF

pull/54/head
coomdev 1 year ago
parent
commit
75ffae164f
  1. 27
      build-ff.js
  2. 22
      firefox/bepis.js
  3. 35
      firefox/kohlchan-hooks.js
  4. 24
      firefox/manifest.json
  5. 2
      firefox/options.html
  6. 2
      firefox_update.json
  7. 48
      src/background.ts
  8. 6
      src/main.ts
  9. 3
      src/platform.ts
  10. 2
      src/websites/index.ts

27
build-ff.js

@ -52,8 +52,9 @@ const domains = [
"https://*.lolibooru.moe/*", "https://*.lolibooru.moe/*",
"https://*.allthefallen.moe/*", "https://*.allthefallen.moe/*",
"https://desu-usergeneratedcontent.xyz/*", "https://desu-usergeneratedcontent.xyz/*",
"https://kohlchan.net/*" "https://kohlchan.net/*",
"https://*.kohlchan.net/*",
"<all_urls>"
]; ];
const manif = { const manif = {
@ -69,6 +70,7 @@ const manif = {
"icons": { "icons": {
"64": "1449696017588.png" "64": "1449696017588.png"
}, },
"host_permissions": ["<all_urls>"],
"permissions": [ "permissions": [
"clipboardWrite", "clipboardWrite",
"webRequest", "webRequest",
@ -81,19 +83,16 @@ const manif = {
"matches": domains, "matches": domains,
"css": [], "css": [],
"run_at": "document_start", "run_at": "document_start",
"js": ["polyfill.min.js", "dist/main.js"], "js": ["dist/main.js"],
} }
], ],
"web_accessible_resources": ["*.html", "*.js",], "web_accessible_resources": ["*.html", "*.js",],
// "background": { "background": {
// persistent: true, "scripts": [
// "scripts": [ "bepis.js"
// "polyfill.min.js", ]
// "browser-polyfill.min.js", }
// "dist/background.js"
// ]
// }
}; };
(async () => { (async () => {
@ -108,7 +107,7 @@ const manif = {
define: { define: {
global: 'window', global: 'window',
execution_mode: '"ff_api"', execution_mode: '"ff_api"',
manifest: manif.version, manifest: manif.manifest_version,
isBackground: 'false', isBackground: 'false',
BUILD_VERSION: JSON.stringify([0, rev]) BUILD_VERSION: JSON.stringify([0, rev])
}, },
@ -130,7 +129,7 @@ const manif = {
define: { define: {
global: 'self', global: 'self',
execution_mode: '"worker"', execution_mode: '"worker"',
manifest: manif.version, manifest: manif.manifest_version,
isBackground: 'false', isBackground: 'false',
BUILD_VERSION: JSON.stringify([0, rev]) BUILD_VERSION: JSON.stringify([0, rev])
}, },
@ -155,7 +154,7 @@ const manif = {
define: { define: {
global: 'window', global: 'window',
execution_mode: '"ff_api"', execution_mode: '"ff_api"',
manifest: manif.version, manifest: manif.manifest_version,
isBackground: 'true', isBackground: 'true',
BUILD_VERSION: JSON.stringify([0, rev]) BUILD_VERSION: JSON.stringify([0, rev])
}, },

22
firefox/bepis.js

@ -0,0 +1,22 @@
const filts = {
urls: ["https://desuarchive.org/*",
"https://arch.b4k.co/*",
"https://kohlchan.net/*"
],
types: ["main_frame", "sub_frame", "csp_report", "object", "other", "ping"]
};
chrome.webRequest.onHeadersReceived.addListener(details => {
const nuke = ['https://arch.b4k.co/', 'https://kohlchan.net/'];
if (nuke.some(u => details.url.startsWith(u)) && details.type == "main_frame") {
const e = details.responseHeaders.findIndex(e => e.name.toLowerCase() == "content-security-policy");
if (e >= 0)
details.responseHeaders[e].value = "";
return {
responseHeaders: [
...details.responseHeaders,
{ name: 'access-control-allow-origin', value: '*' }
]
};
}
}, filts, ['blocking', 'responseHeaders']);

35
firefox/kohlchan-hooks.js

@ -0,0 +1,35 @@
const pc = postCommon;
const pcasf = pc.addSelectedFile.bind(pc);
let prevFile;
pc.addSelectedFile = (f, unk) => {
pcasf(f, unk);
// will only embed in the first file
const refresh = () => {
const currentFile = pc.selectedFiles[0];
if (prevFile != currentFile) {
prevFile = currentFile;
document.dispatchEvent(new CustomEvent("PEEFile", { detail: prevFile }));
}
};
refresh();
const rb = pc.selectedDiv.lastChild?.getElementsByClassName("removeButton")[0];
if (rb)
rb.addEventListener("click", refresh);
};
document.addEventListener("QRSetFile", (e) => {
if (pc.selectedFiles.length > 0)
pc.selectedFiles[0] = e.detail.file;
});
const taup = thread.addUnreadPost.bind(thread);
thread.addUnreadPost = (e) => {
taup(e);
document.dispatchEvent(new CustomEvent("ThreadUpdate", {
detail: {
newPosts: ['b.' + e.postId]
}
}));
}

24
firefox/manifest.json

@ -7,10 +7,13 @@
}, },
"name": "PngExtraEmbedder", "name": "PngExtraEmbedder",
"description": "Discover embedded files on 4chan and archives!", "description": "Discover embedded files on 4chan and archives!",
"version": "0.325", "version": "0.328",
"icons": { "icons": {
"64": "1449696017588.png" "64": "1449696017588.png"
}, },
"host_permissions": [
"<all_urls>"
],
"permissions": [ "permissions": [
"clipboardWrite", "clipboardWrite",
"webRequest", "webRequest",
@ -53,7 +56,10 @@
"https://*.donmai.us/*", "https://*.donmai.us/*",
"https://*.lolibooru.moe/*", "https://*.lolibooru.moe/*",
"https://*.allthefallen.moe/*", "https://*.allthefallen.moe/*",
"https://desu-usergeneratedcontent.xyz/*" "https://desu-usergeneratedcontent.xyz/*",
"https://kohlchan.net/*",
"https://*.kohlchan.net/*",
"<all_urls>"
], ],
"content_scripts": [ "content_scripts": [
{ {
@ -95,12 +101,14 @@
"https://*.donmai.us/*", "https://*.donmai.us/*",
"https://*.lolibooru.moe/*", "https://*.lolibooru.moe/*",
"https://*.allthefallen.moe/*", "https://*.allthefallen.moe/*",
"https://desu-usergeneratedcontent.xyz/*" "https://desu-usergeneratedcontent.xyz/*",
"https://kohlchan.net/*",
"https://*.kohlchan.net/*",
"<all_urls>"
], ],
"css": [], "css": [],
"run_at": "document_start", "run_at": "document_start",
"js": [ "js": [
"polyfill.min.js",
"dist/main.js" "dist/main.js"
] ]
} }
@ -108,5 +116,11 @@
"web_accessible_resources": [ "web_accessible_resources": [
"*.html", "*.html",
"*.js" "*.js"
] ],
"background": {
"persistent": true,
"scripts": [
"bepis.js"
]
}
} }

2
firefox/options.html

@ -1,6 +1,4 @@
<!DOCTYPE html> <!DOCTYPE html>
<body> <body>
<script src="./polyfill.min.js"></script>
<script src="./browser-polyfill.min.js"></script>
<script src="./dist/background.js"></script> <script src="./dist/background.js"></script>
</body> </body>

2
firefox_update.json

@ -1 +1 @@
{"addons":{"{34ac4994-07f2-44d2-8599-682516a6c6a6}":{"updates":[{"version":"0.325","update_link":"https://git.coom.tech/fuckjannies/lolipiss/raw/branch/%E4%B8%AD%E5%87%BA%E3%81%97/pngextraembedder-0.325.xpi"}]}}} {"addons":{"{34ac4994-07f2-44d2-8599-682516a6c6a6}":{"updates":[{"version":"0.328","update_link":"https://git.coom.tech/fuckjannies/lolipiss/raw/branch/%E4%B8%AD%E5%87%BA%E3%81%97/pngextraembedder-0.328.xpi"}]}}}

48
src/background.ts

@ -6,54 +6,6 @@ type Methods<T> = {
[k in Exclude<keyof T, 'prototype'>]: T[k] extends Function ? T[k] : never; [k in Exclude<keyof T, 'prototype'>]: T[k] extends Function ? T[k] : never;
}; };
const types = [
"csp_report",
"font",
"image",
"main_frame",
"media",
"object",
"other",
"ping",
"script",
"stylesheet",
"sub_frame",
"websocket",
"xmlhttprequest"
] as browser.webRequest.ResourceType[];
const filts = {
urls: ["https://boards.4channel.org/*",
"https://boards.4chan.org/*",
"https://desuarchive.org/*",
"https://archived.moe/*",
"https://archive.nyafuu.org/*",
"https://arch.b4k.co/*",
"https://archive.wakarimasen.moe/*",
"https://fireden.net/*",
"https://thebarchive.com/*",
"https://files.catbox.moe/*",
"https://de.catbox.moe/*",
"https://based.coom.tech/*",
"https://archiveofsins.com/*"],
types: ["main_frame", "sub_frame", "csp_report", "object", "other", "ping"] as browser.webRequest.ResourceType[]
};
if (manifest == 2)
obj.webRequest.onHeadersReceived.addListener(details => {
if (details.url.startsWith('https://arch.b4k.co/') && details.type == "main_frame") {
const e = details.responseHeaders!.findIndex(e => e.name.toLowerCase() == "content-security-policy");
if (e >= 0)
details.responseHeaders![e].value = "";
return {
responseHeaders: [
...details.responseHeaders!,
{ name: 'access-control-allow-origin', value: '*' }
]
} as browser.webRequest.BlockingResponse;
}
}, filts, ['blocking', 'responseHeaders', ...(execution_mode == "chrome_api" ? ['extraHeaders' as 'blocking'] : [])]);
async function bravedeserialize(src: any): Promise<any> { async function bravedeserialize(src: any): Promise<any> {
if (typeof src != "object") if (typeof src != "object")
return src; return src;

6
src/main.ts

@ -201,7 +201,7 @@ const signalNewEmbeds = debounce(async () => {
}, 5000, { trailing: true }); }, 5000, { trailing: true });
const shouldUseCache = () => { const shouldUseCache = () => {
if (location.host == "kohlchan.net") if (location.host.includes("kohlchan.net"))
return false; return false;
if (cappState.isCatalog) if (cappState.isCatalog)
return false; return false;
@ -822,7 +822,7 @@ const startup = async (is4chanX = true) => {
} }
}; };
const obs = new MutationObserver(somethingChanged); const obs = new MutationObserver(somethingChanged);
if (location.host == "kohlchan.net") { if (location.host.includes("kohlchan.net")) {
// vanilla kohl, behaves a bit like a mix of the two // vanilla kohl, behaves a bit like a mix of the two
target = e.detail as HTMLDivElement; target = e.detail as HTMLDivElement;
a.style.display = "inline-block"; a.style.display = "inline-block";
@ -875,7 +875,7 @@ const startup = async (is4chanX = true) => {
//return; //return;
} }
if ((!is4chanX && location.host.startsWith('boards.4chan')) || location.host == "kohlchan.net") { if ((!is4chanX && location.host.startsWith('boards.4chan')) || location.host.includes("kohlchan.net")) {
const notificationHost = document.createElement('span'); const notificationHost = document.createElement('span');
new NotificationsHandler({ new NotificationsHandler({
target: notificationHost target: notificationHost

3
src/platform.ts

@ -123,7 +123,8 @@ const altdomains = [
"fireden.net", "fireden.net",
"thebarchive.com", "thebarchive.com",
"archiveofsins.com", "archiveofsins.com",
"kohlchan.net" "kohlchan.net",
"nocsp.kohlchan.net",
]; ];
export function supportedAltDomain(s: string) { export function supportedAltDomain(s: string) {

2
src/websites/index.ts

@ -126,7 +126,7 @@ export const KChan: QueryProcessor = {
export const getQueryProcessor = (is4chanX: boolean) => { export const getQueryProcessor = (is4chanX: boolean) => {
if (['boards.4chan.org', 'boards.4channel.org'].includes(location.host)) if (['boards.4chan.org', 'boards.4channel.org'].includes(location.host))
return is4chanX ? X4chan : V4chan; return is4chanX ? X4chan : V4chan;
if (location.host == 'kohlchan.net') { if (location.host.includes("kohlchan.net")) {
return KChan; return KChan;
} }
if (document.querySelector('meta[name="generator"]')?.getAttribute("content")?.startsWith("FoolFuuka")) if (document.querySelector('meta[name="generator"]')?.getAttribute("content")?.startsWith("FoolFuuka"))

Loading…
Cancel
Save