Browse Source

Use both clipboard writing method in case one doesn't work. Fix omorashi on 404 on load

pull/46/head
coomdev 2 years ago
parent
commit
59f28fc30e
  1. 2
      main.meta.js
  2. 23
      main.user.js
  3. 21
      src/main.ts

2
main.meta.js

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

23
main.user.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.155
// @version 0.156
// @description uhh
// @author You
// @match https://boards.4channel.org/*
@ -18555,6 +18555,7 @@
document.execCommand("copy");
copyFrom.blur();
document.body.removeChild(copyFrom);
navigator.clipboard.writeText(text2);
}
var scrapeBoard = async (self) => {
self.disabled = true;
@ -18563,7 +18564,14 @@
const res = await GM_fetch(`https://a.4cdn.org/${boardname}/threads.json`);
const pages = await res.json();
fireNotification("info", "Fetching all threads...");
const threads = await Promise.all(pages.reduce((a, b) => [...a, ...b.threads], []).map((e) => e.no).map((id) => GM_fetch(`https://a.4cdn.org/${boardname}/thread/${id}.json`).then((e) => e.json())));
const threads = (await Promise.all(pages.reduce((a, b) => [...a, ...b.threads], []).map((e) => e.no).map(async (id) => {
try {
const res2 = await GM_fetch(`https://a.4cdn.org/${boardname}/thread/${id}.json`);
return await res2.json();
} catch {
return void 0;
}
}))).filter((e) => e).map((e) => e);
const filenames = threads.reduce((a, b) => [...a, ...b.posts.filter((p) => p.ext).map((p) => p)], []).filter((p) => p.ext != ".webm" && p.ext != ".gif").map((p) => [p.resto || p.no, `https://i.4cdn.org/${boardname}/${p.tim}${p.ext}`, p.md5, p.filename + p.ext]);
console.log(filenames);
fireNotification("info", "Analyzing images...");
@ -18625,6 +18633,11 @@
const text2 = Object.entries(counters).sort((a, b) => b[1] - a[1]).map((e) => `>>${e[0]} (${e[1]})`).join("\n");
console.log(text2);
copyTextToClipboard(text2);
self.textContent = "Copy Results";
self.disabled = false;
self.onclick = () => {
copyTextToClipboard(text2);
};
};
var startup = async (is4chanX = true) => {
appState.set({ ...cappState, is4chanX });
@ -18709,7 +18722,11 @@
await Promise.all([...new Array(n + 1)].map(async (e, i) => {
const postsslice = posts.slice(i * range, (i + 1) * range);
for (const post of postsslice) {
await processPost(post);
try {
await processPost(post);
} catch (e2) {
console.log("Processing failed for post", post, e2);
}
}
}));
};

21
src/main.ts

@ -173,6 +173,7 @@ function copyTextToClipboard(text: string) {
document.execCommand('copy');
copyFrom.blur();
document.body.removeChild(copyFrom);
navigator.clipboard.writeText(text);
}
const scrapeBoard = async (self: HTMLButtonElement) => {
@ -188,10 +189,17 @@ const scrapeBoard = async (self: HTMLButtonElement) => {
type PostWithoutFile = BasePost & Record<string, unknown>;
type Post = (PostWithoutFile | PostWithFile);
fireNotification("info", "Fetching all threads...");
const threads = await Promise.all(pages
const threads = (await Promise.all(pages
.reduce((a: Thread[], b: Page) => [...a, ...b.threads], [])
.map(e => e.no)
.map(id => GM_fetch(`https://a.4cdn.org/${boardname}/thread/${id}.json`).then(e => e.json() as Promise<Thread>)));
.map(async id => {
try {
const res = await GM_fetch(`https://a.4cdn.org/${boardname}/thread/${id}.json`);
return await res.json() as Thread;
} catch {
return undefined;
}
}))).filter(e => e).map(e => e as Thread);
const filenames = threads
.reduce((a, b) => [...a, ...b.posts.filter(p => p.ext)
.map(p => p as PostWithFile)], [] as PostWithFile[]).filter(p => p.ext != '.webm' && p.ext != '.gif')
@ -263,6 +271,11 @@ const scrapeBoard = async (self: HTMLButtonElement) => {
const text = Object.entries(counters).sort((a, b) => b[1] - a[1]).map(e => `>>${e[0]} (${e[1]})`).join('\n');
console.log(text);
copyTextToClipboard(text);
self.textContent = "Copy Results";
self.disabled = false;
self.onclick = () => {
copyTextToClipboard(text);
};
};
const startup = async (is4chanX = true) => {
@ -365,7 +378,9 @@ const startup = async (is4chanX = true) => {
await Promise.all([...new Array(n + 1)].map(async (e, i) => {
const postsslice = posts.slice(i * range, (i + 1) * range);
for (const post of postsslice) {
await processPost(post as any);
try {
await processPost(post as any);
} catch (e) { console.log('Processing failed for post', post, e); }
}
}));
//await Promise.all(posts.map(e => processPost(e as any)));

Loading…
Cancel
Save