Browse Source

Kohlchan fixes and cleanup

Fixes PEE not working on the nocsp subdomain of KC.
pull/53/head
Araragi 1 year ago
parent
commit
ea085808b7
  1. 3
      build-chrome.js
  2. 62
      src/main.ts
  3. 23
      src/platform.ts
  4. 33
      src/websites/index.ts

3
build-chrome.js

@ -33,7 +33,8 @@ const domains = [
"https://fireden.net/*",
"https://thebarchive.com/*",
"https://archiveofsins.com/*",
"https://kohlchan.net/*"
"https://kohlchan.net/*",
"https://*.kohlchan.net/*"
];
const manif3 = {

62
src/main.ts

@ -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";

23
src/platform.ts

@ -112,29 +112,6 @@ const Bridged = (ctor: any) => {
ctor[k] = bridge(k, ctor[k]);
};
const altdomains = [
"desuarchive.org",
"archived.moe",
"archive.nyafuu.org",
"arch.b4k.co",
"archive.4plebs.org",
"archive.wakarimasen.moe",
"b4k.co",
"fireden.net",
"thebarchive.com",
"archiveofsins.com",
"kohlchan.net",
"nocsp.kohlchan.net",
];
export function supportedAltDomain(s: string) {
return altdomains.includes(s);
}
export function supportedMainDomain(s: string) {
return ['boards.4channel.org', 'boards.4chan.org'].includes(s);
}
let popupport: browser.runtime.Port;
const pendingcmds: Record<number, (v?: any) => void> = {};

33
src/websites/index.ts

@ -23,7 +23,7 @@ export const V4chan: QueryProcessor = {
postsWithFiles: (h) => [...(h || document).querySelectorAll('.file')].map(e => e.closest('.postContainer')) as any,
settingsHost: () => document.getElementById("navtopright") as any,
catalogControlHost: () => document.getElementById("settings") as HTMLDivElement,
getImageLink: async function* (post: HTMLElement) {
getImageLink: async function*(post: HTMLElement) {
yield post.querySelector('a[target="_blank"]')?.getAttribute('href') || '';
},
@ -49,7 +49,7 @@ export const X4chan: QueryProcessor = {
postsWithFiles: (h) => [...(h || document).querySelectorAll('.postContainer:not([class*="noFile"])')] as HTMLElement[],
settingsHost: () => document.getElementById("shortcuts") as any,
catalogControlHost: () => document.getElementById("index-options") as HTMLDivElement,
getImageLink: async function* (post: HTMLElement) {
getImageLink: async function*(post: HTMLElement) {
yield post.querySelector('a[target="_blank"]')?.getAttribute('href') || '';
},
getFilename: (post: HTMLElement) => {
@ -72,7 +72,7 @@ export const FoolFuuka: QueryProcessor = {
postsWithFiles: (h) => [...(h || document).querySelectorAll('article[class*="thread"], article[class*="has_image"]')] as HTMLElement[],
settingsHost: () => document.querySelector(".letters") as any,
catalogControlHost: () => document.getElementById("index-options") as HTMLDivElement,
getImageLink: async function* (post: HTMLElement) {
getImageLink: async function*(post: HTMLElement) {
if (location.host == "arch.b4k.co") { //get hecked
return;
}
@ -103,7 +103,7 @@ export const KChan: QueryProcessor = {
postsWithFiles: (h) => ([...(h || document).querySelectorAll('.postCell')] as HTMLElement[]).filter(p => p.querySelector('figure')),
settingsHost: () => document.getElementById("navOptionsSpanThread") as any,
catalogControlHost: () => document.getElementById("divTools") as HTMLDivElement,
getImageLink: async function* (post: HTMLElement) {
getImageLink: async function*(post: HTMLElement) {
yield (post.querySelector('a.imgLink[target="_blank"]') as HTMLAnchorElement)?.href || '';
},
@ -126,9 +126,32 @@ export const KChan: QueryProcessor = {
export const getQueryProcessor = (is4chanX: boolean) => {
if (['boards.4chan.org', 'boards.4channel.org'].includes(location.host))
return is4chanX ? X4chan : V4chan;
if (location.host.includes("kohlchan.net")) {
if (['kohlchan.net', 'nocsp.kohlchan.net'].includes(location.host)) {
return KChan;
}
if (document.querySelector('meta[name="generator"]')?.getAttribute("content")?.startsWith("FoolFuuka"))
return FoolFuuka;
};
const altdomains = [
"desuarchive.org",
"archived.moe",
"archive.nyafuu.org",
"arch.b4k.co",
"archive.4plebs.org",
"archive.wakarimasen.moe",
"b4k.co",
"fireden.net",
"thebarchive.com",
"archiveofsins.com",
"kohlchan.net",
"nocsp.kohlchan.net",
];
export function supportedAltDomain(s: string) {
return altdomains.includes(s);
}
export function supportedMainDomain(s: string) {
return ['boards.4channel.org', 'boards.4chan.org'].includes(s);
}

Loading…
Cancel
Save