|
|
@ -2,7 +2,7 @@ |
|
|
|
/// <reference lib="dom" />
|
|
|
|
|
|
|
|
import { Buffer } from "buffer"; |
|
|
|
import { appState, settings, initial_settings } from "./stores"; |
|
|
|
import { appState, settings, initial_settings, localLoad } from "./stores"; |
|
|
|
import { debounce } from './debounce'; |
|
|
|
import globalCss from './global.css'; |
|
|
|
|
|
|
@ -427,51 +427,58 @@ const convertToLocalEmbed = (wef: WorkerEmbeddedFile) => { |
|
|
|
return ret!; |
|
|
|
}; |
|
|
|
|
|
|
|
const processPost = async (post: HTMLDivElement) => { |
|
|
|
const origlink = qp.getImageLink(post); |
|
|
|
if (!origlink) |
|
|
|
return; |
|
|
|
const thumbLink = qp.getThumbnailLink(post); |
|
|
|
if (!thumbLink) |
|
|
|
const reportEmbed = (post: HTMLDivElement, op: number) => { |
|
|
|
if (!csettings) |
|
|
|
return; |
|
|
|
let res2: [WorkerEmbeddedFile[], boolean][] | undefined = undefined; |
|
|
|
|
|
|
|
let op: number; |
|
|
|
if (cappState.isCatalog) |
|
|
|
op = +post.id.slice(2); |
|
|
|
else |
|
|
|
op = +location.pathname.match(/\/thread\/(.*)/)![1]; |
|
|
|
const reportEmbed = () => { |
|
|
|
if (!csettings) |
|
|
|
return; |
|
|
|
if (csettings.tm) { |
|
|
|
// dont report results from archive, only live threads
|
|
|
|
if (['boards.4chan.org', 'boards.4channel.org'].includes(location.host)) { |
|
|
|
if (!cappState.isCatalog) { // only save from within threads
|
|
|
|
// we must be in a thread, thus the following is valid
|
|
|
|
pendingPosts.push({ id: +(post.id.match(/([0-9]+)/)![1]), op }); |
|
|
|
signalNewEmbeds(); // let it run async
|
|
|
|
} |
|
|
|
if (csettings.tm) { |
|
|
|
// dont report results from archive, only live threads
|
|
|
|
if (['boards.4chan.org', 'boards.4channel.org'].includes(location.host)) { |
|
|
|
if (!cappState.isCatalog) { // only save from within threads
|
|
|
|
// we must be in a thread, thus the following is valid
|
|
|
|
pendingPosts.push({ id: +(post.id.match(/([0-9]+)/)![1]), op }); |
|
|
|
signalNewEmbeds(); // let it run async
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const reportNoEmbed = () => { |
|
|
|
if (!csettings) |
|
|
|
return; |
|
|
|
if (csettings.tm) { |
|
|
|
// dont report results from archive, only live threads
|
|
|
|
if (['boards.4chan.org', 'boards.4channel.org'].includes(location.host)) { |
|
|
|
if (!cappState.isCatalog) { // only save from within threads
|
|
|
|
// we must be in a thread, thus the following is valid
|
|
|
|
pendingNoPosts.push({ id: +(post.id.match(/([0-9]+)/)![1]), op }); |
|
|
|
signalNewEmbeds(); // let it run async
|
|
|
|
} |
|
|
|
const reportNoEmbed = (post: HTMLDivElement, op: number) => { |
|
|
|
if (!csettings) |
|
|
|
return; |
|
|
|
if (csettings.tm) { |
|
|
|
// dont report results from archive, only live threads
|
|
|
|
if (['boards.4chan.org', 'boards.4channel.org'].includes(location.host)) { |
|
|
|
if (!cappState.isCatalog) { // only save from within threads
|
|
|
|
// we must be in a thread, thus the following is valid
|
|
|
|
pendingNoPosts.push({ id: +(post.id.match(/([0-9]+)/)![1]), op }); |
|
|
|
signalNewEmbeds(); // let it run async
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const processed = new Set<string>(); |
|
|
|
|
|
|
|
const processPost = async (post: HTMLDivElement) => { |
|
|
|
let inc = true; |
|
|
|
try { |
|
|
|
if (processed.has(post.id)) { |
|
|
|
inc = false; |
|
|
|
return; |
|
|
|
} |
|
|
|
const origlink = qp.getImageLink(post); |
|
|
|
if (!origlink) |
|
|
|
return; |
|
|
|
const thumbLink = qp.getThumbnailLink(post); |
|
|
|
if (!thumbLink) |
|
|
|
return; |
|
|
|
let res2: [WorkerEmbeddedFile[], boolean][] | undefined = undefined; |
|
|
|
|
|
|
|
let op: number; |
|
|
|
if (cappState.isCatalog) |
|
|
|
op = +post.id.slice(2); |
|
|
|
else |
|
|
|
op = +location.pathname.match(/\/thread\/(.*)/)![1]; |
|
|
|
if (shouldUseCache()) { |
|
|
|
res2 = await getEmbedsFromCache(qp.getCurrentBoard(), +qp.getCurrentThread()!, post.id); |
|
|
|
} |
|
|
@ -481,15 +488,19 @@ const processPost = async (post: HTMLDivElement) => { |
|
|
|
res2.push(...tmp); |
|
|
|
res2 = res2?.filter(e => e); |
|
|
|
} |
|
|
|
if (!res2 || res2.length == 0) |
|
|
|
return reportNoEmbed(post, op); |
|
|
|
reportEmbed(post, op); |
|
|
|
post.querySelector('.post')?.classList.add("embedfound"); |
|
|
|
processAttachments(post, res2?.flatMap(e => e![0].map(k => [convertToLocalEmbed(k), e![1]] as [EmbeddedFile, boolean]))); |
|
|
|
} catch (e) { |
|
|
|
console.error(e); |
|
|
|
return; |
|
|
|
} finally { |
|
|
|
processed.add(post.id); |
|
|
|
if (inc) |
|
|
|
appState.update(v => { return v.processed++, v; }); |
|
|
|
} |
|
|
|
if (!res2 || res2.length == 0) |
|
|
|
return reportNoEmbed(); |
|
|
|
reportEmbed(); |
|
|
|
post.querySelector('.post')?.classList.add("embedfound"); |
|
|
|
processAttachments(post, res2?.flatMap(e => e![0].map(k => [convertToLocalEmbed(k), e![1]] as [EmbeddedFile, boolean]))); |
|
|
|
}; |
|
|
|
|
|
|
|
const versionCheck = async () => { |
|
|
@ -670,12 +681,8 @@ const startup = async (is4chanX = true) => { |
|
|
|
else |
|
|
|
qp = lqp; |
|
|
|
|
|
|
|
await new Promise<void>(_ => { |
|
|
|
settings.subscribe(val => { |
|
|
|
if (val) |
|
|
|
_(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
const nset = await localLoad('settingsv2', initial_settings); |
|
|
|
settings.set(nset); |
|
|
|
|
|
|
|
if (!csettings) |
|
|
|
return false; |
|
|
@ -750,8 +757,15 @@ const startup = async (is4chanX = true) => { |
|
|
|
let el = qp.postsWithFiles(e); |
|
|
|
if (!el && e.classList.contains('postContainer')) |
|
|
|
el = [e]; |
|
|
|
if (el) |
|
|
|
if (el) { |
|
|
|
appState.update(v => { |
|
|
|
console.log("ADDED FROM MUTATION UPDATE", el.length); |
|
|
|
|
|
|
|
v.processing += el.length; |
|
|
|
return v; |
|
|
|
}); |
|
|
|
[...el].map(el => processPost(el as any)); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
@ -834,6 +848,13 @@ const startup = async (is4chanX = true) => { |
|
|
|
const n = 1; |
|
|
|
//console.log(posts);
|
|
|
|
const range = ~~(posts.length / n) + 1; |
|
|
|
appState.update(v => { |
|
|
|
console.log("ADDED FROM INIT", posts.length); |
|
|
|
v.processing += posts.length; |
|
|
|
console.log("NOW IS", v.processing); |
|
|
|
return v; |
|
|
|
}); |
|
|
|
|
|
|
|
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) { |
|
|
@ -901,7 +922,15 @@ document.addEventListener('ThreadUpdate', <any>(async (e: CustomEvent<any>) => { |
|
|
|
const newPosts = e.detail.newPosts; |
|
|
|
for (const post of newPosts) { |
|
|
|
const postContainer = document.getElementById("pc" + post.substring(post.indexOf(".") + 1)) as HTMLDivElement; |
|
|
|
processPost(postContainer); |
|
|
|
const fn = qp.getFilename(postContainer); |
|
|
|
if (fn) { |
|
|
|
appState.update(v => { |
|
|
|
v.processing++; |
|
|
|
return v; |
|
|
|
}); |
|
|
|
|
|
|
|
processPost(postContainer); |
|
|
|
} |
|
|
|
} |
|
|
|
})); |
|
|
|
|
|
|
|