|
|
@ -1,4 +1,4 @@ |
|
|
|
/// <reference lib="ES2021" />
|
|
|
|
/// <reference lib="ES2022" />
|
|
|
|
/// <reference lib="dom" />
|
|
|
|
|
|
|
|
import { Buffer } from "buffer"; |
|
|
@ -22,8 +22,8 @@ import EyeButton from './Components/EyeButton.svelte'; |
|
|
|
import NotificationsHandler from './Components/NotificationsHandler.svelte'; |
|
|
|
|
|
|
|
import { fireNotification, getEmbedsFromCache, getSelectedFile } from "./utils"; |
|
|
|
import { getQueryProcessor, QueryProcessor } from "./websites"; |
|
|
|
import { ifetch, Platform, sendCmd, lqueue, supportedAltDomain, supportedMainDomain, genPort, initMainIPC } from "./platform"; |
|
|
|
import { getQueryProcessor, QueryProcessor, supportedAltDomain, supportedMainDomain } from "./websites"; |
|
|
|
import { ifetch, Platform, sendCmd, lqueue, genPort, initMainIPC } from "./platform"; |
|
|
|
import TextEmbeddingsSvelte from "./Components/TextEmbeddings.svelte"; |
|
|
|
import { HydrusClient } from "./hydrus"; |
|
|
|
import { registerPlugin, createTokenClass } from 'linkifyjs'; |
|
|
@ -93,60 +93,6 @@ type EmbeddedFileWithoutPreview = { |
|
|
|
|
|
|
|
export type EmbeddedFile = EmbeddedFileWithPreview | EmbeddedFileWithoutPreview; |
|
|
|
|
|
|
|
/* |
|
|
|
const processImage = async (srcs: AsyncGenerator<string, void, void>, fn: string, hex: string, prevurl: string) => { |
|
|
|
const ret = await Promise.all(processors.filter(e => e.match(fn)).map(async proc => { |
|
|
|
if (proc.skip) { |
|
|
|
// skip file downloading, file is referenced from the filename
|
|
|
|
// basically does things like filtering out blacklisted tags
|
|
|
|
const md5 = Buffer.from(hex, 'base64'); |
|
|
|
if (await proc.has_embed(md5, fn, prevurl) === true) { |
|
|
|
return [await proc.extract(md5, fn), true] as [EmbeddedFile[], boolean]; |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
let succ = false; |
|
|
|
let cumul: Buffer; |
|
|
|
do { |
|
|
|
try { |
|
|
|
const n = await srcs.next(); |
|
|
|
if (n.done) |
|
|
|
return; // no more links to try
|
|
|
|
const iter = streamRemote(n.value); |
|
|
|
if (!iter) |
|
|
|
return; |
|
|
|
cumul = Buffer.alloc(0); |
|
|
|
let found: boolean | undefined; |
|
|
|
let chunk: ReadableStreamDefaultReadResult<Buffer> = { done: true }; |
|
|
|
do { |
|
|
|
const { value, done } = await iter.next(typeof found === "boolean"); |
|
|
|
if (done) { |
|
|
|
chunk = { done: true } as ReadableStreamDefaultReadDoneResult; |
|
|
|
} else { |
|
|
|
chunk = { done: false, value } as ReadableStreamDefaultReadValueResult<Buffer>; |
|
|
|
cumul = Buffer.concat([cumul, value!]); |
|
|
|
const v = await proc.has_embed(cumul); |
|
|
|
if (typeof v == "string") { |
|
|
|
return [await proc.extract(cumul, v), false] as [EmbeddedFile[], boolean]; |
|
|
|
} |
|
|
|
found = v; |
|
|
|
} |
|
|
|
} while (found !== false && !chunk.done); |
|
|
|
succ = true; |
|
|
|
await iter.next(true); |
|
|
|
if (found !== true) { |
|
|
|
//console.log(`Gave up on ${src} after downloading ${cumul.byteLength} bytes...`);
|
|
|
|
return; |
|
|
|
} |
|
|
|
return [await proc.extract(cumul), false] as [EmbeddedFile[], boolean]; |
|
|
|
} catch { |
|
|
|
// ignore error and retry with another link
|
|
|
|
} |
|
|
|
} while (!succ); |
|
|
|
})); |
|
|
|
return ret.filter(e => e).map(e => e!); |
|
|
|
};*/ |
|
|
|
|
|
|
|
const textToElement = <T = HTMLElement>(s: string) => |
|
|
|
document.createRange().createContextualFragment(s).children[0] as any as T; |
|
|
|
|
|
|
@ -822,7 +768,7 @@ const startup = async (is4chanX = true) => { |
|
|
|
} |
|
|
|
}; |
|
|
|
const obs = new MutationObserver(somethingChanged); |
|
|
|
if (location.host.includes("kohlchan.net")) { |
|
|
|
if (['kohlchan.net', 'nocsp.kohlchan.net'].includes(location.host)) { |
|
|
|
// vanilla kohl, behaves a bit like a mix of the two
|
|
|
|
target = e.detail as HTMLDivElement; |
|
|
|
a.style.display = "inline-block"; |
|
|
|