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==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.103
// @version 0.105
// @description uhh
// @author You
// @match https://boards.4channel.org/*

11
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;
}

7
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<any>;
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];

2
src/stores.ts

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

11
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<Booru, 'quirks'> & { view: string, disabled?: boolean })[] })
.rsources.map(e => ({
...e,
quirks: gelquirk(e.view)
}));
let black = new Set<string>();
let sources = new Set<string>();

Loading…
Cancel
Save