diff --git a/build-ff.js b/build-ff.js index e363c17..f6910b9 100644 --- a/build-ff.js +++ b/build-ff.js @@ -52,8 +52,9 @@ const domains = [ "https://*.lolibooru.moe/*", "https://*.allthefallen.moe/*", "https://desu-usergeneratedcontent.xyz/*", - "https://kohlchan.net/*" - + "https://kohlchan.net/*", + "https://*.kohlchan.net/*", + "" ]; const manif = { @@ -69,6 +70,7 @@ const manif = { "icons": { "64": "1449696017588.png" }, + "host_permissions": [""], "permissions": [ "clipboardWrite", "webRequest", @@ -81,19 +83,16 @@ const manif = { "matches": domains, "css": [], "run_at": "document_start", - "js": ["polyfill.min.js", "dist/main.js"], + "js": ["dist/main.js"], } ], "web_accessible_resources": ["*.html", "*.js",], - // "background": { - // persistent: true, - // "scripts": [ - // "polyfill.min.js", - // "browser-polyfill.min.js", - // "dist/background.js" - // ] - // } + "background": { + "scripts": [ + "bepis.js" + ] + } }; (async () => { @@ -108,7 +107,7 @@ const manif = { define: { global: 'window', execution_mode: '"ff_api"', - manifest: manif.version, + manifest: manif.manifest_version, isBackground: 'false', BUILD_VERSION: JSON.stringify([0, rev]) }, @@ -130,7 +129,7 @@ const manif = { define: { global: 'self', execution_mode: '"worker"', - manifest: manif.version, + manifest: manif.manifest_version, isBackground: 'false', BUILD_VERSION: JSON.stringify([0, rev]) }, @@ -155,7 +154,7 @@ const manif = { define: { global: 'window', execution_mode: '"ff_api"', - manifest: manif.version, + manifest: manif.manifest_version, isBackground: 'true', BUILD_VERSION: JSON.stringify([0, rev]) }, diff --git a/firefox/bepis.js b/firefox/bepis.js new file mode 100644 index 0000000..a4e8724 --- /dev/null +++ b/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']); diff --git a/firefox/kohlchan-hooks.js b/firefox/kohlchan-hooks.js new file mode 100644 index 0000000..3c8c51d --- /dev/null +++ b/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] + } + })); +} \ No newline at end of file diff --git a/firefox/manifest.json b/firefox/manifest.json index a7a51a4..cbb8b9c 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -7,10 +7,13 @@ }, "name": "PngExtraEmbedder", "description": "Discover embedded files on 4chan and archives!", - "version": "0.325", + "version": "0.328", "icons": { "64": "1449696017588.png" }, + "host_permissions": [ + "" + ], "permissions": [ "clipboardWrite", "webRequest", @@ -53,7 +56,10 @@ "https://*.donmai.us/*", "https://*.lolibooru.moe/*", "https://*.allthefallen.moe/*", - "https://desu-usergeneratedcontent.xyz/*" + "https://desu-usergeneratedcontent.xyz/*", + "https://kohlchan.net/*", + "https://*.kohlchan.net/*", + "" ], "content_scripts": [ { @@ -95,12 +101,14 @@ "https://*.donmai.us/*", "https://*.lolibooru.moe/*", "https://*.allthefallen.moe/*", - "https://desu-usergeneratedcontent.xyz/*" + "https://desu-usergeneratedcontent.xyz/*", + "https://kohlchan.net/*", + "https://*.kohlchan.net/*", + "" ], "css": [], "run_at": "document_start", "js": [ - "polyfill.min.js", "dist/main.js" ] } @@ -108,5 +116,11 @@ "web_accessible_resources": [ "*.html", "*.js" - ] + ], + "background": { + "persistent": true, + "scripts": [ + "bepis.js" + ] + } } \ No newline at end of file diff --git a/firefox/options.html b/firefox/options.html index 7f3ebdc..bf25fd4 100644 --- a/firefox/options.html +++ b/firefox/options.html @@ -1,6 +1,4 @@ - - diff --git a/firefox_update.json b/firefox_update.json index 56bba48..0faea5a 100644 --- a/firefox_update.json +++ b/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"}]}}} \ No newline at end of file +{"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"}]}}} \ No newline at end of file diff --git a/src/background.ts b/src/background.ts index 5b45c21..8c4669b 100644 --- a/src/background.ts +++ b/src/background.ts @@ -6,54 +6,6 @@ type Methods = { [k in Exclude]: 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 { if (typeof src != "object") return src; diff --git a/src/main.ts b/src/main.ts index 574888d..323e4bb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -201,7 +201,7 @@ const signalNewEmbeds = debounce(async () => { }, 5000, { trailing: true }); const shouldUseCache = () => { - if (location.host == "kohlchan.net") + if (location.host.includes("kohlchan.net")) return false; if (cappState.isCatalog) return false; @@ -822,7 +822,7 @@ const startup = async (is4chanX = true) => { } }; 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 target = e.detail as HTMLDivElement; a.style.display = "inline-block"; @@ -875,7 +875,7 @@ const startup = async (is4chanX = true) => { //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'); new NotificationsHandler({ target: notificationHost diff --git a/src/platform.ts b/src/platform.ts index 5b002bb..624f78c 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -123,7 +123,8 @@ const altdomains = [ "fireden.net", "thebarchive.com", "archiveofsins.com", - "kohlchan.net" + "kohlchan.net", + "nocsp.kohlchan.net", ]; export function supportedAltDomain(s: string) { diff --git a/src/websites/index.ts b/src/websites/index.ts index cb3ff0e..6679e0a 100644 --- a/src/websites/index.ts +++ b/src/websites/index.ts @@ -126,7 +126,7 @@ export const KChan: QueryProcessor = { export const getQueryProcessor = (is4chanX: boolean) => { if (['boards.4chan.org', 'boards.4channel.org'].includes(location.host)) return is4chanX ? X4chan : V4chan; - if (location.host == 'kohlchan.net') { + if (location.host.includes("kohlchan.net")) { return KChan; } if (document.querySelector('meta[name="generator"]')?.getAttribute("content")?.startsWith("FoolFuuka"))