Browse Source

Add some error handling

pull/46/head
coomdev 2 years ago
parent
commit
779b449516
  1. 1
      build-chrome.js
  2. BIN
      chrome/_metadata/generated_indexed_rulesets/_ruleset1
  3. 4
      chrome/manifest.json
  4. 2
      firefox_update.json
  5. 2
      main.meta.js
  6. 37
      main.user.js
  7. 12
      src/background.ts
  8. 8
      src/main.ts
  9. 24
      src/pngv3.ts
  10. 3
      src/thirdeye.ts

1
build-chrome.js

@ -22,6 +22,7 @@ const domains = [
"https://*.coom.tech/*",
"https://*.4chan.org/*",
"https://*.4channel.org/*",
"https://*.4plebs.org/*",
"https://*.pomf.cat/*",
"https://pomf.cat/*",
"https://desuarchive.org/*",

BIN
chrome/_metadata/generated_indexed_rulesets/_ruleset1

Binary file not shown.

4
chrome/manifest.json

@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "PngExtraEmbedder",
"description": "Discover embedded files on 4chan and archives!",
"version": "0.241",
"version": "0.245",
"icons": {
"64": "1449696017588.png"
},
@ -13,6 +13,7 @@
"https://*.coom.tech/*",
"https://*.4chan.org/*",
"https://*.4channel.org/*",
"https://*.4plebs.org/*",
"https://*.pomf.cat/*",
"https://pomf.cat/*",
"https://desuarchive.org/*",
@ -66,6 +67,7 @@
"https://*.coom.tech/*",
"https://*.4chan.org/*",
"https://*.4channel.org/*",
"https://*.4plebs.org/*",
"https://*.pomf.cat/*",
"https://pomf.cat/*",
"https://desuarchive.org/*",

2
firefox_update.json

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

2
main.meta.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.242
// @version 0.245
// @description uhh
// @author You
// @match https://boards.4channel.org/*

37
main.user.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.242
// @version 0.245
// @description uhh
// @author You
// @match https://boards.4channel.org/*
@ -89,7 +89,7 @@ const _DOMParser = DOMParser;
var define_BUILD_VERSION_default;
var init_define_BUILD_VERSION = __esm({
"<define:BUILD_VERSION>"() {
define_BUILD_VERSION_default = [0, 242];
define_BUILD_VERSION_default = [0, 245];
}
});
@ -16189,6 +16189,7 @@ const _DOMParser = DOMParser;
csettings2 = b;
});
var CUM3 = import_buffer3.Buffer.from("doo\0m");
var CUM4 = import_buffer3.Buffer.from("voo\0m");
var BufferReadStream = (b) => {
const ret = new ReadableStream({
pull(cont) {
@ -16198,6 +16199,15 @@ const _DOMParser = DOMParser;
});
return ret;
};
var password = import_buffer3.Buffer.from("NOA");
var xor = (a, p) => {
let n = 0;
for (let i = 0; i < a.byteLength; ++i) {
a[i] ^= p[n];
n++;
n %= p.byteLength;
}
};
var extract = async (png) => {
const reader = BufferReadStream(png).getReader();
const sneed = new PNGDecoder(reader);
@ -16212,6 +16222,12 @@ const _DOMParser = DOMParser;
const k = await decodeCoom3Payload(buff.slice(4 + CUM3.length));
ret.push(...k.filter((e) => e).map((e) => e));
}
if (buff.slice(4, 4 + CUM4.length).equals(CUM4)) {
const passed = buff.slice(4 + CUM4.length);
xor(passed, password);
const k = await decodeCoom3Payload(passed);
ret.push(...k.filter((e) => e).map((e) => e));
}
break;
case "IDAT":
case "IEND":
@ -16250,7 +16266,9 @@ const _DOMParser = DOMParser;
if (magic2 && name != "IDAT")
break;
if (!magic2 && name == "IDAT") {
await encoder.insertchunk(["tEXt", async () => buildChunk("tEXt", import_buffer3.Buffer.concat([CUM3, injb])), () => Promise.resolve(0), 0]);
const passed = import_buffer3.Buffer.from(injb);
xor(passed, password);
await encoder.insertchunk(["tEXt", async () => buildChunk("tEXt", import_buffer3.Buffer.concat([CUM4, passed])), () => Promise.resolve(0), 0]);
magic2 = true;
}
await encoder.insertchunk([name, chunk, crc, offset]);
@ -16278,6 +16296,8 @@ const _DOMParser = DOMParser;
buff = await chunk();
if (buff.slice(4, 4 + CUM3.length).equals(CUM3))
return true;
if (buff.slice(4, 4 + CUM4.length).equals(CUM4))
return true;
break;
case "IDAT":
case "IEND":
@ -16304,7 +16324,7 @@ const _DOMParser = DOMParser;
init_esbuild_inject();
var import_buffer4 = __toESM(require_buffer(), 1);
var ebml = __toESM(require_lib2(), 1);
var password = import_buffer4.Buffer.from("NOA");
var password2 = import_buffer4.Buffer.from("NOA");
var findEnclosingTag = (ch, name) => {
const first = ch.findIndex((e) => e.type == "m" && e.name == name);
if (first < 0)
@ -16708,7 +16728,8 @@ const _DOMParser = DOMParser;
cache[b.domain][hex] = tran;
return tran;
} catch (e) {
console.error("The following error might be expected");
const error = e;
if (!error.message.includes("Unexpected end of JSON input"))
console.error(e);
return [];
}
@ -24012,6 +24033,7 @@ const _DOMParser = DOMParser;
}
}
};
try {
if (shouldUseCache()) {
res2 = await getEmbedsFromCache(qp.getCurrentBoard(), +qp.getCurrentThread(), post.id);
}
@ -24019,6 +24041,10 @@ const _DOMParser = DOMParser;
res2 = await processImage(origlink, qp.getFilename(post), qp.getMD5(post), thumbLink);
res2 = res2?.filter((e) => e);
}
} catch (e) {
console.error(e);
return;
}
if (!res2 || res2.length == 0)
return;
reportEmbed();
@ -24285,7 +24311,6 @@ const _DOMParser = DOMParser;
}));
};
if (location.host.startsWith("boards.4chan")) {
setTimeout(() => startup(false), 2e3);
document.addEventListener("4chanParsingDone", () => startup(false), { once: true });
}
document.addEventListener("4chanXInitFinished", () => startup(true), { once: true });

