Browse Source

Remove requirement for blob: in 4chanX (fuck you btw)

pull/54/head
coomdev 2 years ago
parent
commit
7a492c77b2
  1. 6
      build-chrome.js
  2. 2
      build-ff.js
  3. 11
      chrome/4chan-x-prevent-csp-inject.js
  4. 29
      chrome/bg.js
  5. 2
      chrome/dist/background.js
  6. 17
      chrome/dist/main.js
  7. 10
      chrome/manifest.json
  8. 37
      esbuild.inject.js
  9. 30
      firefox/dist/background.js
  10. 41
      firefox/dist/main.js
  11. 2
      firefox/manifest.json
  12. 2
      firefox_update.json
  13. 4
      main.d.ts
  14. 1
      src/Components/App.svelte
  15. 11
      src/main.ts

6
build-chrome.js

@ -46,8 +46,13 @@ const manif3 = {
},
permissions: [
"storage",
"activeTab",
"scripting",
"declarativeNetRequestWithHostAccess"
],
background: {
service_worker: "bg.js"
},
"host_permissions": ["<all_urls>"],
web_accessible_resources: [{
resources: ["*.html", "*.js"],
@ -59,6 +64,7 @@ const manif3 = {
css: [],
run_at: "document_start",
js: ["dist/main.js"],
world: "MAIN"
}
],
declarative_net_request: {

2
build-ff.js

@ -79,7 +79,7 @@ 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",],

11
chrome/4chan-x-prevent-csp-inject.js

@ -0,0 +1,11 @@
// This is injected ASAP on 4chan to prevent 4chanX from adding a CSP
// meta tag that prevents the Background WebWorker from running
const ocreate = document.createElement.bind(document);
document.createElement = (tag) => {
if (tag != "meta")
return ocreate(tag);
document.createElement = ocreate; // restore
return document.createElement('link'); // whatever to not make 4chanX crash
};

29
chrome/bg.js

@ -0,0 +1,29 @@
//debugger;
//console.error("LOADING");
chrome.scripting.registerContentScripts(
[{
runAt: "document_start",
world: "MAIN",
js: ["4chan-x-prevent-csp-inject.js"],
id: "0",
matches: [
"https://boards.4chan.org/*",
"https://boards.4channel.org/*"
]
}]
);
chrome.scripting.updateContentScripts(
[{
runAt: "document_start",
world: "MAIN",
js: ["4chan-x-prevent-csp-inject.js"],
id: "0",
matches: [
"https://boards.4chan.org/*",
"https://boards.4channel.org/*"
]
}]
);
//console.error("LOADED");

2
chrome/dist/background.js

@ -1918,7 +1918,7 @@
};
var popupport;
var pendingcmds = {};
if (true) {
if (false) {
popupport = chrome.runtime.connect({ name: "popup" });
popupport.onMessage.addListener((msg) => {
if (msg.id in pendingcmds) {

17
chrome/dist/main.js

@ -73,7 +73,7 @@
var define_BUILD_VERSION_default;
var init_define_BUILD_VERSION = __esm({
"<define:BUILD_VERSION>"() {
define_BUILD_VERSION_default = [0, 320];
define_BUILD_VERSION_default = [0, 323];
}
});
@ -18679,8 +18679,12 @@
} catch {
try {
const content = prompt("Paste it in here") || "";
set_store_value(settings, $settings.rsources = JSON.parse(content), $settings);
} catch {
let v = JSON.parse(content);
if (false)
v = cloneInto(v, window);
set_store_value(settings, $settings.rsources = v, $settings);
} catch (e) {
console.log(e);
alert("How can you fail so badly? pathetic...");
}
}
@ -21907,12 +21911,16 @@ Use the WebExtension version of PEE if you want to use b4k!`);
}
}
});
const meta = document.querySelector('meta[name="referrer"]');
let meta = document.querySelector('meta[name="referrer"]');
const customStyles = document.createElement("style");
customStyles.appendChild(document.createTextNode(global_default));
document.documentElement.insertBefore(customStyles, null);
if (!navigator.userAgent.includes("Firefox") && meta)
meta.setAttribute("content", "no-referrer");
meta = document.createElement("meta");
meta.setAttribute("http-equiv", "Content-Security-Policy");
meta.setAttribute("content", "worker-src 'self' blob:");
document.head.append(meta);
appState.set({ ...cappState, is4chanX });
const lqp = getQueryProcessor(is4chanX);
if (!lqp)
@ -22019,7 +22027,6 @@ Use the WebExtension version of PEE if you want to use b4k!`);
fireNotification("error", "The page you're on has a CSP that prevents PEE from functionning properly.\n\n If using 4chanX, Add 'blob:' to the JS whitelist. Else, install PEE-companion.");
else
fireNotification("error", "You may be using 4chanX\n\nGo to 4chanX's settings, Advanced > JS Whitelist and add 'blob:' without quotes to the list.");
return;
}
if (!is4chanX && location.host.startsWith("boards.4chan")) {
const notificationHost = document.createElement("span");

10
chrome/manifest.json

@ -2,14 +2,19 @@
"manifest_version": 3,
"name": "PngExtraEmbedder",
"description": "Discover embedded files on 4chan and archives!",
"version": "0.320",
"version": "0.323",
"icons": {
"64": "1449696017588.png"
},
"permissions": [
"storage",
"activeTab",
"scripting",
"declarativeNetRequestWithHostAccess"
],
"background": {
"service_worker": "bg.js"
},
"host_permissions": [
"<all_urls>"
],
@ -45,7 +50,8 @@
"run_at": "document_start",
"js": [
"dist/main.js"
]
],
"world": "MAIN"
}
],
"declarative_net_request": {

37
esbuild.inject.js

@ -1 +1,38 @@
export let Buffer = require("buffer").Buffer;
if (!isBackground) {
if (execution_mode == "userscript") {
const ocreate = unsafeWindow.document.createElement.bind(document);
unsafeWindow.document.createElement = (tag) => {
if (tag != "meta")
return ocreate(tag);
unsafeWindow.document.createElement = ocreate; // restore
return unsafeWindow.document.createElement('link'); // whatever to not make 4chanX crash
};
}
if (execution_mode == "ff_api") {
if (typeof cloneInto != "undefined")
console.log("CLONE INTO DEFINED");
else
console.log("CLONE INTO NOT DEFINED");
let a = 1;
console.log(a++);
const unsafeWindow = window;
//const ogdoc = window.wrappedJSObject.document;
console.log(a++);
const ocreate = unsafeWindow.document.createElement.bind(document);
console.log(a++);
exportFunction((tag) => {
if (tag != "meta")
return ocreate(tag);
unsafeWindow.document.createElement = ocreate; // restore
return unsafeWindow.document.createElement('link'); // whatever to not make 4chanX crash
}, window.document, { defineAs: 'createElement' });
console.log(a++);
}
}

30
firefox/dist/background.js

@ -1855,6 +1855,36 @@
"esbuild.inject.js"() {
"use strict";
Buffer2 = require_buffer().Buffer;
if (false) {
if (false) {
const ocreate = unsafeWindow.document.createElement.bind(document);
unsafeWindow.document.createElement = (tag) => {
if (tag != "meta")
return ocreate(tag);
unsafeWindow.document.createElement = ocreate;
return unsafeWindow.document.createElement("link");
};
}
if (true) {
if (typeof cloneInto != "undefined")
console.log("CLONE INTO DEFINED");
else
console.log("CLONE INTO NOT DEFINED");
let a = 1;
console.log(a++);
const unsafeWindow2 = window;
console.log(a++);
const ocreate = unsafeWindow2.document.createElement.bind(document);
console.log(a++);
exportFunction((tag) => {
if (tag != "meta")
return ocreate(tag);
unsafeWindow2.document.createElement = ocreate;
return unsafeWindow2.document.createElement("link");
}, window.document, { defineAs: "createElement" });
console.log(a++);
}
}
}
});

