Browse Source

Fixed boorus not loading initially

pull/46/head 0.106
coomdev 2 years ago
parent
commit
e0455a37f3
  1. 2
      main.meta.js
  2. 11
      main.user.js
  3. 7
      src/main.ts
  4. 2
      src/stores.ts
  5. 11
      src/thirdeye.ts

2
main.meta.js

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

11
main.user.js

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name PNGExtraEmbed // @name PNGExtraEmbed
// @namespace https://coom.tech/ // @namespace https://coom.tech/
// @version 0.103 // @version 0.105
// @description uhh // @description uhh
// @author You // @author You
// @match https://boards.4channel.org/* // @match https://boards.4channel.org/*
@ -11488,7 +11488,10 @@
quirks: gelquirk(e.view) 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 black = /* @__PURE__ */ new Set();
var sources = /* @__PURE__ */ new Set(); var sources = /* @__PURE__ */ new Set();
settings.subscribe((s) => { settings.subscribe((s) => {
@ -16233,7 +16236,7 @@
appState.subscribe((v) => { appState.subscribe((v) => {
cappState = 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 headers = await GM_head(url);
const h = headerStringToObject(headers); const h = headerStringToObject(headers);
const size = +h["content-length"]; const size = +h["content-length"];
@ -16282,7 +16285,7 @@
cumul = import_buffer4.Buffer.concat([cumul, value]); cumul = import_buffer4.Buffer.concat([cumul, value]);
found = await proc.has_embed(cumul); found = await proc.has_embed(cumul);
} while (found !== false && !chunk.done); } while (found !== false && !chunk.done);
await iter.next(false); await iter.next(true);
if (found === false) { if (found === false) {
return; return;
} }

7
src/main.ts

@ -47,7 +47,7 @@ async function* streamRemote(url: string, chunkSize = 72 * 1024, fetchRestOnNonC
let ptr = 0; let ptr = 0;
let fetchSize = chunkSize; let fetchSize = chunkSize;
while (ptr != size) { 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<any>; const res = await GM_fetch(url, { headers: { range: `bytes=${ptr}-${ptr + fetchSize - 1}` } }) as any as Tampermonkey.Response<any>;
const obj = headerStringToObject(res.responseHeaders); const obj = headerStringToObject(res.responseHeaders);
if (!('content-length' in obj)) { if (!('content-length' in obj)) {
@ -59,7 +59,7 @@ async function* streamRemote(url: string, chunkSize = 72 * 1024, fetchRestOnNonC
fetchSize = size; fetchSize = size;
const val = Buffer.from(await (res as any).arrayBuffer()); const val = Buffer.from(await (res as any).arrayBuffer());
const e = (yield val) as boolean; const e = (yield val) as boolean;
console.log('yeieledd, a', e); //console.log('yeieledd, a', e);
if (e) { if (e) {
break; break;
} }
@ -111,11 +111,10 @@ const processImage = async (src: string, fn: string, hex: string): Promise<([Emb
if (!done) if (!done)
cumul = Buffer.concat([cumul, value!]); cumul = Buffer.concat([cumul, value!]);
found = await proc.has_embed(cumul); found = await proc.has_embed(cumul);
console.log(`on ${src} ${found}...`);
} while (found !== false && !chunk.done); } while (found !== false && !chunk.done);
await iter.next(true); await iter.next(true);
if (found === false) { 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;
} }
return [await proc.extract(cumul), false] as [EmbeddedFile, boolean]; return [await proc.extract(cumul), false] as [EmbeddedFile, boolean];

2
src/stores.ts

@ -1,7 +1,7 @@
import { writable } from "svelte/store"; import { writable } from "svelte/store";
import type { Booru } from "./thirdeye"; import type { Booru } from "./thirdeye";
const localLoad = <T>(key: string, def: T) => export const localLoad = <T>(key: string, def: T) =>
('__pee__' + key) in localStorage ('__pee__' + key) in localStorage
? JSON.parse(localStorage.getItem('__pee__' + key)!) as T ? JSON.parse(localStorage.getItem('__pee__' + key)!) as T
: def; : def;

11
src/thirdeye.ts

@ -1,6 +1,6 @@
import type { EmbeddedFile, ImageProcessor } from "./main"; import type { EmbeddedFile, ImageProcessor } from "./main";
import { GM_fetch } from "./requests"; import { GM_fetch } from "./requests";
import { settings } from "./stores"; import { localLoad, settings } from "./stores";
export type Booru = { export type Booru = {
name: string; name: string;
@ -43,10 +43,15 @@ const gelquirk: (s: string) => tran = prefix => (a =>
settings.subscribe(s => { settings.subscribe(s => {
boorus = s.rsources.map(e => ({ boorus = s.rsources.map(e => ({
...e, ...e,
quirks: gelquirk(e.view) quirks: gelquirk(e.view)
})); }));
}); });
export let boorus: Booru[] = []; export let boorus: Booru[] =
localLoad('settingsv2', { rsources: [] as (Omit<Booru, 'quirks'> & { view: string, disabled?: boolean })[] })
.rsources.map(e => ({
...e,
quirks: gelquirk(e.view)
}));
let black = new Set<string>(); let black = new Set<string>();
let sources = new Set<string>(); let sources = new Set<string>();

Loading…
Cancel
Save