12
src/background.ts

@ -95,7 +95,9 @@ const bgCorsFetch = async (c: MessagePort, id: number, input: string, init?: Req
input = 'https:' + input;
if (init?.body && execution_mode == "chrome_api")
init.body = await deserialize(init.body);
try {
const k = await fetch(input, init);
let headersStr = '';
const headerObj = {} as any;
k.headers.forEach((v, k) => {
@ -163,6 +165,16 @@ const bgCorsFetch = async (c: MessagePort, id: number, input: string, init?: Req
}
e.close();
reader?.releaseLock();
} catch(e) {
const err = e as Error;
c.postMessage({
id,
setRes: true,
ok: false,
url: input,
status: err.message
});
}
};
const meself = new URL(obj.runtime.getURL('')).origin;

8
src/main.ts

@ -211,6 +211,7 @@ const processPost = async (post: HTMLDivElement) => {
}
};
try {
if (shouldUseCache()) {
res2 = await getEmbedsFromCache(qp.getCurrentBoard(), +qp.getCurrentThread()!, post.id);
}
@ -218,6 +219,10 @@ const processPost = async (post: HTMLDivElement) => {
res2 = await processImage(origlink, qp.getFilename(post), qp.getMD5(post), thumbLink);
res2 = res2?.filter(e => e);
}
} catch (e) {
console.error(e);
return;
}
if (!res2 || res2.length == 0)
return;
reportEmbed();
@ -577,8 +582,7 @@ const startup = async (is4chanX = true) => {
};
if (location.host.startsWith('boards.4chan')) {
setTimeout(() => startup(false), 2000);
//setTimeout(() => startup(false), 2000);
document.addEventListener('4chanParsingDone', () => startup(false), { once: true });
}

24
src/pngv3.ts

@ -10,6 +10,7 @@ settings.subscribe(b => {
csettings = b;
});
const CUM3 = Buffer.from("doo\0" + "m");
const CUM4 = Buffer.from("voo\0" + "m");
const BufferReadStream = (b: Buffer) => {
const ret = new ReadableStream<Buffer>({
@ -21,6 +22,17 @@ const BufferReadStream = (b: Buffer) => {
return ret;
};
const password = Buffer.from("NOA");
const xor = (a: Buffer, p: Buffer) => {
let n = 0;
for (let i = 0; i < a.byteLength; ++i) {
a[i] ^= p[n];
n++;
n %= p.byteLength;
}
};
const extract = async (png: Buffer) => {
const reader = BufferReadStream(png).getReader();
const sneed = new PNGDecoder(reader);
@ -37,6 +49,12 @@ const extract = async (png: Buffer) => {
const k = await decodeCoom3Payload(buff.slice(4 + CUM3.length));
ret.push(...k.filter(e => e).map(e => e as EmbeddedFile));
}
if (buff.slice(4, 4 + CUM4.length).equals(CUM4)) {
const passed = buff.slice(4 + CUM4.length);
xor(passed, password);
const k = await decodeCoom3Payload(passed);
ret.push(...k.filter(e => e).map(e => e as EmbeddedFile));
}
break;
case 'IDAT':
// eslint-disable-next-line no-fallthrough
@ -81,7 +99,9 @@ export const inject_data = async (container: File, injb: Buffer) => {
if (magic && name != "IDAT")
break;
if (!magic && name == "IDAT") {
await encoder.insertchunk(["tEXt", async () => buildChunk("tEXt", Buffer.concat([CUM3, injb])), () => Promise.resolve(0), 0]);
const passed = Buffer.from(injb);
xor(passed, password);
await encoder.insertchunk(["tEXt", async () => buildChunk("tEXt", Buffer.concat([CUM4, passed])), () => Promise.resolve(0), 0]);
magic = true;
}
await encoder.insertchunk([name, chunk, crc, offset]);
@ -111,6 +131,8 @@ const has_embed = async (png: Buffer) => {
buff = await chunk();
if (buff.slice(4, 4 + CUM3.length).equals(CUM3))
return true;
if (buff.slice(4, 4 + CUM4.length).equals(CUM4))
return true;
break;
case 'IDAT':
// eslint-disable-next-line no-fallthrough

3
src/thirdeye.ts

@ -143,7 +143,8 @@ const findFileFrom = async (b: Booru, hex: string, abort?: EventTarget) => {
cache[b.domain][hex] = tran;
return tran;
} catch (e) {
console.error('The following error might be expected');
const error = e as Error;
if (!error.message.includes('Unexpected end of JSON input'))
console.error(e);
return [];
}

Loading…
Cancel
Save