2022-05-02 19:07:24 +00:00
|
|
|
import { ifetch } from "../platform";
|
2022-04-30 00:03:49 +00:00
|
|
|
|
2022-01-15 12:33:29 +00:00
|
|
|
export type QueryProcessor = {
|
2022-01-18 09:03:32 +00:00
|
|
|
getPost: (post: HTMLElement) => HTMLElement;
|
|
|
|
getFileThumbnail: (post: HTMLElement) => HTMLElement;
|
2022-01-16 13:34:14 +00:00
|
|
|
postsWithFiles: (host?: HTMLElement) => HTMLElement[];
|
|
|
|
settingsHost: () => HTMLSpanElement;
|
|
|
|
catalogControlHost: () => HTMLDivElement;
|
2022-04-30 00:03:49 +00:00
|
|
|
getImageLink:(post: HTMLElement) => AsyncGenerator<string, void, void>;
|
2022-01-26 20:45:15 +00:00
|
|
|
getThumbnailLink: (post: HTMLElement) => string;
|
2022-01-16 13:34:14 +00:00
|
|
|
getFilename: (post: HTMLElement) => string;
|
|
|
|
getMD5: (post: HTMLElement) => string;
|
|
|
|
getInfoBox: (post: HTMLElement) => HTMLElement;
|
2022-04-17 18:45:40 +00:00
|
|
|
getPostIdPrefix: () => string;
|
|
|
|
getTextBox: (post: HTMLElement) => HTMLElement;
|
2022-01-15 12:33:29 +00:00
|
|
|
};
|
2022-01-16 13:34:14 +00:00
|
|
|
|
|
|
|
export const V4chan: QueryProcessor = {
|
2022-01-18 09:33:06 +00:00
|
|
|
getFileThumbnail: post => post.querySelector('div.file')!,
|
2022-01-18 09:03:32 +00:00
|
|
|
getPost: (post) => post.querySelector('.post')!,
|
2022-01-16 13:34:14 +00:00
|
|
|
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,
|
2022-04-30 00:03:49 +00:00
|
|
|
getImageLink: async function *(post: HTMLElement) {
|
|
|
|
yield post.querySelector('a[target="_blank"]')?.getAttribute('href') || '';
|
|
|
|
},
|
|
|
|
|
|
|
|
//(post: HTMLElement) => post.querySelector('a[target="_blank"]')?.getAttribute('href') || '',
|
2022-01-16 13:34:14 +00:00
|
|
|
getFilename: (post: HTMLElement) => {
|
|
|
|
const a = post.querySelector('a[target="_blank"]') as (HTMLAnchorElement | null);
|
|
|
|
if (a && a.title)
|
|
|
|
return a.title;
|
|
|
|
return a?.textContent || '';
|
|
|
|
},
|
|
|
|
getMD5: (post: HTMLElement) => post.querySelector("img[data-md5]")?.getAttribute("data-md5") || '',
|
2022-01-26 20:45:15 +00:00
|
|
|
getThumbnailLink: (post: HTMLElement) => post.querySelector("img[data-md5]")?.getAttribute("src") || '',
|
2022-04-17 18:45:40 +00:00
|
|
|
getInfoBox: post => post.querySelector("div.fileText")!,
|
|
|
|
getPostIdPrefix: () => 'p',
|
|
|
|
getTextBox: (post) => post.querySelector('blockquote')!
|
2022-01-16 13:34:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const X4chan: QueryProcessor = {
|
2022-01-18 09:33:06 +00:00
|
|
|
getFileThumbnail: post => post.querySelector('div.file')!,
|
2022-01-18 09:03:32 +00:00
|
|
|
getPost: (post) => post.querySelector('.post')!,
|
2022-01-16 13:34:14 +00:00
|
|
|
postsWithFiles: (h) => [...(h || document).querySelectorAll('.postContainer:not([class*="noFile"])')] as HTMLElement[],
|
|
|
|
settingsHost: () => document.getElementById("shortcuts") as any,
|
|
|
|
catalogControlHost: () => document.getElementById("index-options") as HTMLDivElement,
|
2022-04-30 00:03:49 +00:00
|
|
|
getImageLink: async function *(post: HTMLElement) {
|
|
|
|
yield post.querySelector('a[target="_blank"]')?.getAttribute('href') || '';
|
|
|
|
},
|
2022-01-16 13:34:14 +00:00
|
|
|
getFilename: (post: HTMLElement) => {
|
|
|
|
const a = post.querySelector('a[target="_blank"]') as (HTMLAnchorElement | null);
|
2022-01-16 20:01:37 +00:00
|
|
|
const origlink = post.querySelector('.file-info > a[target*="_blank"]') as HTMLAnchorElement;
|
|
|
|
return (origlink.querySelector('.fnfull') || origlink)?.textContent || '';
|
2022-01-16 13:34:14 +00:00
|
|
|
},
|
|
|
|
getMD5: (post: HTMLElement) => post.querySelector("img[data-md5]")?.getAttribute("data-md5") || '',
|
2022-01-26 20:45:15 +00:00
|
|
|
getThumbnailLink: (post: HTMLElement) => post.querySelector("img[data-md5]")?.getAttribute("src") || '',
|
2022-04-17 18:45:40 +00:00
|
|
|
getInfoBox: post => post.querySelector("span.file-info")!,
|
|
|
|
getPostIdPrefix: V4chan.getPostIdPrefix,
|
|
|
|
getTextBox: V4chan.getTextBox
|
2022-01-16 13:34:14 +00:00
|
|
|
};
|
|
|
|
|
2022-01-18 12:19:33 +00:00
|
|
|
export const FoolFuuka: QueryProcessor = {
|
2022-01-18 09:33:06 +00:00
|
|
|
getFileThumbnail: post => post.classList.contains('post_is_op') ? post.querySelector('.thread_image_link')! : post.querySelector('.thread_image_box')!,
|
2022-01-18 09:20:42 +00:00
|
|
|
getPost: (post) => post.querySelector('.post_wrapper')!,
|
2022-01-18 09:03:32 +00:00
|
|
|
postsWithFiles: (h) => [...(h || document).querySelectorAll('article[class*="has_image"]')] as HTMLElement[],
|
|
|
|
settingsHost: () => document.querySelector(".letters") as any,
|
|
|
|
catalogControlHost: () => document.getElementById("index-options") as HTMLDivElement,
|
2022-04-30 00:03:49 +00:00
|
|
|
getImageLink: async function *(post: HTMLElement) {
|
2022-05-04 03:21:53 +00:00
|
|
|
if (location.host == "arch.b4k.co") { //get hecked
|
2022-04-30 00:03:49 +00:00
|
|
|
const pid = post.id.match(/\d+/)![0];
|
|
|
|
const board = location.pathname.match(/\/(..?.?)\//)![1];
|
2022-05-02 19:07:24 +00:00
|
|
|
const res = await ifetch(`https://archive.wakarimasen.moe/_/api/chan/post/?board=${board}&num=${pid}`);
|
2022-04-30 00:03:49 +00:00
|
|
|
const data = await res.json();
|
|
|
|
yield data.media.media_link;
|
|
|
|
}
|
2022-05-08 11:23:46 +00:00
|
|
|
yield post.querySelector('a[rel]')?.getAttribute('href') || '';
|
2022-04-30 00:03:49 +00:00
|
|
|
},
|
2022-01-18 09:03:32 +00:00
|
|
|
getFilename: (post: HTMLElement) => {
|
2022-01-18 09:33:06 +00:00
|
|
|
const opfn = post.querySelector('a.post_file_filename')?.textContent;
|
|
|
|
if (opfn)
|
|
|
|
return opfn;
|
2022-01-18 09:03:32 +00:00
|
|
|
const a = post.querySelector('a[rel]') as (HTMLAnchorElement | null);
|
|
|
|
return a?.title || '';
|
|
|
|
},
|
|
|
|
getMD5: (post: HTMLElement) => post.querySelector("img[data-md5]")?.getAttribute("data-md5") || '',
|
2022-01-29 20:04:50 +00:00
|
|
|
getThumbnailLink: (post: HTMLElement) => {
|
|
|
|
const e = post.querySelector("img[data-md5]");
|
|
|
|
return e?.getAttribute("src") || e?.getAttribute("data-src") || '';
|
|
|
|
},
|
2022-04-17 18:45:40 +00:00
|
|
|
getInfoBox: post => post.querySelector("span.post_controls")!,
|
|
|
|
getPostIdPrefix: () => '',
|
|
|
|
getTextBox: post => post.querySelector('.text')!
|
|
|
|
|
2022-01-18 09:03:32 +00:00
|
|
|
};
|
|
|
|
|
2022-01-16 13:34:14 +00:00
|
|
|
export const getQueryProcessor = (is4chanX: boolean) => {
|
|
|
|
if (['boards.4chan.org', 'boards.4channel.org'].includes(location.host))
|
|
|
|
return is4chanX ? X4chan : V4chan;
|
2022-01-18 12:19:33 +00:00
|
|
|
if (document.querySelector('meta[name="generator"]')?.getAttribute("content")?.startsWith("FoolFuuka"))
|
|
|
|
return FoolFuuka;
|
|
|
|
};
|