From e0455a37f34d92772cdad703c07c352ca5cbfce0 Mon Sep 17 00:00:00 2001 From: coomdev Date: Sun, 9 Jan 2022 16:03:53 +0100 Subject: [PATCH] Fixed boorus not loading initially --- main.meta.js | 2 +- main.user.js | 11 +++++++---- src/main.ts | 7 +++---- src/stores.ts | 2 +- src/thirdeye.ts | 11 ++++++++--- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/main.meta.js b/main.meta.js index 2f7e082..f76a3e0 100644 --- a/main.meta.js +++ b/main.meta.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PNGExtraEmbed // @namespace https://coom.tech/ -// @version 0.103 +// @version 0.105 // @description uhh // @author You // @match https://boards.4channel.org/* diff --git a/main.user.js b/main.user.js index 375676d..74354d0 100644 --- a/main.user.js +++ b/main.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PNGExtraEmbed // @namespace https://coom.tech/ -// @version 0.103 +// @version 0.105 // @description uhh // @author You // @match https://boards.4channel.org/* @@ -11488,7 +11488,10 @@ quirks: gelquirk(e.view) })); }); - var boorus = []; + var boorus = localLoad("settingsv2", { rsources: [] }).rsources.map((e) => ({ + ...e, + quirks: gelquirk(e.view) + })); var black = /* @__PURE__ */ new Set(); var sources = /* @__PURE__ */ new Set(); settings.subscribe((s) => { @@ -16233,7 +16236,7 @@ appState.subscribe((v) => { cappState = v; }); - async function* streamRemote(url, chunkSize = 16 * 1024, fetchRestOnNonCanceled = true) { + async function* streamRemote(url, chunkSize = 72 * 1024, fetchRestOnNonCanceled = true) { const headers = await GM_head(url); const h = headerStringToObject(headers); const size = +h["content-length"]; @@ -16282,7 +16285,7 @@ cumul = import_buffer4.Buffer.concat([cumul, value]); found = await proc.has_embed(cumul); } while (found !== false && !chunk.done); - await iter.next(false); + await iter.next(true); if (found === false) { return; } diff --git a/src/main.ts b/src/main.ts index b78571a..43a5996 100644 --- a/src/main.ts +++ b/src/main.ts @@ -47,7 +47,7 @@ async function* streamRemote(url: string, chunkSize = 72 * 1024, fetchRestOnNonC let ptr = 0; let fetchSize = chunkSize; while (ptr != size) { - console.log('doing a fetch of ', url, ptr, ptr + fetchSize - 1); + //console.log('doing a fetch of ', url, ptr, ptr + fetchSize - 1); const res = await GM_fetch(url, { headers: { range: `bytes=${ptr}-${ptr + fetchSize - 1}` } }) as any as Tampermonkey.Response; const obj = headerStringToObject(res.responseHeaders); if (!('content-length' in obj)) { @@ -59,7 +59,7 @@ async function* streamRemote(url: string, chunkSize = 72 * 1024, fetchRestOnNonC fetchSize = size; const val = Buffer.from(await (res as any).arrayBuffer()); const e = (yield val) as boolean; - console.log('yeieledd, a', e); + //console.log('yeieledd, a', e); if (e) { break; } @@ -111,11 +111,10 @@ const processImage = async (src: string, fn: string, hex: string): Promise<([Emb if (!done) cumul = Buffer.concat([cumul, value!]); found = await proc.has_embed(cumul); - console.log(`on ${src} ${found}...`); } while (found !== false && !chunk.done); await iter.next(true); if (found === false) { - console.log(`Gave up on ${src} after downloading ${cumul.byteLength} bytes...`); + //console.log(`Gave up on ${src} after downloading ${cumul.byteLength} bytes...`); return; } return [await proc.extract(cumul), false] as [EmbeddedFile, boolean]; diff --git a/src/stores.ts b/src/stores.ts index f9c7437..fa447fd 100644 --- a/src/stores.ts +++ b/src/stores.ts @@ -1,7 +1,7 @@ import { writable } from "svelte/store"; import type { Booru } from "./thirdeye"; -const localLoad = (key: string, def: T) => +export const localLoad = (key: string, def: T) => ('__pee__' + key) in localStorage ? JSON.parse(localStorage.getItem('__pee__' + key)!) as T : def; diff --git a/src/thirdeye.ts b/src/thirdeye.ts index 9703fce..ea0e299 100644 --- a/src/thirdeye.ts +++ b/src/thirdeye.ts @@ -1,6 +1,6 @@ import type { EmbeddedFile, ImageProcessor } from "./main"; import { GM_fetch } from "./requests"; -import { settings } from "./stores"; +import { localLoad, settings } from "./stores"; export type Booru = { name: string; @@ -43,10 +43,15 @@ const gelquirk: (s: string) => tran = prefix => (a => settings.subscribe(s => { boorus = s.rsources.map(e => ({ ...e, - quirks: gelquirk(e.view) + quirks: gelquirk(e.view) })); }); -export let boorus: Booru[] = []; +export let boorus: Booru[] = + localLoad('settingsv2', { rsources: [] as (Omit & { view: string, disabled?: boolean })[] }) + .rsources.map(e => ({ + ...e, + quirks: gelquirk(e.view) + })); let black = new Set(); let sources = new Set();