41
firefox/dist/main.js

File diff suppressed because one or more lines are too long

2
firefox/manifest.json

@ -7,7 +7,7 @@
},
"name": "PngExtraEmbedder",
"description": "Discover embedded files on 4chan and archives!",
"version": "0.322",
"version": "0.323",
"icons": {
"64": "1449696017588.png"
},

2
firefox_update.json

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

4
main.d.ts

@ -72,7 +72,7 @@ declare module 'mp4box' {
onReady(info: InfoType): void;
appendBuffer(a: ArrayBuffer, end?: boolean): void;
start(): void;
seek(time: number, useRap: boolean): {offset: number};
seek(time: number, useRap: boolean): { offset: number };
stop(): void;
flush(): void;
setSegmentOptions(id: number, user?: any, options?: {
@ -146,4 +146,4 @@ declare const chrome: typeof browser;
declare const _DOMParser: typeof DOMParser;
declare const manifest: 2 | 3;
declare function GM_addElement(parent: HTMLElement, tagname: string, attrs: Record<string, string>);
declare function cloneInto<T>(e: T, where: Window & typeof globalThis | null): T;
declare function cloneInto<T>(e: T, where: Window & typeof globalThis | null, opts?: { cloneFunctions: boolean }): T;

1
src/Components/App.svelte

@ -86,6 +86,7 @@
eyes: number;
other: number;
}[] = [];
async function updateThreads() {
updating = true;
let params = "";

11
src/main.ts

@ -659,7 +659,7 @@ const startup = async (is4chanX = true) => {
if (init)
return;
init = true;
window.addEventListener("securitypolicyviolation", (e) => {
if (e.blockedURI.startsWith("blob")) {
if (supportedMainDomain(location.host)) {
@ -670,7 +670,7 @@ const startup = async (is4chanX = true) => {
}
});
const meta = document.querySelector('meta[name="referrer"]') as HTMLMetaElement;
let meta = document.querySelector('meta[name="referrer"]') as HTMLMetaElement;
const customStyles = document.createElement('style');
customStyles.appendChild(document.createTextNode(globalCss));
@ -678,6 +678,11 @@ const startup = async (is4chanX = true) => {
if (!navigator.userAgent.includes('Firefox') && meta)
meta.setAttribute('content', 'no-referrer');
meta = document.createElement('meta');
meta.setAttribute("http-equiv", "Content-Security-Policy");
meta.setAttribute("content", "worker-src 'self' blob:");
document.head.append(meta);
appState.set({ ...cappState, is4chanX });
const lqp = getQueryProcessor(is4chanX);
if (!lqp)
@ -803,7 +808,7 @@ const startup = async (is4chanX = true) => {
fireNotification("error", "The page you're on has a CSP that prevents PEE from functionning properly.\n\n If using 4chanX, Add 'blob:' to the JS whitelist. Else, install PEE-companion.");
else
fireNotification("error", "You may be using 4chanX\n\nGo to 4chanX's settings, Advanced > JS Whitelist and add 'blob:' without quotes to the list.");
return;
//return;
}
if (!is4chanX && location.host.startsWith('boards.4chan')) {

Loading…
Cancel
Save