Browse Source

Merge branch 'feat-black-posts' into 中出し

Anonymous 2 years ago
parent
commit
b9d62f5f58
  1. 2
      main.meta.js
  2. 136
      main.user.js
  3. 42
      src/Embedding.svelte
  4. 17
      src/EyeButton.svelte
  5. 30
      src/main.ts
  6. 2
      src/pomf.ts
  7. 4
      src/thirdeye.ts

2
main.meta.js

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

136
main.user.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed2
// @namespace https://coom.tech/
// @version 0.145
// @version 0.146
// @description uhh
// @author You
// @match https://boards.4channel.org/*
@ -11147,7 +11147,7 @@
const fnsize = data.readUInt32LE(0);
const fn = data.slice(4, 4 + fnsize).toString();
data = data.slice(4 + fnsize);
return [{ embed_type: 1 /* MEDIA_EMBED */, filename: fn, data }];
return [{ embed_type: 2 /* MEDIA_EMBED */, filename: fn, data }];
}
} catch (e) {
console.error(e);
@ -11274,7 +11274,7 @@
return;
const chk = chunks[embed2 + 1];
if (chk.type == "b" && chk.name == "TagBinary")
return [{ embed_type: 1 /* MEDIA_EMBED */, filename: "string", data: chk.data }];
return [{ embed_type: 2 /* MEDIA_EMBED */, filename: "string", data: chk.data }];
};
var inject = async (container, [inj]) => embed(import_buffer2.Buffer.from(await container.arrayBuffer()), import_buffer2.Buffer.from(await inj.arrayBuffer()));
var has_embed2 = (webm) => {
@ -11336,7 +11336,7 @@
ptr += sec.data.byteLength;
end = sec.end;
} while (sec.appname == "COOMTECH" && gif[end] == "!".charCodeAt(0));
return [{ embed_type: 1 /* MEDIA_EMBED */, data: ret, filename: "embedded" }];
return [{ embed_type: 2 /* MEDIA_EMBED */, data: ret, filename: "embedded" }];
}
end = sec.end;
}
@ -11588,7 +11588,7 @@
const prev = result[0].preview_url;
const full = result[0].full_url;
return [{
embed_type: 0 /* THIRD_EYE */,
embed_type: 0 /* EXTERNAL_BOORU */,
tags,
source: result[0].source,
page: { title: booru, url: result[0].page },
@ -11669,7 +11669,7 @@
}
}
return [{
embed_type: 1 /* MEDIA_EMBED */,
embed_type: 1 /* EXTERNAL_POMF */,
filename: ext,
data: csettings3.hotlink ? rsource : async (lsn) => {
try {
@ -15171,8 +15171,8 @@
if_block5.c();
attr(div0, "class", "place svelte-145c3cl");
toggle_class(div0, "contract", ctx[6]);
toggle_class(div0, "hasembed", ctx[0]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(div0, "hasext", ctx[0]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(div0, "hasembed", ctx[0]?.embed_type === 2 /* MEDIA_EMBED */);
toggle_class(div0, "hasext", ctx[0]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx[0]?.embed_type === 1 /* EXTERNAL_POMF */);
attr(div1, "class", "hoverer svelte-145c3cl");
attr(div1, "id", "ihover");
toggle_class(div1, "visible", ctx[7] && ctx[6]);
@ -15254,10 +15254,10 @@
toggle_class(div0, "contract", ctx2[6]);
}
if (dirty[0] & 1) {
toggle_class(div0, "hasembed", ctx2[0]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(div0, "hasembed", ctx2[0]?.embed_type === 2 /* MEDIA_EMBED */);
}
if (dirty[0] & 1) {
toggle_class(div0, "hasext", ctx2[0]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(div0, "hasext", ctx2[0]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx2[0]?.embed_type === 1 /* EXTERNAL_POMF */);
}
if (ctx2[16]) {
if (if_block3) {
@ -15622,26 +15622,24 @@
if (settled)
return;
settled = true;
const media = typeof file.thumbnail === "function" ? await file.thumbnail() : file.data;
if (media == null)
const thumb = typeof file.thumbnail === "function" ? await file.thumbnail() : file.data;
if (thumb == null)
return;
let type;
if (media instanceof ArrayBuffer || media instanceof Uint8Array) {
type = await fileTypeFromBuffer(media);
$$invalidate(5, url = URL.createObjectURL(new Blob([media], { type: type?.mime })));
} else if (typeof media === "string") {
let head = headerStringToObject(await GM_head(media, void 0));
if (thumb instanceof ArrayBuffer || thumb instanceof Uint8Array) {
type = await fileTypeFromBuffer(thumb);
$$invalidate(5, url = URL.createObjectURL(new Blob([thumb], { type: type?.mime })));
} else if (typeof thumb === "string") {
let head = headerStringToObject(await GM_head(thumb, void 0));
type = {
ext: "",
mime: head["content-type"].split(";")[0].trim()
};
}
if (!type)
return;
$$invalidate(8, ftype = type.mime);
$$invalidate(2, isVideo = type.mime.startsWith("video/"));
$$invalidate(4, isAudio = type.mime.startsWith("audio/"));
$$invalidate(3, isImage = type.mime.startsWith("image/"));
$$invalidate(8, ftype = type?.mime ?? "");
$$invalidate(2, isVideo = ftype.startsWith("video/") ?? false);
$$invalidate(4, isAudio = ftype.startsWith("audio/") ?? false);
$$invalidate(3, isImage = ftype.startsWith("image/") ?? false);
dispatch("fileinfo", { type });
if (isImage) {
$$invalidate(6, contracted = !$settings.xpi);
@ -15667,7 +15665,9 @@
rootMargin: "1000px",
threshold: 0.01
});
obs.observe(place);
setTimeout(() => {
obs.observe(place);
}, 1e3);
}
});
let unzipping = false;
@ -15675,8 +15675,6 @@
async function unzip() {
if (file?.isBlacklisted === true)
return;
if (!file.thumbnail)
return;
if (unzipping)
return;
let type;
@ -15687,8 +15685,8 @@
$$invalidate(17, progress = e.detail);
});
let full = await file.data(lisn);
const type2 = await fileTypeFromBuffer(full);
$$invalidate(14, furl = URL.createObjectURL(new Blob([full], { type: type2?.mime })));
type = await fileTypeFromBuffer(full);
$$invalidate(14, furl = URL.createObjectURL(new Blob([full], { type: type?.mime })));
} else if (typeof file.data === "string") {
$$invalidate(5, url = file.data);
$$invalidate(14, furl = file.data);
@ -15697,9 +15695,13 @@
ext: "",
mime: head["content-type"].split(";")[0].trim()
};
} else {
return;
}
if (!type)
if (!type) {
debugger;
return;
}
$$invalidate(2, isVideo = type.mime.startsWith("video/"));
$$invalidate(4, isAudio = type.mime.startsWith("audio/"));
$$invalidate(3, isImage = type.mime.startsWith("image/"));
@ -16192,8 +16194,8 @@
attr(a, "href", a_href_value = ctx[22].source);
attr(a, "target", "_blank");
attr(a, "class", "clickable svelte-1b3be75");
toggle_class(a, "hasembed", ctx[22]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(a, "hasext", ctx[22]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(a, "hasembed", ctx[22]?.embed_type === 2 /* MEDIA_EMBED */);
toggle_class(a, "hasext", ctx[22]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx[22]?.embed_type === 1 /* EXTERNAL_POMF */);
toggle_class(a, "hasblack", ctx[22]?.isBlacklisted === true);
},
m(target, anchor) {
@ -16205,10 +16207,10 @@
attr(a, "href", a_href_value);
}
if (dirty & 1) {
toggle_class(a, "hasembed", ctx2[22]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(a, "hasembed", ctx2[22]?.embed_type === 2 /* MEDIA_EMBED */);
}
if (dirty & 1) {
toggle_class(a, "hasext", ctx2[22]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(a, "hasext", ctx2[22]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx2[22]?.embed_type === 1 /* EXTERNAL_POMF */);
}
if (dirty & 1) {
toggle_class(a, "hasblack", ctx2[22]?.isBlacklisted === true);
@ -16232,8 +16234,8 @@
attr(a, "href", a_href_value = ctx[22].page.url);
attr(a, "target", "_blank");
attr(a, "class", "clickable svelte-1b3be75");
toggle_class(a, "hasembed", ctx[22]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(a, "hasext", ctx[22]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(a, "hasembed", ctx[22]?.embed_type === 2 /* MEDIA_EMBED */);
toggle_class(a, "hasext", ctx[22]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx[22]?.embed_type === 1 /* EXTERNAL_POMF */);
toggle_class(a, "hasblack", ctx[22]?.isBlacklisted === true);
},
m(target, anchor) {
@ -16247,10 +16249,10 @@
attr(a, "href", a_href_value);
}
if (dirty & 1) {
toggle_class(a, "hasembed", ctx2[22]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(a, "hasembed", ctx2[22]?.embed_type === 2 /* MEDIA_EMBED */);
}
if (dirty & 1) {
toggle_class(a, "hasext", ctx2[22]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(a, "hasext", ctx2[22]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx2[22]?.embed_type === 1 /* EXTERNAL_POMF */);
}
if (dirty & 1) {
toggle_class(a, "hasblack", ctx2[22]?.isBlacklisted === true);
@ -16283,8 +16285,8 @@
each_blocks[i].c();
}
attr(summary, "class", "svelte-1b3be75");
toggle_class(summary, "hasembed", ctx[22]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(summary, "hasext", ctx[22]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(summary, "hasembed", ctx[22]?.embed_type === 2 /* MEDIA_EMBED */);
toggle_class(summary, "hasext", ctx[22]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx[22]?.embed_type === 1 /* EXTERNAL_POMF */);
toggle_class(summary, "hasblack", ctx[22]?.isBlacklisted === true);
attr(ul, "class", "svelte-1b3be75");
attr(details, "class", "tags svelte-1b3be75");
@ -16300,10 +16302,10 @@
},
p(ctx2, dirty) {
if (dirty & 1) {
toggle_class(summary, "hasembed", ctx2[22]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(summary, "hasembed", ctx2[22]?.embed_type === 2 /* MEDIA_EMBED */);
}
if (dirty & 1) {
toggle_class(summary, "hasext", ctx2[22]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(summary, "hasext", ctx2[22]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx2[22]?.embed_type === 1 /* EXTERNAL_POMF */);
}
if (dirty & 1) {
toggle_class(summary, "hasblack", ctx2[22]?.isBlacklisted === true);
@ -16372,8 +16374,8 @@
a.textContent = "[PEE contract]";
attr(a, "alt", "By clicking this you agree to stay hydrated");
attr(a, "class", "clickable svelte-1b3be75");
toggle_class(a, "hasembed", ctx[22]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(a, "hasext", ctx[22]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(a, "hasembed", ctx[22]?.embed_type === 2 /* MEDIA_EMBED */);
toggle_class(a, "hasext", ctx[22]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx[22]?.embed_type === 1 /* EXTERNAL_POMF */);
toggle_class(a, "hasblack", ctx[22]?.isBlacklisted === true);
},
m(target, anchor) {
@ -16385,10 +16387,10 @@
},
p(ctx2, dirty) {
if (dirty & 1) {
toggle_class(a, "hasembed", ctx2[22]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(a, "hasembed", ctx2[22]?.embed_type === 2 /* MEDIA_EMBED */);
}
if (dirty & 1) {
toggle_class(a, "hasext", ctx2[22]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(a, "hasext", ctx2[22]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx2[22]?.embed_type === 1 /* EXTERNAL_POMF */);
}
if (dirty & 1) {
toggle_class(a, "hasblack", ctx2[22]?.isBlacklisted === true);
@ -16437,8 +16439,8 @@
if_block3_anchor = empty();
attr(span, "title", span_title_value = ctx[22].filename);
attr(span, "class", "fa fa-download clickable svelte-1b3be75");
toggle_class(span, "hasembed", ctx[22]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(span, "hasext", ctx[22]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(span, "hasembed", ctx[22]?.embed_type === 2 /* MEDIA_EMBED */);
toggle_class(span, "hasext", ctx[22]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx[22]?.embed_type === 1 /* EXTERNAL_POMF */);
toggle_class(span, "hasblack", ctx[22]?.isBlacklisted === true);
},
m(target, anchor) {
@ -16467,10 +16469,10 @@
attr(span, "title", span_title_value);
}
if (dirty & 1) {
toggle_class(span, "hasembed", ctx[22]?.embed_type === 1 /* MEDIA_EMBED */);
toggle_class(span, "hasembed", ctx[22]?.embed_type === 2 /* MEDIA_EMBED */);
}
if (dirty & 1) {
toggle_class(span, "hasext", ctx[22]?.embed_type === 0 /* THIRD_EYE */);
toggle_class(span, "hasext", ctx[22]?.embed_type === 0 /* EXTERNAL_BOORU */ || ctx[22]?.embed_type === 1 /* EXTERNAL_POMF */);
}
if (dirty & 1) {
toggle_class(span, "hasblack", ctx[22]?.isBlacklisted === true);
@ -16661,7 +16663,12 @@
const a = document.createElement("a");
document.body.appendChild(a);
a.style.display = "none";
const thumb = Buffer2.isBuffer(file.data) ? file.data : await file.data();
const thumb = typeof file.data === "function" ? await file.data() : file.data;
if (!(thumb instanceof Buffer2)) {
console.error("Couldn't download File");
debugger;
return;
}
const type = await fileTypeFromBuffer(thumb);
const url = URL.createObjectURL(new Blob([thumb], { type: type?.mime }));
a.href = url;
@ -16772,8 +16779,9 @@
}
}
var EMBED_TYPES = /* @__PURE__ */ ((EMBED_TYPES2) => {
EMBED_TYPES2[EMBED_TYPES2["THIRD_EYE"] = 0] = "THIRD_EYE";
EMBED_TYPES2[EMBED_TYPES2["MEDIA_EMBED"] = 1] = "MEDIA_EMBED";
EMBED_TYPES2[EMBED_TYPES2["EXTERNAL_BOORU"] = 0] = "EXTERNAL_BOORU";
EMBED_TYPES2[EMBED_TYPES2["EXTERNAL_POMF"] = 1] = "EXTERNAL_POMF";
EMBED_TYPES2[EMBED_TYPES2["MEDIA_EMBED"] = 2] = "MEDIA_EMBED";
return EMBED_TYPES2;
})(EMBED_TYPES || {});
var EMBED_STATUS = /* @__PURE__ */ ((EMBED_STATUS2) => {
@ -16788,13 +16796,21 @@
if (proc.skip) {
const md5 = import_buffer5.Buffer.from(hex, "base64");
const embed_status = await proc.has_embed(md5, fn);
if (embed_status === 0 /* SUCCESS */ || embed_status === 1 /* TE_BLACKLISTED */) {
const isBlacklisted = embed_status === 1 /* TE_BLACKLISTED */;
if (embed_status === 0 /* SUCCESS */ || isBlacklisted) {
const file2 = await proc.extract(md5, fn);
if (embed_status === 1 /* TE_BLACKLISTED */)
file2?.forEach((e) => {
let type;
file2?.forEach((e) => {
type = e.embed_type;
if (isBlacklisted)
e.isBlacklisted = true;
});
return [file2, 0 /* THIRD_EYE */];
});
if (type == null) {
debugger;
return;
}
;
return [file2, type];
}
return;
}
@ -16821,7 +16837,7 @@
return;
}
const file = await proc.extract(cumul);
return [file, 1 /* MEDIA_EMBED */];
return [file, 2 /* MEDIA_EMBED */];
}));
};
var textToElement = (s) => document.createRange().createContextualFragment(s).children[0];
@ -16980,9 +16996,9 @@
function processAttachments(post, ress) {
const replyBox = post.querySelector(".post");
const embed_status = ress[0][1];
if (embed_status === 0 /* THIRD_EYE */)
if (embed_status === 0 /* EXTERNAL_BOORU */ || embed_status === 1 /* EXTERNAL_POMF */)
replyBox?.classList.add("hasext");
else if (embed_status === 1 /* MEDIA_EMBED */)
else if (embed_status === 2 /* MEDIA_EMBED */)
replyBox?.classList.add("hasembed");
if (ress.length > 1)
replyBox?.classList.add("hasmultiple");

42
src/Embedding.svelte

@ -40,30 +40,30 @@
}
beforeUpdate(async () => {
if(file?.isBlacklisted === true) return
if (file?.isBlacklisted === true) return
if (settled) return
settled = true
// media is to be either thumbnail or data
// const thumb = file.thumbnail || file.data
const media = typeof file.thumbnail === 'function' ? (await file.thumbnail()) : file.data;
if(media == null) return
const thumb = typeof file.thumbnail === 'function' ? (await file.thumbnail()) : file.data;
if (thumb == null) return
let type: FileTypeResult | undefined
if (media instanceof ArrayBuffer || media instanceof Uint8Array) {
type = await fileTypeFromBuffer(media);
url = URL.createObjectURL(new Blob([media], { type: type?.mime }))
if (thumb instanceof ArrayBuffer || thumb instanceof Uint8Array) {
type = await fileTypeFromBuffer(thumb);
url = URL.createObjectURL(new Blob([thumb], { type: type?.mime }))
// if (!type) return; // extracted out below for TypeScript
} else if (typeof media === 'string'){
let head = headerStringToObject(await GM_head(media, undefined))
} else if (typeof thumb === 'string'){
let head = headerStringToObject(await GM_head(thumb, undefined))
// TODO write a proper getExt() and getMime()
type = { ext: '' as any, mime: head['content-type'].split(';')[0].trim() }
}
if (!type) return
ftype = type.mime;
isVideo = type.mime.startsWith('video/')
isAudio = type.mime.startsWith('audio/')
isImage = type.mime.startsWith('image/')
// if (!type) return
ftype = type?.mime ?? '';
isVideo = ftype.startsWith('video/') ?? false
isAudio = ftype.startsWith('audio/') ?? false
isImage = ftype.startsWith('image/') ?? false
dispatch('fileinfo', { type })
if (isImage) {
@ -88,7 +88,9 @@
},
{ root: null, rootMargin: '1000px', threshold: 0.01 },
)
obs.observe(place)
// TODO use subscription instead as place gets defined through render that
// is depended on certain variables.
setTimeout(()=>{obs.observe(place)}, 1000)
}
})
@ -97,7 +99,7 @@
async function unzip() {
if(file?.isBlacklisted === true) return
if (!file.thumbnail) return
// if (!file.thumbnail) return
if (unzipping) return
let type: FileTypeResult | undefined
@ -108,7 +110,7 @@
progress = e.detail
});
let full = await file.data(lisn);
const type = await fileTypeFromBuffer(full);
type = await fileTypeFromBuffer(full);
furl = URL.createObjectURL(new Blob([full], { type: type?.mime }));
} else if (typeof file.data === 'string') {
url = file.data
@ -116,9 +118,9 @@
let head = headerStringToObject(await GM_head(file.data, undefined))
// TODO write a proper getExt() and getMime()
type = { ext: '' as any, mime: head['content-type'].split(';')[0].trim() } as FileTypeResult
}
} else { return; }
// unzipping = false;
if (!type) return
if (!type) { debugger; return; }
isVideo = type.mime.startsWith('video/')
isAudio = type.mime.startsWith('audio/')
isImage = type.mime.startsWith('image/')
@ -247,6 +249,8 @@
lastev = lastev || ev
if ($settings.dh) return
if (!contracted) return
// const doc = document.documentElement
// const [sw, sh] = [doc.clientWidth, doc.clientHeight]
recompute(); // yeah I gave up
const [sw, sh] = [visualViewport.width, visualViewport.height]
// shamelessly stolen from 4chanX
@ -288,7 +292,7 @@
class:contract={contracted}
class="place"
class:hasembed={file?.embed_type === EMBED_TYPES.MEDIA_EMBED}
class:hasext={file?.embed_type === EMBED_TYPES.THIRD_EYE}
class:hasext={file?.embed_type === EMBED_TYPES.EXTERNAL_BOORU || file?.embed_type === EMBED_TYPES.EXTERNAL_POMF}
on:click={(e) => e.preventDefault()}
on:auxclick={(e) => e.preventDefault()}
on:mousedown={bepis}

17
src/EyeButton.svelte

@ -66,7 +66,12 @@ import { EmbeddedFile, EMBED_TYPES } from './main';
const a = document.createElement("a") as HTMLAnchorElement;
document.body.appendChild(a);
a.style.display = 'none';
const thumb = Buffer.isBuffer(file.data) ? file.data : await file.data();
const thumb = (typeof file.data === 'function') ? await file.data() : file.data ;
if(!(thumb instanceof Buffer)) {
console.error("Couldn't download File");
debugger;
return;
}
const type = await fileTypeFromBuffer(thumb);
const url = URL.createObjectURL(new Blob([thumb], { type: type?.mime }))
a.href = url;
@ -97,7 +102,7 @@ import { EmbeddedFile, EMBED_TYPES } from './main';
on:click={() => downloadFile(file)}
class="fa fa-download clickable"
class:hasembed={file?.embed_type === EMBED_TYPES.MEDIA_EMBED}
class:hasext={file?.embed_type === EMBED_TYPES.THIRD_EYE}
class:hasext={file?.embed_type === EMBED_TYPES.EXTERNAL_BOORU || file?.embed_type === EMBED_TYPES.EXTERNAL_POMF}
class:hasblack={file?.isBlacklisted === true}
/> <!-- hasblack is last for it to have greater weight than hasext, to override it -->
@ -108,7 +113,7 @@ import { EmbeddedFile, EMBED_TYPES } from './main';
target="_blank"
class="clickable"
class:hasembed={file?.embed_type === EMBED_TYPES.MEDIA_EMBED}
class:hasext={file?.embed_type === EMBED_TYPES.THIRD_EYE}
class:hasext={file?.embed_type === EMBED_TYPES.EXTERNAL_BOORU || file?.embed_type === EMBED_TYPES.EXTERNAL_POMF}
class:hasblack={file?.isBlacklisted === true}
>Source</a>
{/if}
@ -119,7 +124,7 @@ import { EmbeddedFile, EMBED_TYPES } from './main';
target="_blank"
class="clickable"
class:hasembed={file?.embed_type === EMBED_TYPES.MEDIA_EMBED}
class:hasext={file?.embed_type === EMBED_TYPES.THIRD_EYE}
class:hasext={file?.embed_type === EMBED_TYPES.EXTERNAL_BOORU || file?.embed_type === EMBED_TYPES.EXTERNAL_POMF}
class:hasblack={file?.isBlacklisted === true}
>{file.page.title}</a>
{/if}
@ -128,7 +133,7 @@ import { EmbeddedFile, EMBED_TYPES } from './main';
<details class="tags">
<summary
class:hasembed={file?.embed_type === EMBED_TYPES.MEDIA_EMBED}
class:hasext={file?.embed_type === EMBED_TYPES.THIRD_EYE}
class:hasext={file?.embed_type === EMBED_TYPES.EXTERNAL_BOORU || file?.embed_type === EMBED_TYPES.EXTERNAL_POMF}
class:hasblack={file?.isBlacklisted === true}
>Tags</summary>
<ul>
@ -144,7 +149,7 @@ import { EmbeddedFile, EMBED_TYPES } from './main';
alt="By clicking this you agree to stay hydrated"
class="clickable"
class:hasembed={file?.embed_type === EMBED_TYPES.MEDIA_EMBED}
class:hasext={file?.embed_type === EMBED_TYPES.THIRD_EYE}
class:hasext={file?.embed_type === EMBED_TYPES.EXTERNAL_BOORU || file?.embed_type === EMBED_TYPES.EXTERNAL_POMF}
class:hasblack={file?.isBlacklisted === true}
>[PEE contract]</a
>

30
src/main.ts

@ -69,7 +69,8 @@ async function* streamRemote(url: string, chunkSize = 72 * 1024, fetchRestOnNonC
}
export enum EMBED_TYPES {
THIRD_EYE,
EXTERNAL_BOORU,
EXTERNAL_POMF,
MEDIA_EMBED,
}
export enum EMBED_STATUS {
@ -105,22 +106,33 @@ export type EmbeddedFile = EmbeddedFileWithPreview | EmbeddedFileWithoutPreview;
const processImage = async (src: string, fn: string, hex: string): Promise<([EmbeddedFile[], EMBED_TYPES] | undefined)[]> => {
return Promise.all(processors.filter(e => e.match(fn)).map(async proc => {
if (proc.skip) { /* third-eye */
/* external: booru or pomf */
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');
const embed_status = await proc.has_embed(md5, fn)
if (embed_status === EMBED_STATUS.SUCCESS || embed_status === EMBED_STATUS.TE_BLACKLISTED){
const isBlacklisted = (embed_status === EMBED_STATUS.TE_BLACKLISTED);
if (embed_status === EMBED_STATUS.SUCCESS || isBlacklisted){
const file = await proc.extract(md5, fn);
if(embed_status === EMBED_STATUS.TE_BLACKLISTED)
file?.forEach(e=>{e!.isBlacklisted = true;})
return [file, EMBED_TYPES.THIRD_EYE] as [EmbeddedFile[], EMBED_TYPES];
let type;
file?.forEach(e=>{
type = e.embed_type
if(isBlacklisted)
e.isBlacklisted = true;
})
if(type == null) {debugger; return};
return [file, type] as [EmbeddedFile[], EMBED_TYPES];
}
// if (await proc.has_embed(md5, fn) === true)
// return [await proc.extract(md5, fn), true] as [EmbeddedFile[], boolean];
return;
}
const iter = streamRemote(src); /* media-embed */
/* media-embed */
const iter = streamRemote(src);
if (!iter)
return;
let cumul = Buffer.alloc(0);
@ -360,8 +372,8 @@ document.documentElement.insertBefore(customStyles, null);
function processAttachments(post: HTMLDivElement, ress: [EmbeddedFile, EMBED_TYPES][]) {
const replyBox = post.querySelector('.post');
const embed_status = ress[0][1];
if (embed_status === EMBED_TYPES.THIRD_EYE)
replyBox?.classList.add('hasext'); /* ext(ernal) = third-eye */
if (embed_status === EMBED_TYPES.EXTERNAL_BOORU || embed_status === EMBED_TYPES.EXTERNAL_POMF)
replyBox?.classList.add('hasext'); /* ext(ernal) */
else if (embed_status === EMBED_TYPES.MEDIA_EMBED)
replyBox?.classList.add('hasembed'); /* media-embed */
if (ress.length > 1)

2
src/pomf.ts

@ -45,7 +45,7 @@ const extract = async (b: Buffer, fn?: string) : Promise<EmbeddedFile[]> => {
}
return [{
embed_type: EMBED_TYPES.MEDIA_EMBED,
embed_type: EMBED_TYPES.EXTERNAL_POMF,
filename: ext,
data: csettings.hotlink ? rsource! : async (lsn) => {
try {

4
src/thirdeye.ts

@ -158,7 +158,7 @@ const extract = async (b: Buffer, fn?: string) : Promise<EmbeddedFile[]> => {
const prev = result[0].preview_url;
const full = result[0].full_url;
return [{
embed_type: EMBED_TYPES.THIRD_EYE,
embed_type: EMBED_TYPES.EXTERNAL_BOORU,
tags: tags,
source: result[0].source,
page: { title: booru, url: result[0].page },
@ -184,7 +184,7 @@ const extract = async (b: Buffer, fn?: string) : Promise<EmbeddedFile[]> => {
};
const has_embed = async (b: Buffer, fn?: string) : Promise<EMBED_STATUS> => {
// It's not worth to bother skipping images with filenames that match their md5 because
// It's not worth to bother skipping images with filenames that match their md5 because
// 4chan reencodes jpegs, which is well over half the files posted
// ok fine you autists

Loading…
Cancel
Save