Merge branch 'feature/reddit-chapter-fetch'
@@ -5,8 +5,10 @@
5
5
*
6
6
* De catalogus (titels, auteurs, hoofdstuklijsten) komt uit een statische
7
7
* JSON-index. De verhaaltekst zelf staat niet in die index: parseChapter
8
* haalt een hoofdstuk live op via de Arctic Shift-API (optioneel te
9
* overschrijven in de plugin-instellingen).
8
* probeert eerst de echte Reddit-JSON (www.reddit.com/.../.json, daarna
9
* old.reddit.com) via fetchApi, zodat cookies uit de LNReader-WebView
10
* meegaan na inloggen op reddit.com. Bij een fout, 403 of login-/blokpagina
11
* valt de plugin terug op Arctic Shift.
10
12
*
11
13
* Dit bestand is CommonJS, zoals de officiële gecompileerde plugins:
12
14
* require(...) uit de LNReader-allowlist, en `exports.default = instance`.
@@ -94,9 +96,12 @@ class HFYNovelsPlugin {
94
96
constructor() {
95
97
this.id = "hfyNovels";
96
98
this.name = "HFY Novels";
97
this.version = "0.1.0";
99
this.version = "0.2.0";
98
100
this.site = "https://www.reddit.com/r/HFY/";
99
101
this.icon = "icon.png";
102
// Geen webStorageUtilized: Reddit-login zit in cookies. LNReader's
103
// fetchApi (native fetch) stuurt de WebView-cookies automatisch mee
104
// voor hetzelfde domein; localStorage is daarvoor niet nodig.
100
105
this.filters = {
101
106
kind: {
102
107
value: "all",
@@ -129,9 +134,19 @@ class HFYNovelsPlugin {
129
134
label: "Git-revisie van de index (rev=)",
130
135
type: "Text",
131
136
},
137
chapterSource: {
138
value: "auto",
139
label: "Bron voor hoofdstuktekst",
140
type: "Select",
141
options: [
142
{ label: "Automatisch (Reddit, anders Arctic Shift)", value: "auto" },
143
{ label: "Alleen Reddit", value: "reddit" },
144
{ label: "Alleen Arctic Shift", value: "arctic" },
145
],
146
},
132
147
chapterSourceUrl: {
133
148
value: DEFAULT_CHAPTER_SOURCE,
134
label: "Bron voor hoofdstuktekst (Arctic Shift)",
149
label: "Arctic Shift-basis-URL (fallback)",
135
150
type: "Text",
136
151
},
137
152
};
@@ -166,6 +181,32 @@ class HFYNovelsPlugin {
166
181
return String(setting("chapterSourceUrl", DEFAULT_CHAPTER_SOURCE)).replace(/\/+$/, "");
167
182
}
168
183
184
chapterMode() {
185
const mode = String(setting("chapterSource", "auto") || "auto").toLowerCase();
186
if (mode === "reddit" || mode === "arctic") {
187
return mode;
188
}
189
return "auto";
190
}
191
192
/**
193
* Maakt "Open in WebView" op een reeks of hoofdstuk tot een Reddit-URL,
194
* zodat je daar kunt inloggen. Zonder deze functie zou LNReader
195
* site+path plakken (bijv. /r/HFY/series/id), wat geen geldige Reddit-pagina is.
196
* Het reeks-id is de oudste post (eerste deel).
197
*/
198
resolveUrl(path, isNovel) {
199
const raw = String(path || "").trim();
200
if (/^https?:\/\//i.test(raw)) {
201
return raw;
202
}
203
const id = chapterIdFromPath(raw) || chapterIdFromPath(raw.replace(/^series\//, "chapter/"));
204
if (id) {
205
return "https://www.reddit.com/r/HFY/comments/" + id + "/";
206
}
207
return this.site;
208
}
209
169
210
matchesFilters(entry, filters) {
170
211
const kind = filters && filters.kind ? filters.kind.value : "all";
171
212
const nsfw = filters && filters.nsfw ? filters.nsfw.value : "hide";
@@ -266,37 +307,206 @@ class HFYNovelsPlugin {
266
307
};
267
308
}
268
309
310
269
311
async parseChapter(chapterPath) {
270
const id = String(chapterPath || "")
271
.replace(/^chapter\//, "")
272
.trim()
273
.toLowerCase();
274
if (!/^[0-9a-z]{4,10}$/.test(id)) {
312
const id = chapterIdFromPath(chapterPath);
313
if (!id) {
275
314
throw new Error("HFY Novels: ongeldig hoofdstuk-id");
276
315
}
277
const url =
278
this.chapterSource() +
279
"/api/posts/ids?ids=" +
280
encodeURIComponent(id) +
281
"&md2html=true";
316
const mode = this.chapterMode();
317
let redditError = "";
318
if (mode !== "arctic") {
319
const reddit = await tryRedditChapter(id);
320
if (reddit.ok) {
321
return renderChapter(reddit.post, "Reddit");
322
}
323
redditError = reddit.reason || "onbekende fout";
324
if (mode === "reddit") {
325
throw new Error(
326
"HFY Novels: Reddit gaf geen hoofdstuk (" +
327
redditError +
328
"). Log in via Open in WebView op reddit.com en probeer het opnieuw.",
329
);
330
}
331
}
332
const arctic = await tryArcticChapter(this.chapterSource(), id);
333
if (arctic.ok) {
334
const suffix = mode === "arctic" ? "Arctic Shift" : "Arctic Shift (fallback)";
335
return renderChapter(arctic.post, suffix);
336
}
337
if (redditError) {
338
throw new Error(
339
"HFY Novels: Reddit (" +
340
redditError +
341
") en Arctic Shift (" +
342
(arctic.reason || "geen tekst") +
343
") faalden allebei.",
344
);
345
}
346
throw new Error("HFY Novels: kon hoofdstuk " + id + " niet laden (" + (arctic.reason || "geen tekst") + ")");
347
}
348
}
349
350
function chapterIdFromPath(chapterPath) {
351
const id = String(chapterPath || "")
352
.replace(/^chapter\//, "")
353
.replace(/^series\//, "")
354
.trim()
355
.toLowerCase();
356
return /^[0-9a-z]{4,10}$/.test(id) ? id : "";
357
}
358
359
function redditJsonUrls(id) {
360
const path = "/r/HFY/comments/" + id + "/.json?raw_json=1";
361
return [
362
"https://www.reddit.com" + path,
363
"https://old.reddit.com" + path,
364
];
365
}
366
367
function looksLikeHtml(text) {
368
const body = String(text || "").trim();
369
if (!body) {
370
return false;
371
}
372
return /^\s*<(!DOCTYPE|html|body|head)\b/i.test(body);
373
}
374
375
function isLoginOrBlockPage(res, body) {
376
const status = res && res.status != null ? Number(res.status) : 0;
377
if (status === 401 || status === 403 || status === 429) {
378
return true;
379
}
380
const finalUrl = String((res && res.url) || "");
381
if (/[?&]reason=lor2\b/i.test(finalUrl) || /\/login\b/i.test(finalUrl)) {
382
return true;
383
}
384
const type = String(
385
(res && res.headers && typeof res.headers.get === "function" && res.headers.get("content-type")) || "",
386
).toLowerCase();
387
if (type.indexOf("text/html") !== -1 && !/json/i.test(type)) {
388
return true;
389
}
390
const text = String(body || "");
391
if (looksLikeHtml(text)) {
392
return true;
393
}
394
const lower = text.toLowerCase();
395
if (
396
lower.indexOf("reason=lor2") !== -1 ||
397
lower.indexOf("www.reddit.com/login") !== -1 ||
398
lower.indexOf("old.reddit.com/login") !== -1 ||
399
lower.indexOf("log in to reddit") !== -1 ||
400
(lower.indexOf("shreddit") !== -1 && lower.indexOf("<!doctype html") !== -1)
401
) {
402
return true;
403
}
404
return false;
405
}
406
407
function postFromRedditPayload(payload) {
408
if (!payload) {
409
return null;
410
}
411
const listing = Array.isArray(payload) ? payload[0] : payload;
412
const children =
413
listing && listing.data && Array.isArray(listing.data.children) ? listing.data.children : [];
414
const child = children.find((c) => !c.kind || c.kind === "t3") || children[0];
415
if (!child || !child.data) {
416
return null;
417
}
418
if (child.kind && child.kind !== "t3") {
419
return null;
420
}
421
return child.data;
422
}
423
424
function decodeRedditHtml(html) {
425
let text = String(html || "");
426
if (text.indexOf("<") !== -1 || text.indexOf("&") !== -1) {
427
text = text
428
.replace(/</g, "<")
429
.replace(/>/g, ">")
430
.replace(/"/g, '"')
431
.replace(/'/g, "'")
432
.replace(/&/g, "&");
433
}
434
return text;
435
}
436
437
async function tryRedditChapter(id) {
438
let lastReason = "geen antwoord";
439
const urls = redditJsonUrls(id);
440
for (let i = 0; i < urls.length; i++) {
441
const url = urls[i];
442
try {
443
const res = await fetchApi(url, { headers: { Accept: "application/json" } });
444
const body = typeof res.text === "function" ? await res.text() : "";
445
if (!res || res.ok === false || isLoginOrBlockPage(res, body)) {
446
const status = res && res.status != null ? res.status : "?";
447
lastReason = "HTTP " + status + (isLoginOrBlockPage(res, body) ? " (login of blokkade)" : "");
448
continue;
449
}
450
if (!body || looksLikeHtml(body)) {
451
lastReason = "geen JSON";
452
continue;
453
}
454
let payload;
455
try {
456
payload = JSON.parse(body);
457
} catch (err) {
458
lastReason = "ongeldige JSON";
459
continue;
460
}
461
const post = postFromRedditPayload(payload);
462
if (!post) {
463
lastReason = "geen post in de listing";
464
continue;
465
}
466
return { ok: true, post: post };
467
} catch (err) {
468
lastReason = err && err.message ? err.message : String(err);
469
}
470
}
471
return { ok: false, reason: lastReason };
472
}
473
474
async function tryArcticChapter(base, id) {
475
const url = String(base || "").replace(/\/+$/, "") + "/api/posts/ids?ids=" + encodeURIComponent(id) + "&md2html=true";
476
try {
282
477
const payload = await readJson(url, "hoofdstuk " + id);
283
478
const posts = payload.data || payload;
284
479
const post = Array.isArray(posts) ? posts[0] : posts;
285
480
if (!post) {
286
return "<p><em>Dit hoofdstuk is niet (meer) beschikbaar.</em></p>";
481
return { ok: false, reason: "leeg antwoord" };
287
482
}
288
const title = post.title ? "<h1>" + escapeHtml(post.title) + "</h1>" : "";
289
const by = post.author
290
? "<p><em>by u/" + escapeHtml(post.author) + "</em></p>"
291
: "";
292
const html = post.selftext_html
293
? sanitizeHtml(post.selftext_html)
294
: markdownToHtml(post.selftext || "");
295
if (!html) {
296
return title + by + "<p><em>Deze post heeft geen tekst (verwijderd of een link-post).</em></p>";
297
}
298
return title + by + html;
483
return { ok: true, post: post };
484
} catch (err) {
485
return { ok: false, reason: err && err.message ? err.message : String(err) };
486
}
487
}
488
489
function sourceFooter(label) {
490
return '<p class="hfy-source"><em>Bron: ' + escapeHtml(label) + "</em></p>";
491
}
492
493
function renderChapter(post, sourceLabel) {
494
if (!post) {
495
return "<p><em>Dit hoofdstuk is niet (meer) beschikbaar.</em></p>" + sourceFooter(sourceLabel);
496
}
497
const title = post.title ? "<h1>" + escapeHtml(post.title) + "</h1>" : "";
498
const by = post.author ? "<p><em>by u/" + escapeHtml(post.author) + "</em></p>" : "";
499
const rawHtml = post.selftext_html ? decodeRedditHtml(post.selftext_html) : "";
500
const html = rawHtml ? sanitizeHtml(rawHtml) : markdownToHtml(post.selftext || "");
501
if (!html) {
502
return (
503
title +
504
by +
505
"<p><em>Deze post heeft geen tekst (verwijderd of een link-post).</em></p>" +
506
sourceFooter(sourceLabel)
507
);
299
508
}
509
return title + by + html + sourceFooter(sourceLabel);
300
510
}
301
511
302
512
function escapeHtml(text) {
@@ -308,7 +518,7 @@ function escapeHtml(text) {
308
518
}
309
519
310
520
function sanitizeHtml(html) {
311
// Arctic Shift levert al HTML; we strippen scripts en on-event-attributen.
521
// Reddit en Arctic Shift leveren HTML; we strippen scripts en on-event-attributen.
312
522
return String(html)
313
523
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "")
314
524
.replace(/\son[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi, "");
@@ -5,8 +5,10 @@5
*5
*6
* De catalogus (titels, auteurs, hoofdstuklijsten) komt uit een statische6
* De catalogus (titels, auteurs, hoofdstuklijsten) komt uit een statische7
* JSON-index. De verhaaltekst zelf staat niet in die index: parseChapter7
* JSON-index. De verhaaltekst zelf staat niet in die index: parseChapter8
* haalt een hoofdstuk live op via de Arctic Shift-API (optioneel te8
* probeert eerst de echte Reddit-JSON (www.reddit.com/.../.json, daarna9
* overschrijven in de plugin-instellingen).9
* old.reddit.com) via fetchApi, zodat cookies uit de LNReader-WebView10
* meegaan na inloggen op reddit.com. Bij een fout, 403 of login-/blokpagina11
* valt de plugin terug op Arctic Shift.10
*12
*11
* Dit bestand is CommonJS, zoals de officiële gecompileerde plugins:13
* Dit bestand is CommonJS, zoals de officiële gecompileerde plugins:12
* require(...) uit de LNReader-allowlist, en `exports.default = instance`.14
* require(...) uit de LNReader-allowlist, en `exports.default = instance`.@@ -94,9 +96,12 @@ class HFYNovelsPlugin {94
constructor() {96
constructor() {95
this.id = "hfyNovels";97
this.id = "hfyNovels";96
this.name = "HFY Novels";98
this.name = "HFY Novels";97
this.version = "0.1.0";99
this.version = "0.2.0";98
this.site = "https://www.reddit.com/r/HFY/";100
this.site = "https://www.reddit.com/r/HFY/";99
this.icon = "icon.png";101
this.icon = "icon.png";102
// Geen webStorageUtilized: Reddit-login zit in cookies. LNReader's103
// fetchApi (native fetch) stuurt de WebView-cookies automatisch mee104
// voor hetzelfde domein; localStorage is daarvoor niet nodig.100
this.filters = {105
this.filters = {101
kind: {106
kind: {102
value: "all",107
value: "all",@@ -129,9 +134,19 @@ class HFYNovelsPlugin {129
label: "Git-revisie van de index (rev=)",134
label: "Git-revisie van de index (rev=)",130
type: "Text",135
type: "Text",131
},136
},137
chapterSource: {138
value: "auto",139
label: "Bron voor hoofdstuktekst",140
type: "Select",141
options: [142
{ label: "Automatisch (Reddit, anders Arctic Shift)", value: "auto" },143
{ label: "Alleen Reddit", value: "reddit" },144
{ label: "Alleen Arctic Shift", value: "arctic" },145
],146
},132
chapterSourceUrl: {147
chapterSourceUrl: {133
value: DEFAULT_CHAPTER_SOURCE,148
value: DEFAULT_CHAPTER_SOURCE,134
label: "Bron voor hoofdstuktekst (Arctic Shift)",149
label: "Arctic Shift-basis-URL (fallback)",135
type: "Text",150
type: "Text",136
},151
},137
};152
};@@ -166,6 +181,32 @@ class HFYNovelsPlugin {166
return String(setting("chapterSourceUrl", DEFAULT_CHAPTER_SOURCE)).replace(/\/+$/, "");181
return String(setting("chapterSourceUrl", DEFAULT_CHAPTER_SOURCE)).replace(/\/+$/, "");167
}182
}168
183
184
chapterMode() {185
const mode = String(setting("chapterSource", "auto") || "auto").toLowerCase();186
if (mode === "reddit" || mode === "arctic") {187
return mode;188
}189
return "auto";190
}191
192
/**193
* Maakt "Open in WebView" op een reeks of hoofdstuk tot een Reddit-URL,194
* zodat je daar kunt inloggen. Zonder deze functie zou LNReader195
* site+path plakken (bijv. /r/HFY/series/id), wat geen geldige Reddit-pagina is.196
* Het reeks-id is de oudste post (eerste deel).197
*/198
resolveUrl(path, isNovel) {199
const raw = String(path || "").trim();200
if (/^https?:\/\//i.test(raw)) {201
return raw;202
}203
const id = chapterIdFromPath(raw) || chapterIdFromPath(raw.replace(/^series\//, "chapter/"));204
if (id) {205
return "https://www.reddit.com/r/HFY/comments/" + id + "/";206
}207
return this.site;208
}209
169
matchesFilters(entry, filters) {210
matchesFilters(entry, filters) {170
const kind = filters && filters.kind ? filters.kind.value : "all";211
const kind = filters && filters.kind ? filters.kind.value : "all";171
const nsfw = filters && filters.nsfw ? filters.nsfw.value : "hide";212
const nsfw = filters && filters.nsfw ? filters.nsfw.value : "hide";@@ -266,37 +307,206 @@ class HFYNovelsPlugin {266
};307
};267
}308
}268
309
310
269
async parseChapter(chapterPath) {311
async parseChapter(chapterPath) {270
const id = String(chapterPath || "")312
const id = chapterIdFromPath(chapterPath);271
.replace(/^chapter\//, "")313
if (!id) {272
.trim()273
.toLowerCase();274
if (!/^[0-9a-z]{4,10}$/.test(id)) {275
throw new Error("HFY Novels: ongeldig hoofdstuk-id");314
throw new Error("HFY Novels: ongeldig hoofdstuk-id");276
}315
}277
const url =316
const mode = this.chapterMode();278
this.chapterSource() +317
let redditError = "";279
"/api/posts/ids?ids=" +318
if (mode !== "arctic") {280
encodeURIComponent(id) +319
const reddit = await tryRedditChapter(id);281
"&md2html=true";320
if (reddit.ok) {321
return renderChapter(reddit.post, "Reddit");322
}323
redditError = reddit.reason || "onbekende fout";324
if (mode === "reddit") {325
throw new Error(326
"HFY Novels: Reddit gaf geen hoofdstuk (" +327
redditError +328
"). Log in via Open in WebView op reddit.com en probeer het opnieuw.",329
);330
}331
}332
const arctic = await tryArcticChapter(this.chapterSource(), id);333
if (arctic.ok) {334
const suffix = mode === "arctic" ? "Arctic Shift" : "Arctic Shift (fallback)";335
return renderChapter(arctic.post, suffix);336
}337
if (redditError) {338
throw new Error(339
"HFY Novels: Reddit (" +340
redditError +341
") en Arctic Shift (" +342
(arctic.reason || "geen tekst") +343
") faalden allebei.",344
);345
}346
throw new Error("HFY Novels: kon hoofdstuk " + id + " niet laden (" + (arctic.reason || "geen tekst") + ")");347
}348
}349
350
function chapterIdFromPath(chapterPath) {351
const id = String(chapterPath || "")352
.replace(/^chapter\//, "")353
.replace(/^series\//, "")354
.trim()355
.toLowerCase();356
return /^[0-9a-z]{4,10}$/.test(id) ? id : "";357
}358
359
function redditJsonUrls(id) {360
const path = "/r/HFY/comments/" + id + "/.json?raw_json=1";361
return [362
"https://www.reddit.com" + path,363
"https://old.reddit.com" + path,364
];365
}366
367
function looksLikeHtml(text) {368
const body = String(text || "").trim();369
if (!body) {370
return false;371
}372
return /^\s*<(!DOCTYPE|html|body|head)\b/i.test(body);373
}374
375
function isLoginOrBlockPage(res, body) {376
const status = res && res.status != null ? Number(res.status) : 0;377
if (status === 401 || status === 403 || status === 429) {378
return true;379
}380
const finalUrl = String((res && res.url) || "");381
if (/[?&]reason=lor2\b/i.test(finalUrl) || /\/login\b/i.test(finalUrl)) {382
return true;383
}384
const type = String(385
(res && res.headers && typeof res.headers.get === "function" && res.headers.get("content-type")) || "",386
).toLowerCase();387
if (type.indexOf("text/html") !== -1 && !/json/i.test(type)) {388
return true;389
}390
const text = String(body || "");391
if (looksLikeHtml(text)) {392
return true;393
}394
const lower = text.toLowerCase();395
if (396
lower.indexOf("reason=lor2") !== -1 ||397
lower.indexOf("www.reddit.com/login") !== -1 ||398
lower.indexOf("old.reddit.com/login") !== -1 ||399
lower.indexOf("log in to reddit") !== -1 ||400
(lower.indexOf("shreddit") !== -1 && lower.indexOf("<!doctype html") !== -1)401
) {402
return true;403
}404
return false;405
}406
407
function postFromRedditPayload(payload) {408
if (!payload) {409
return null;410
}411
const listing = Array.isArray(payload) ? payload[0] : payload;412
const children =413
listing && listing.data && Array.isArray(listing.data.children) ? listing.data.children : [];414
const child = children.find((c) => !c.kind || c.kind === "t3") || children[0];415
if (!child || !child.data) {416
return null;417
}418
if (child.kind && child.kind !== "t3") {419
return null;420
}421
return child.data;422
}423
424
function decodeRedditHtml(html) {425
let text = String(html || "");426
if (text.indexOf("<") !== -1 || text.indexOf("&") !== -1) {427
text = text428
.replace(/</g, "<")429
.replace(/>/g, ">")430
.replace(/"/g, '"')431
.replace(/'/g, "'")432
.replace(/&/g, "&");433
}434
return text;435
}436
437
async function tryRedditChapter(id) {438
let lastReason = "geen antwoord";439
const urls = redditJsonUrls(id);440
for (let i = 0; i < urls.length; i++) {441
const url = urls[i];442
try {443
const res = await fetchApi(url, { headers: { Accept: "application/json" } });444
const body = typeof res.text === "function" ? await res.text() : "";445
if (!res || res.ok === false || isLoginOrBlockPage(res, body)) {446
const status = res && res.status != null ? res.status : "?";447
lastReason = "HTTP " + status + (isLoginOrBlockPage(res, body) ? " (login of blokkade)" : "");448
continue;449
}450
if (!body || looksLikeHtml(body)) {451
lastReason = "geen JSON";452
continue;453
}454
let payload;455
try {456
payload = JSON.parse(body);457
} catch (err) {458
lastReason = "ongeldige JSON";459
continue;460
}461
const post = postFromRedditPayload(payload);462
if (!post) {463
lastReason = "geen post in de listing";464
continue;465
}466
return { ok: true, post: post };467
} catch (err) {468
lastReason = err && err.message ? err.message : String(err);469
}470
}471
return { ok: false, reason: lastReason };472
}473
474
async function tryArcticChapter(base, id) {475
const url = String(base || "").replace(/\/+$/, "") + "/api/posts/ids?ids=" + encodeURIComponent(id) + "&md2html=true";476
try {282
const payload = await readJson(url, "hoofdstuk " + id);477
const payload = await readJson(url, "hoofdstuk " + id);283
const posts = payload.data || payload;478
const posts = payload.data || payload;284
const post = Array.isArray(posts) ? posts[0] : posts;479
const post = Array.isArray(posts) ? posts[0] : posts;285
if (!post) {480
if (!post) {286
return "<p><em>Dit hoofdstuk is niet (meer) beschikbaar.</em></p>";481
return { ok: false, reason: "leeg antwoord" };287
}482
}288
const title = post.title ? "<h1>" + escapeHtml(post.title) + "</h1>" : "";483
return { ok: true, post: post };289
const by = post.author484
} catch (err) {290
? "<p><em>by u/" + escapeHtml(post.author) + "</em></p>"485
return { ok: false, reason: err && err.message ? err.message : String(err) };291
: "";486
}292
const html = post.selftext_html487
}293
? sanitizeHtml(post.selftext_html)488
294
: markdownToHtml(post.selftext || "");489
function sourceFooter(label) {295
if (!html) {490
return '<p class="hfy-source"><em>Bron: ' + escapeHtml(label) + "</em></p>";296
return title + by + "<p><em>Deze post heeft geen tekst (verwijderd of een link-post).</em></p>";491
}297
}492
298
return title + by + html;493
function renderChapter(post, sourceLabel) {494
if (!post) {495
return "<p><em>Dit hoofdstuk is niet (meer) beschikbaar.</em></p>" + sourceFooter(sourceLabel);496
}497
const title = post.title ? "<h1>" + escapeHtml(post.title) + "</h1>" : "";498
const by = post.author ? "<p><em>by u/" + escapeHtml(post.author) + "</em></p>" : "";499
const rawHtml = post.selftext_html ? decodeRedditHtml(post.selftext_html) : "";500
const html = rawHtml ? sanitizeHtml(rawHtml) : markdownToHtml(post.selftext || "");501
if (!html) {502
return (503
title +504
by +505
"<p><em>Deze post heeft geen tekst (verwijderd of een link-post).</em></p>" +506
sourceFooter(sourceLabel)507
);299
}508
}509
return title + by + html + sourceFooter(sourceLabel);300
}510
}301
511
302
function escapeHtml(text) {512
function escapeHtml(text) {@@ -308,7 +518,7 @@ function escapeHtml(text) {308
}518
}309
519
310
function sanitizeHtml(html) {520
function sanitizeHtml(html) {311
// Arctic Shift levert al HTML; we strippen scripts en on-event-attributen.521
// Reddit en Arctic Shift leveren HTML; we strippen scripts en on-event-attributen.312
return String(html)522
return String(html)313
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "")523
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "")314
.replace(/\son[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi, "");524
.replace(/\son[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi, "");@@ -4,7 +4,7 @@
4
4
"name": "HFY Novels",
5
5
"site": "https://www.reddit.com/r/HFY/",
6
6
"lang": "English",
7
"version": "0.1.0",
7
"version": "0.2.0",
8
8
"url": "https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/hfy-novels.js?rev=master",
9
9
"iconUrl": "https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/icon.png?rev=master",
10
10
"hasSettings": true
@@ -4,7 +4,7 @@4
"name": "HFY Novels",4
"name": "HFY Novels",5
"site": "https://www.reddit.com/r/HFY/",5
"site": "https://www.reddit.com/r/HFY/",6
"lang": "English",6
"lang": "English",7
"version": "0.1.0",7
"version": "0.2.0",8
"url": "https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/hfy-novels.js?rev=master",8
"url": "https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/hfy-novels.js?rev=master",9
"iconUrl": "https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/icon.png?rev=master",9
"iconUrl": "https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/icon.png?rev=master",10
"hasSettings": true10
"hasSettings": true@@ -1 +1 @@
1
[{"id":"hfyNovels","name":"HFY Novels","site":"https://www.reddit.com/r/HFY/","lang":"English","version":"0.1.0","url":"https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/hfy-novels.js?rev=master","iconUrl":"https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/icon.png?rev=master","hasSettings":true}]
1
[{"id":"hfyNovels","name":"HFY Novels","site":"https://www.reddit.com/r/HFY/","lang":"English","version":"0.2.0","url":"https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/hfy-novels.js?rev=master","iconUrl":"https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/icon.png?rev=master","hasSettings":true}]
@@ -1 +1 @@1
[{"id":"hfyNovels","name":"HFY Novels","site":"https://www.reddit.com/r/HFY/","lang":"English","version":"0.1.0","url":"https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/hfy-novels.js?rev=master","iconUrl":"https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/icon.png?rev=master","hasSettings":true}]1
[{"id":"hfyNovels","name":"HFY Novels","site":"https://www.reddit.com/r/HFY/","lang":"English","version":"0.2.0","url":"https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/hfy-novels.js?rev=master","iconUrl":"https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/icon.png?rev=master","hasSettings":true}]@@ -1,19 +1,19 @@
1
1
# HFY Novels
2
2
3
Een [LNReader](https://www.lnreader.app/)-pluginbron voor verhalen van [r/HFY](https://www.reddit.com/r/HFY/). Deze repository is zelf de plugin-repository: LNReader laadt een `plugins.json` en een gebouwde plugin-JS via de raw-URL van BlueGit.
3
Een [LNReader](https://www.lnreader.app/)-pluginbron voor verhalen van [r/HFY](https://www.reddit.com/r/HFY/). Deze repository is zelf de plugin-repository: LNReader laadt een `plugins.min.json` en een gebouwde plugin-JS via de raw-URL van BlueGit.
4
4
5
De index bevat **alleen metadata** (titel, auteur, hoofdstukvolgorde, Reddit-IDs). De tekst van de verhalen staat er niet in. Die haalt de plugin pas op als je een hoofdstuk opent, via de publieke [Arctic Shift](https://arctic-shift.photon-reddit.com/)-API.
5
De index bevat **alleen metadata** (titel, auteur, hoofdstukvolgorde, Reddit-IDs). De tekst van de verhalen staat er niet in. Die haalt de plugin pas op als je een hoofdstuk opent: eerst via Reddit-JSON (met de sessie uit de WebView), en bij een fout, 403 of loginpagina via [Arctic Shift](https://arctic-shift.photon-reddit.com/).
6
6
7
7
## In LNReader zetten
8
8
9
9
1. Open LNReader → **Plugins** (of Instellingen → Repos).
10
2. Voeg deze repository-URL toe, precies zo (inclusief `?rev=master`):
10
2. Voeg deze repository-URL toe, precies zo (inclusief `plugins.min.json` en `?rev=master`):
11
11
12
12
```
13
https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/plugins.json?rev=master
13
https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/plugins.min.json?rev=master
14
14
```
15
15
16
Een verkleinde variant is `.dist/plugins.min.json` (zelfde inhoud). Daarna bronnen verversen en de plugin **HFY Novels** installeren.
16
LNReader accepteert alleen een URL die `plugins.min.json` bevat. Daarna bronnen verversen en de plugin **HFY Novels** installeren of bijwerken.
17
17
18
18
BlueGit slaat de repository op als `timfa/hfy-novels` (kleine letters). Die spelling moet in de URL staan; `HFY-Novels` geeft een 404.
19
19
@@ -24,12 +24,21 @@ BlueGit serveert raw-bestanden als `text/plain`. Dat is voor LNReader geen probl
24
24
- Bladeren (paginagewijs, nieuwste reeksen eerst) en zoeken op titel of auteur.
25
25
- Filters: reeksen / oneshots, NSFW verbergen of tonen.
26
26
- Een reeks openen met de volledige hoofdstuklijst.
27
- Een hoofdstuk lezen (tekst komt live van Arctic Shift, niet uit deze repo).
27
- Een hoofdstuk lezen (eerst Reddit-JSON, anders Arctic Shift; onderaan het hoofdstuk staat welke bron is gebruikt).
28
28
29
29
Elk verhaal zonder eigen omslag krijgt een **deterministische cover**: uit een hash van de titel volgt een kleurverloop of patroon, met de titel leesbaar erop. Dezelfde titel geeft altijd dezelfde cover; lange titels worden netjes afgebroken. De indexer schrijft een PNG (240×360) in `public/covers/`, omdat LNReader covers via expo-image laadt. Zonder Pillow valt hij terug op SVG. De covers worden bij het bouwen van de index meegenomen, ook in CI.
30
30
31
31
32
In de plugin-instellingen kun je de index-URL, de git-revisie en de hoofdstukbron aanpassen.
32
### Inloggen via de WebView (aanbevolen)
33
34
Anonieme Reddit-JSON is sinds 2026 vaak geblokkeerd. Als je in LNReader op reddit.com inlogt, stuurt de plugin die cookies automatisch mee (dezelfde cookie-jar als de WebView; `fetchApi` gebruikt dezelfde User-Agent).
35
36
1. Werk de plugin bij als LNReader een update naar een nieuwere versie toont (bronnen verversen, daarna bijwerken).
37
2. Open de plugin **HFY Novels** → **Website** (of in een reeks/hoofdstuk **Open in WebView**). Je komt op r/HFY.
38
3. Log in op Reddit en sluit de WebView daarna af.
39
4. Open een hoofdstuk. Onderaan de tekst staat **Bron: Reddit** als het via je sessie lukte, of **Bron: Arctic Shift (fallback)** als Reddit een 403 of loginpagina teruggaf.
40
41
In de plugin-instellingen kun je de bron vastzetten op *Automatisch*, *Alleen Reddit* of *Alleen Arctic Shift*, en zo nodig de index-URL of Arctic Shift-basis-URL aanpassen.
33
42
34
43
## Hoe de index wordt gemaakt
35
44
@@ -56,7 +65,7 @@ Zet `HFY_LIVE=1` bij de plugintest om `parseChapter` ook tegen de echte Arctic S
56
65
57
66
- De catalogus volgt de wiki, niet een eigen scan van de subreddit. De wiki is zelf een momentopname (Arctic Shift bewaart een revisie) en is niet altijd volledig of bijgewerkt. Ontbrekende subpagina’s in het archief betekenen vaak dat een serie nog geen hoofdstukken in de index krijgt.
58
67
- Hoofdstukken na het laatste wiki-deel worden via next-links en titelgelijkenis toegevoegd; die heuristiek kan een keten te vroeg stoppen of (zelden) een verkeerde link volgen.
59
- Hoofdstukken laden hangt af van Arctic Shift (een onofficieel archief, zonder uptime-garantie). De officiële Reddit-API eist sinds 2026 OAuth; anonieme `.json`-URLs werken niet meer.
68
- Hoofdstukken komen bij voorkeur van Reddit-JSON met je WebView-sessie. Zonder login (of bij een 403/blokpagina) valt de plugin terug op Arctic Shift, een onofficieel archief zonder uptime-garantie.
60
69
- Auteurs houden het auteursrecht op hun verhalen. Deze repo host die teksten bewust niet. Gebruik is bedoeld voor persoonlijk lezen; een openbare herpublicatie van de teksten is iets anders.
61
70
- `--max-pages` is een budget voor API-verzoeken per run. Een eerste volledige index kan meerdere `update-index`-runs nodig hebben.
62
71
@@ -1,19 +1,19 @@1
# HFY Novels1
# HFY Novels2
2
3
Een [LNReader](https://www.lnreader.app/)-pluginbron voor verhalen van [r/HFY](https://www.reddit.com/r/HFY/). Deze repository is zelf de plugin-repository: LNReader laadt een `plugins.json` en een gebouwde plugin-JS via de raw-URL van BlueGit.3
Een [LNReader](https://www.lnreader.app/)-pluginbron voor verhalen van [r/HFY](https://www.reddit.com/r/HFY/). Deze repository is zelf de plugin-repository: LNReader laadt een `plugins.min.json` en een gebouwde plugin-JS via de raw-URL van BlueGit.4
4
5
De index bevat **alleen metadata** (titel, auteur, hoofdstukvolgorde, Reddit-IDs). De tekst van de verhalen staat er niet in. Die haalt de plugin pas op als je een hoofdstuk opent, via de publieke [Arctic Shift](https://arctic-shift.photon-reddit.com/)-API.5
De index bevat **alleen metadata** (titel, auteur, hoofdstukvolgorde, Reddit-IDs). De tekst van de verhalen staat er niet in. Die haalt de plugin pas op als je een hoofdstuk opent: eerst via Reddit-JSON (met de sessie uit de WebView), en bij een fout, 403 of loginpagina via [Arctic Shift](https://arctic-shift.photon-reddit.com/).6
6
7
## In LNReader zetten7
## In LNReader zetten8
8
9
1. Open LNReader → **Plugins** (of Instellingen → Repos).9
1. Open LNReader → **Plugins** (of Instellingen → Repos).10
2. Voeg deze repository-URL toe, precies zo (inclusief `?rev=master`):10
2. Voeg deze repository-URL toe, precies zo (inclusief `plugins.min.json` en `?rev=master`):11
11
12
```12
```13
https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/plugins.json?rev=master13
https://git.timfalken.com/timfa/hfy-novels/-/raw/.dist/plugins.min.json?rev=master14
```14
```15
15
16
Een verkleinde variant is `.dist/plugins.min.json` (zelfde inhoud). Daarna bronnen verversen en de plugin **HFY Novels** installeren.16
LNReader accepteert alleen een URL die `plugins.min.json` bevat. Daarna bronnen verversen en de plugin **HFY Novels** installeren of bijwerken.17
17
18
BlueGit slaat de repository op als `timfa/hfy-novels` (kleine letters). Die spelling moet in de URL staan; `HFY-Novels` geeft een 404.18
BlueGit slaat de repository op als `timfa/hfy-novels` (kleine letters). Die spelling moet in de URL staan; `HFY-Novels` geeft een 404.19
19
@@ -24,12 +24,21 @@ BlueGit serveert raw-bestanden als `text/plain`. Dat is voor LNReader geen probl24
- Bladeren (paginagewijs, nieuwste reeksen eerst) en zoeken op titel of auteur.24
- Bladeren (paginagewijs, nieuwste reeksen eerst) en zoeken op titel of auteur.25
- Filters: reeksen / oneshots, NSFW verbergen of tonen.25
- Filters: reeksen / oneshots, NSFW verbergen of tonen.26
- Een reeks openen met de volledige hoofdstuklijst.26
- Een reeks openen met de volledige hoofdstuklijst.27
- Een hoofdstuk lezen (tekst komt live van Arctic Shift, niet uit deze repo).27
- Een hoofdstuk lezen (eerst Reddit-JSON, anders Arctic Shift; onderaan het hoofdstuk staat welke bron is gebruikt).28
28
29
Elk verhaal zonder eigen omslag krijgt een **deterministische cover**: uit een hash van de titel volgt een kleurverloop of patroon, met de titel leesbaar erop. Dezelfde titel geeft altijd dezelfde cover; lange titels worden netjes afgebroken. De indexer schrijft een PNG (240×360) in `public/covers/`, omdat LNReader covers via expo-image laadt. Zonder Pillow valt hij terug op SVG. De covers worden bij het bouwen van de index meegenomen, ook in CI.29
Elk verhaal zonder eigen omslag krijgt een **deterministische cover**: uit een hash van de titel volgt een kleurverloop of patroon, met de titel leesbaar erop. Dezelfde titel geeft altijd dezelfde cover; lange titels worden netjes afgebroken. De indexer schrijft een PNG (240×360) in `public/covers/`, omdat LNReader covers via expo-image laadt. Zonder Pillow valt hij terug op SVG. De covers worden bij het bouwen van de index meegenomen, ook in CI.30
30
31
31
32
In de plugin-instellingen kun je de index-URL, de git-revisie en de hoofdstukbron aanpassen.32
### Inloggen via de WebView (aanbevolen)33
34
Anonieme Reddit-JSON is sinds 2026 vaak geblokkeerd. Als je in LNReader op reddit.com inlogt, stuurt de plugin die cookies automatisch mee (dezelfde cookie-jar als de WebView; `fetchApi` gebruikt dezelfde User-Agent).35
36
1. Werk de plugin bij als LNReader een update naar een nieuwere versie toont (bronnen verversen, daarna bijwerken).37
2. Open de plugin **HFY Novels** → **Website** (of in een reeks/hoofdstuk **Open in WebView**). Je komt op r/HFY.38
3. Log in op Reddit en sluit de WebView daarna af.39
4. Open een hoofdstuk. Onderaan de tekst staat **Bron: Reddit** als het via je sessie lukte, of **Bron: Arctic Shift (fallback)** als Reddit een 403 of loginpagina teruggaf.40
41
In de plugin-instellingen kun je de bron vastzetten op *Automatisch*, *Alleen Reddit* of *Alleen Arctic Shift*, en zo nodig de index-URL of Arctic Shift-basis-URL aanpassen.33
42
34
## Hoe de index wordt gemaakt43
## Hoe de index wordt gemaakt35
44
@@ -56,7 +65,7 @@ Zet `HFY_LIVE=1` bij de plugintest om `parseChapter` ook tegen de echte Arctic S56
65
57
- De catalogus volgt de wiki, niet een eigen scan van de subreddit. De wiki is zelf een momentopname (Arctic Shift bewaart een revisie) en is niet altijd volledig of bijgewerkt. Ontbrekende subpagina’s in het archief betekenen vaak dat een serie nog geen hoofdstukken in de index krijgt.66
- De catalogus volgt de wiki, niet een eigen scan van de subreddit. De wiki is zelf een momentopname (Arctic Shift bewaart een revisie) en is niet altijd volledig of bijgewerkt. Ontbrekende subpagina’s in het archief betekenen vaak dat een serie nog geen hoofdstukken in de index krijgt.58
- Hoofdstukken na het laatste wiki-deel worden via next-links en titelgelijkenis toegevoegd; die heuristiek kan een keten te vroeg stoppen of (zelden) een verkeerde link volgen.67
- Hoofdstukken na het laatste wiki-deel worden via next-links en titelgelijkenis toegevoegd; die heuristiek kan een keten te vroeg stoppen of (zelden) een verkeerde link volgen.59
- Hoofdstukken laden hangt af van Arctic Shift (een onofficieel archief, zonder uptime-garantie). De officiële Reddit-API eist sinds 2026 OAuth; anonieme `.json`-URLs werken niet meer.68
- Hoofdstukken komen bij voorkeur van Reddit-JSON met je WebView-sessie. Zonder login (of bij een 403/blokpagina) valt de plugin terug op Arctic Shift, een onofficieel archief zonder uptime-garantie.60
- Auteurs houden het auteursrecht op hun verhalen. Deze repo host die teksten bewust niet. Gebruik is bedoeld voor persoonlijk lezen; een openbare herpublicatie van de teksten is iets anders.69
- Auteurs houden het auteursrecht op hun verhalen. Deze repo host die teksten bewust niet. Gebruik is bedoeld voor persoonlijk lezen; een openbare herpublicatie van de teksten is iets anders.61
- `--max-pages` is een budget voor API-verzoeken per run. Een eerste volledige index kan meerdere `update-index`-runs nodig hebben.70
- `--max-pages` is een budget voor API-verzoeken per run. Een eerste volledige index kan meerdere `update-index`-runs nodig hebben.62
71
@@ -57,7 +57,11 @@ Statusvelden (`Ongoing`, `On Hiatus`, `Completed`) zijn een schatting (oneshot =
57
57
58
58
## Plugin-runtime
59
59
60
De tests evalueren de plugin met `new Function` en een begrensde `require`, en serveren de fixture-index over HTTP als `text/plain`, hetzelfde type als BlueGit-raw. `parseChapter` wordt tegen een lokale mock van Arctic Shift getest, en optioneel live (`HFY_LIVE=1`). We hebben de plugin niet in de LNReader-Android-app zelf geïnstalleerd.
60
De tests evalueren de plugin met `new Function` en een begrensde `require`, en serveren de fixture-index over HTTP als `text/plain`, hetzelfde type als BlueGit-raw. `parseChapter` wordt getest met een mock van Reddit-JSON (succes, HTTP 403 en login-HTML) en een fallback naar Arctic Shift, en optioneel live (`HFY_LIVE=1`). We hebben de plugin niet in de LNReader-Android-app zelf geïnstalleerd.
61
62
LNReader's `fetchApi` is native `fetch` plus de app-User-Agent. Cookies uit de WebView worden door React Native automatisch meegestuurd naar hetzelfde domein; je hoeft geen `Cookie`-header te zetten. `webStorageUtilized` is niet gezet: dat kopieert alleen `localStorage`/`sessionStorage`, terwijl Reddit-login in cookies zit. De plugin-`site` is `https://www.reddit.com/r/HFY/`, zodat **Website** / **Open in WebView** op reddit.com opent. `resolveUrl` zet een reeks- of hoofdstukpad om naar `https://www.reddit.com/r/HFY/comments/<id>/`.
63
64
LNReader eist dat de repository-URL `plugins.min.json` bevat (regex in `SettingsRepositoryScreen.tsx`).
61
65
62
66
## Covers
63
67
@@ -57,7 +57,11 @@ Statusvelden (`Ongoing`, `On Hiatus`, `Completed`) zijn een schatting (oneshot =57
57
58
## Plugin-runtime58
## Plugin-runtime59
59
60
De tests evalueren de plugin met `new Function` en een begrensde `require`, en serveren de fixture-index over HTTP als `text/plain`, hetzelfde type als BlueGit-raw. `parseChapter` wordt tegen een lokale mock van Arctic Shift getest, en optioneel live (`HFY_LIVE=1`). We hebben de plugin niet in de LNReader-Android-app zelf geïnstalleerd.60
De tests evalueren de plugin met `new Function` en een begrensde `require`, en serveren de fixture-index over HTTP als `text/plain`, hetzelfde type als BlueGit-raw. `parseChapter` wordt getest met een mock van Reddit-JSON (succes, HTTP 403 en login-HTML) en een fallback naar Arctic Shift, en optioneel live (`HFY_LIVE=1`). We hebben de plugin niet in de LNReader-Android-app zelf geïnstalleerd.61
62
LNReader's `fetchApi` is native `fetch` plus de app-User-Agent. Cookies uit de WebView worden door React Native automatisch meegestuurd naar hetzelfde domein; je hoeft geen `Cookie`-header te zetten. `webStorageUtilized` is niet gezet: dat kopieert alleen `localStorage`/`sessionStorage`, terwijl Reddit-login in cookies zit. De plugin-`site` is `https://www.reddit.com/r/HFY/`, zodat **Website** / **Open in WebView** op reddit.com opent. `resolveUrl` zet een reeks- of hoofdstukpad om naar `https://www.reddit.com/r/HFY/comments/<id>/`.63
64
LNReader eist dat de repository-URL `plugins.min.json` bevat (regex in `SettingsRepositoryScreen.tsx`).61
65
62
## Covers66
## Covers63
67
@@ -5,8 +5,10 @@
5
5
*
6
6
* De catalogus (titels, auteurs, hoofdstuklijsten) komt uit een statische
7
7
* JSON-index. De verhaaltekst zelf staat niet in die index: parseChapter
8
* haalt een hoofdstuk live op via de Arctic Shift-API (optioneel te
9
* overschrijven in de plugin-instellingen).
8
* probeert eerst de echte Reddit-JSON (www.reddit.com/.../.json, daarna
9
* old.reddit.com) via fetchApi, zodat cookies uit de LNReader-WebView
10
* meegaan na inloggen op reddit.com. Bij een fout, 403 of login-/blokpagina
11
* valt de plugin terug op Arctic Shift.
10
12
*
11
13
* Dit bestand is CommonJS, zoals de officiële gecompileerde plugins:
12
14
* require(...) uit de LNReader-allowlist, en `exports.default = instance`.
@@ -94,9 +96,12 @@ class HFYNovelsPlugin {
94
96
constructor() {
95
97
this.id = "hfyNovels";
96
98
this.name = "HFY Novels";
97
this.version = "0.1.0";
99
this.version = "0.2.0";
98
100
this.site = "https://www.reddit.com/r/HFY/";
99
101
this.icon = "icon.png";
102
// Geen webStorageUtilized: Reddit-login zit in cookies. LNReader's
103
// fetchApi (native fetch) stuurt de WebView-cookies automatisch mee
104
// voor hetzelfde domein; localStorage is daarvoor niet nodig.
100
105
this.filters = {
101
106
kind: {
102
107
value: "all",
@@ -129,9 +134,19 @@ class HFYNovelsPlugin {
129
134
label: "Git-revisie van de index (rev=)",
130
135
type: "Text",
131
136
},
137
chapterSource: {
138
value: "auto",
139
label: "Bron voor hoofdstuktekst",
140
type: "Select",
141
options: [
142
{ label: "Automatisch (Reddit, anders Arctic Shift)", value: "auto" },
143
{ label: "Alleen Reddit", value: "reddit" },
144
{ label: "Alleen Arctic Shift", value: "arctic" },
145
],
146
},
132
147
chapterSourceUrl: {
133
148
value: DEFAULT_CHAPTER_SOURCE,
134
label: "Bron voor hoofdstuktekst (Arctic Shift)",
149
label: "Arctic Shift-basis-URL (fallback)",
135
150
type: "Text",
136
151
},
137
152
};
@@ -166,6 +181,32 @@ class HFYNovelsPlugin {
166
181
return String(setting("chapterSourceUrl", DEFAULT_CHAPTER_SOURCE)).replace(/\/+$/, "");
167
182
}
168
183
184
chapterMode() {
185
const mode = String(setting("chapterSource", "auto") || "auto").toLowerCase();
186
if (mode === "reddit" || mode === "arctic") {
187
return mode;
188
}
189
return "auto";
190
}
191
192
/**
193
* Maakt "Open in WebView" op een reeks of hoofdstuk tot een Reddit-URL,
194
* zodat je daar kunt inloggen. Zonder deze functie zou LNReader
195
* site+path plakken (bijv. /r/HFY/series/id), wat geen geldige Reddit-pagina is.
196
* Het reeks-id is de oudste post (eerste deel).
197
*/
198
resolveUrl(path, isNovel) {
199
const raw = String(path || "").trim();
200
if (/^https?:\/\//i.test(raw)) {
201
return raw;
202
}
203
const id = chapterIdFromPath(raw) || chapterIdFromPath(raw.replace(/^series\//, "chapter/"));
204
if (id) {
205
return "https://www.reddit.com/r/HFY/comments/" + id + "/";
206
}
207
return this.site;
208
}
209
169
210
matchesFilters(entry, filters) {
170
211
const kind = filters && filters.kind ? filters.kind.value : "all";
171
212
const nsfw = filters && filters.nsfw ? filters.nsfw.value : "hide";
@@ -266,37 +307,206 @@ class HFYNovelsPlugin {
266
307
};
267
308
}
268
309
310
269
311
async parseChapter(chapterPath) {
270
const id = String(chapterPath || "")
271
.replace(/^chapter\//, "")
272
.trim()
273
.toLowerCase();
274
if (!/^[0-9a-z]{4,10}$/.test(id)) {
312
const id = chapterIdFromPath(chapterPath);
313
if (!id) {
275
314
throw new Error("HFY Novels: ongeldig hoofdstuk-id");
276
315
}
277
const url =
278
this.chapterSource() +
279
"/api/posts/ids?ids=" +
280
encodeURIComponent(id) +
281
"&md2html=true";
316
const mode = this.chapterMode();
317
let redditError = "";
318
if (mode !== "arctic") {
319
const reddit = await tryRedditChapter(id);
320
if (reddit.ok) {
321
return renderChapter(reddit.post, "Reddit");
322
}
323
redditError = reddit.reason || "onbekende fout";
324
if (mode === "reddit") {
325
throw new Error(
326
"HFY Novels: Reddit gaf geen hoofdstuk (" +
327
redditError +
328
"). Log in via Open in WebView op reddit.com en probeer het opnieuw.",
329
);
330
}
331
}
332
const arctic = await tryArcticChapter(this.chapterSource(), id);
333
if (arctic.ok) {
334
const suffix = mode === "arctic" ? "Arctic Shift" : "Arctic Shift (fallback)";
335
return renderChapter(arctic.post, suffix);
336
}
337
if (redditError) {
338
throw new Error(
339
"HFY Novels: Reddit (" +
340
redditError +
341
") en Arctic Shift (" +
342
(arctic.reason || "geen tekst") +
343
") faalden allebei.",
344
);
345
}
346
throw new Error("HFY Novels: kon hoofdstuk " + id + " niet laden (" + (arctic.reason || "geen tekst") + ")");
347
}
348
}
349
350
function chapterIdFromPath(chapterPath) {
351
const id = String(chapterPath || "")
352
.replace(/^chapter\//, "")
353
.replace(/^series\//, "")
354
.trim()
355
.toLowerCase();
356
return /^[0-9a-z]{4,10}$/.test(id) ? id : "";
357
}
358
359
function redditJsonUrls(id) {
360
const path = "/r/HFY/comments/" + id + "/.json?raw_json=1";
361
return [
362
"https://www.reddit.com" + path,
363
"https://old.reddit.com" + path,
364
];
365
}
366
367
function looksLikeHtml(text) {
368
const body = String(text || "").trim();
369
if (!body) {
370
return false;
371
}
372
return /^\s*<(!DOCTYPE|html|body|head)\b/i.test(body);
373
}
374
375
function isLoginOrBlockPage(res, body) {
376
const status = res && res.status != null ? Number(res.status) : 0;
377
if (status === 401 || status === 403 || status === 429) {
378
return true;
379
}
380
const finalUrl = String((res && res.url) || "");
381
if (/[?&]reason=lor2\b/i.test(finalUrl) || /\/login\b/i.test(finalUrl)) {
382
return true;
383
}
384
const type = String(
385
(res && res.headers && typeof res.headers.get === "function" && res.headers.get("content-type")) || "",
386
).toLowerCase();
387
if (type.indexOf("text/html") !== -1 && !/json/i.test(type)) {
388
return true;
389
}
390
const text = String(body || "");
391
if (looksLikeHtml(text)) {
392
return true;
393
}
394
const lower = text.toLowerCase();
395
if (
396
lower.indexOf("reason=lor2") !== -1 ||
397
lower.indexOf("www.reddit.com/login") !== -1 ||
398
lower.indexOf("old.reddit.com/login") !== -1 ||
399
lower.indexOf("log in to reddit") !== -1 ||
400
(lower.indexOf("shreddit") !== -1 && lower.indexOf("<!doctype html") !== -1)
401
) {
402
return true;
403
}
404
return false;
405
}
406
407
function postFromRedditPayload(payload) {
408
if (!payload) {
409
return null;
410
}
411
const listing = Array.isArray(payload) ? payload[0] : payload;
412
const children =
413
listing && listing.data && Array.isArray(listing.data.children) ? listing.data.children : [];
414
const child = children.find((c) => !c.kind || c.kind === "t3") || children[0];
415
if (!child || !child.data) {
416
return null;
417
}
418
if (child.kind && child.kind !== "t3") {
419
return null;
420
}
421
return child.data;
422
}
423
424
function decodeRedditHtml(html) {
425
let text = String(html || "");
426
if (text.indexOf("<") !== -1 || text.indexOf("&") !== -1) {
427
text = text
428
.replace(/</g, "<")
429
.replace(/>/g, ">")
430
.replace(/"/g, '"')
431
.replace(/'/g, "'")
432
.replace(/&/g, "&");
433
}
434
return text;
435
}
436
437
async function tryRedditChapter(id) {
438
let lastReason = "geen antwoord";
439
const urls = redditJsonUrls(id);
440
for (let i = 0; i < urls.length; i++) {
441
const url = urls[i];
442
try {
443
const res = await fetchApi(url, { headers: { Accept: "application/json" } });
444
const body = typeof res.text === "function" ? await res.text() : "";
445
if (!res || res.ok === false || isLoginOrBlockPage(res, body)) {
446
const status = res && res.status != null ? res.status : "?";
447
lastReason = "HTTP " + status + (isLoginOrBlockPage(res, body) ? " (login of blokkade)" : "");
448
continue;
449
}
450
if (!body || looksLikeHtml(body)) {
451
lastReason = "geen JSON";
452
continue;
453
}
454
let payload;
455
try {
456
payload = JSON.parse(body);
457
} catch (err) {
458
lastReason = "ongeldige JSON";
459
continue;
460
}
461
const post = postFromRedditPayload(payload);
462
if (!post) {
463
lastReason = "geen post in de listing";
464
continue;
465
}
466
return { ok: true, post: post };
467
} catch (err) {
468
lastReason = err && err.message ? err.message : String(err);
469
}
470
}
471
return { ok: false, reason: lastReason };
472
}
473
474
async function tryArcticChapter(base, id) {
475
const url = String(base || "").replace(/\/+$/, "") + "/api/posts/ids?ids=" + encodeURIComponent(id) + "&md2html=true";
476
try {
282
477
const payload = await readJson(url, "hoofdstuk " + id);
283
478
const posts = payload.data || payload;
284
479
const post = Array.isArray(posts) ? posts[0] : posts;
285
480
if (!post) {
286
return "<p><em>Dit hoofdstuk is niet (meer) beschikbaar.</em></p>";
481
return { ok: false, reason: "leeg antwoord" };
287
482
}
288
const title = post.title ? "<h1>" + escapeHtml(post.title) + "</h1>" : "";
289
const by = post.author
290
? "<p><em>by u/" + escapeHtml(post.author) + "</em></p>"
291
: "";
292
const html = post.selftext_html
293
? sanitizeHtml(post.selftext_html)
294
: markdownToHtml(post.selftext || "");
295
if (!html) {
296
return title + by + "<p><em>Deze post heeft geen tekst (verwijderd of een link-post).</em></p>";
297
}
298
return title + by + html;
483
return { ok: true, post: post };
484
} catch (err) {
485
return { ok: false, reason: err && err.message ? err.message : String(err) };
486
}
487
}
488
489
function sourceFooter(label) {
490
return '<p class="hfy-source"><em>Bron: ' + escapeHtml(label) + "</em></p>";
491
}
492
493
function renderChapter(post, sourceLabel) {
494
if (!post) {
495
return "<p><em>Dit hoofdstuk is niet (meer) beschikbaar.</em></p>" + sourceFooter(sourceLabel);
496
}
497
const title = post.title ? "<h1>" + escapeHtml(post.title) + "</h1>" : "";
498
const by = post.author ? "<p><em>by u/" + escapeHtml(post.author) + "</em></p>" : "";
499
const rawHtml = post.selftext_html ? decodeRedditHtml(post.selftext_html) : "";
500
const html = rawHtml ? sanitizeHtml(rawHtml) : markdownToHtml(post.selftext || "");
501
if (!html) {
502
return (
503
title +
504
by +
505
"<p><em>Deze post heeft geen tekst (verwijderd of een link-post).</em></p>" +
506
sourceFooter(sourceLabel)
507
);
299
508
}
509
return title + by + html + sourceFooter(sourceLabel);
300
510
}
301
511
302
512
function escapeHtml(text) {
@@ -308,7 +518,7 @@ function escapeHtml(text) {
308
518
}
309
519
310
520
function sanitizeHtml(html) {
311
// Arctic Shift levert al HTML; we strippen scripts en on-event-attributen.
521
// Reddit en Arctic Shift leveren HTML; we strippen scripts en on-event-attributen.
312
522
return String(html)
313
523
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "")
314
524
.replace(/\son[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi, "");
@@ -5,8 +5,10 @@5
*5
*6
* De catalogus (titels, auteurs, hoofdstuklijsten) komt uit een statische6
* De catalogus (titels, auteurs, hoofdstuklijsten) komt uit een statische7
* JSON-index. De verhaaltekst zelf staat niet in die index: parseChapter7
* JSON-index. De verhaaltekst zelf staat niet in die index: parseChapter8
* haalt een hoofdstuk live op via de Arctic Shift-API (optioneel te8
* probeert eerst de echte Reddit-JSON (www.reddit.com/.../.json, daarna9
* overschrijven in de plugin-instellingen).9
* old.reddit.com) via fetchApi, zodat cookies uit de LNReader-WebView10
* meegaan na inloggen op reddit.com. Bij een fout, 403 of login-/blokpagina11
* valt de plugin terug op Arctic Shift.10
*12
*11
* Dit bestand is CommonJS, zoals de officiële gecompileerde plugins:13
* Dit bestand is CommonJS, zoals de officiële gecompileerde plugins:12
* require(...) uit de LNReader-allowlist, en `exports.default = instance`.14
* require(...) uit de LNReader-allowlist, en `exports.default = instance`.@@ -94,9 +96,12 @@ class HFYNovelsPlugin {94
constructor() {96
constructor() {95
this.id = "hfyNovels";97
this.id = "hfyNovels";96
this.name = "HFY Novels";98
this.name = "HFY Novels";97
this.version = "0.1.0";99
this.version = "0.2.0";98
this.site = "https://www.reddit.com/r/HFY/";100
this.site = "https://www.reddit.com/r/HFY/";99
this.icon = "icon.png";101
this.icon = "icon.png";102
// Geen webStorageUtilized: Reddit-login zit in cookies. LNReader's103
// fetchApi (native fetch) stuurt de WebView-cookies automatisch mee104
// voor hetzelfde domein; localStorage is daarvoor niet nodig.100
this.filters = {105
this.filters = {101
kind: {106
kind: {102
value: "all",107
value: "all",@@ -129,9 +134,19 @@ class HFYNovelsPlugin {129
label: "Git-revisie van de index (rev=)",134
label: "Git-revisie van de index (rev=)",130
type: "Text",135
type: "Text",131
},136
},137
chapterSource: {138
value: "auto",139
label: "Bron voor hoofdstuktekst",140
type: "Select",141
options: [142
{ label: "Automatisch (Reddit, anders Arctic Shift)", value: "auto" },143
{ label: "Alleen Reddit", value: "reddit" },144
{ label: "Alleen Arctic Shift", value: "arctic" },145
],146
},132
chapterSourceUrl: {147
chapterSourceUrl: {133
value: DEFAULT_CHAPTER_SOURCE,148
value: DEFAULT_CHAPTER_SOURCE,134
label: "Bron voor hoofdstuktekst (Arctic Shift)",149
label: "Arctic Shift-basis-URL (fallback)",135
type: "Text",150
type: "Text",136
},151
},137
};152
};@@ -166,6 +181,32 @@ class HFYNovelsPlugin {166
return String(setting("chapterSourceUrl", DEFAULT_CHAPTER_SOURCE)).replace(/\/+$/, "");181
return String(setting("chapterSourceUrl", DEFAULT_CHAPTER_SOURCE)).replace(/\/+$/, "");167
}182
}168
183
184
chapterMode() {185
const mode = String(setting("chapterSource", "auto") || "auto").toLowerCase();186
if (mode === "reddit" || mode === "arctic") {187
return mode;188
}189
return "auto";190
}191
192
/**193
* Maakt "Open in WebView" op een reeks of hoofdstuk tot een Reddit-URL,194
* zodat je daar kunt inloggen. Zonder deze functie zou LNReader195
* site+path plakken (bijv. /r/HFY/series/id), wat geen geldige Reddit-pagina is.196
* Het reeks-id is de oudste post (eerste deel).197
*/198
resolveUrl(path, isNovel) {199
const raw = String(path || "").trim();200
if (/^https?:\/\//i.test(raw)) {201
return raw;202
}203
const id = chapterIdFromPath(raw) || chapterIdFromPath(raw.replace(/^series\//, "chapter/"));204
if (id) {205
return "https://www.reddit.com/r/HFY/comments/" + id + "/";206
}207
return this.site;208
}209
169
matchesFilters(entry, filters) {210
matchesFilters(entry, filters) {170
const kind = filters && filters.kind ? filters.kind.value : "all";211
const kind = filters && filters.kind ? filters.kind.value : "all";171
const nsfw = filters && filters.nsfw ? filters.nsfw.value : "hide";212
const nsfw = filters && filters.nsfw ? filters.nsfw.value : "hide";@@ -266,37 +307,206 @@ class HFYNovelsPlugin {266
};307
};267
}308
}268
309
310
269
async parseChapter(chapterPath) {311
async parseChapter(chapterPath) {270
const id = String(chapterPath || "")312
const id = chapterIdFromPath(chapterPath);271
.replace(/^chapter\//, "")313
if (!id) {272
.trim()273
.toLowerCase();274
if (!/^[0-9a-z]{4,10}$/.test(id)) {275
throw new Error("HFY Novels: ongeldig hoofdstuk-id");314
throw new Error("HFY Novels: ongeldig hoofdstuk-id");276
}315
}277
const url =316
const mode = this.chapterMode();278
this.chapterSource() +317
let redditError = "";279
"/api/posts/ids?ids=" +318
if (mode !== "arctic") {280
encodeURIComponent(id) +319
const reddit = await tryRedditChapter(id);281
"&md2html=true";320
if (reddit.ok) {321
return renderChapter(reddit.post, "Reddit");322
}323
redditError = reddit.reason || "onbekende fout";324
if (mode === "reddit") {325
throw new Error(326
"HFY Novels: Reddit gaf geen hoofdstuk (" +327
redditError +328
"). Log in via Open in WebView op reddit.com en probeer het opnieuw.",329
);330
}331
}332
const arctic = await tryArcticChapter(this.chapterSource(), id);333
if (arctic.ok) {334
const suffix = mode === "arctic" ? "Arctic Shift" : "Arctic Shift (fallback)";335
return renderChapter(arctic.post, suffix);336
}337
if (redditError) {338
throw new Error(339
"HFY Novels: Reddit (" +340
redditError +341
") en Arctic Shift (" +342
(arctic.reason || "geen tekst") +343
") faalden allebei.",344
);345
}346
throw new Error("HFY Novels: kon hoofdstuk " + id + " niet laden (" + (arctic.reason || "geen tekst") + ")");347
}348
}349
350
function chapterIdFromPath(chapterPath) {351
const id = String(chapterPath || "")352
.replace(/^chapter\//, "")353
.replace(/^series\//, "")354
.trim()355
.toLowerCase();356
return /^[0-9a-z]{4,10}$/.test(id) ? id : "";357
}358
359
function redditJsonUrls(id) {360
const path = "/r/HFY/comments/" + id + "/.json?raw_json=1";361
return [362
"https://www.reddit.com" + path,363
"https://old.reddit.com" + path,364
];365
}366
367
function looksLikeHtml(text) {368
const body = String(text || "").trim();369
if (!body) {370
return false;371
}372
return /^\s*<(!DOCTYPE|html|body|head)\b/i.test(body);373
}374
375
function isLoginOrBlockPage(res, body) {376
const status = res && res.status != null ? Number(res.status) : 0;377
if (status === 401 || status === 403 || status === 429) {378
return true;379
}380
const finalUrl = String((res && res.url) || "");381
if (/[?&]reason=lor2\b/i.test(finalUrl) || /\/login\b/i.test(finalUrl)) {382
return true;383
}384
const type = String(385
(res && res.headers && typeof res.headers.get === "function" && res.headers.get("content-type")) || "",386
).toLowerCase();387
if (type.indexOf("text/html") !== -1 && !/json/i.test(type)) {388
return true;389
}390
const text = String(body || "");391
if (looksLikeHtml(text)) {392
return true;393
}394
const lower = text.toLowerCase();395
if (396
lower.indexOf("reason=lor2") !== -1 ||397
lower.indexOf("www.reddit.com/login") !== -1 ||398
lower.indexOf("old.reddit.com/login") !== -1 ||399
lower.indexOf("log in to reddit") !== -1 ||400
(lower.indexOf("shreddit") !== -1 && lower.indexOf("<!doctype html") !== -1)401
) {402
return true;403
}404
return false;405
}406
407
function postFromRedditPayload(payload) {408
if (!payload) {409
return null;410
}411
const listing = Array.isArray(payload) ? payload[0] : payload;412
const children =413
listing && listing.data && Array.isArray(listing.data.children) ? listing.data.children : [];414
const child = children.find((c) => !c.kind || c.kind === "t3") || children[0];415
if (!child || !child.data) {416
return null;417
}418
if (child.kind && child.kind !== "t3") {419
return null;420
}421
return child.data;422
}423
424
function decodeRedditHtml(html) {425
let text = String(html || "");426
if (text.indexOf("<") !== -1 || text.indexOf("&") !== -1) {427
text = text428
.replace(/</g, "<")429
.replace(/>/g, ">")430
.replace(/"/g, '"')431
.replace(/'/g, "'")432
.replace(/&/g, "&");433
}434
return text;435
}436
437
async function tryRedditChapter(id) {438
let lastReason = "geen antwoord";439
const urls = redditJsonUrls(id);440
for (let i = 0; i < urls.length; i++) {441
const url = urls[i];442
try {443
const res = await fetchApi(url, { headers: { Accept: "application/json" } });444
const body = typeof res.text === "function" ? await res.text() : "";445
if (!res || res.ok === false || isLoginOrBlockPage(res, body)) {446
const status = res && res.status != null ? res.status : "?";447
lastReason = "HTTP " + status + (isLoginOrBlockPage(res, body) ? " (login of blokkade)" : "");448
continue;449
}450
if (!body || looksLikeHtml(body)) {451
lastReason = "geen JSON";452
continue;453
}454
let payload;455
try {456
payload = JSON.parse(body);457
} catch (err) {458
lastReason = "ongeldige JSON";459
continue;460
}461
const post = postFromRedditPayload(payload);462
if (!post) {463
lastReason = "geen post in de listing";464
continue;465
}466
return { ok: true, post: post };467
} catch (err) {468
lastReason = err && err.message ? err.message : String(err);469
}470
}471
return { ok: false, reason: lastReason };472
}473
474
async function tryArcticChapter(base, id) {475
const url = String(base || "").replace(/\/+$/, "") + "/api/posts/ids?ids=" + encodeURIComponent(id) + "&md2html=true";476
try {282
const payload = await readJson(url, "hoofdstuk " + id);477
const payload = await readJson(url, "hoofdstuk " + id);283
const posts = payload.data || payload;478
const posts = payload.data || payload;284
const post = Array.isArray(posts) ? posts[0] : posts;479
const post = Array.isArray(posts) ? posts[0] : posts;285
if (!post) {480
if (!post) {286
return "<p><em>Dit hoofdstuk is niet (meer) beschikbaar.</em></p>";481
return { ok: false, reason: "leeg antwoord" };287
}482
}288
const title = post.title ? "<h1>" + escapeHtml(post.title) + "</h1>" : "";483
return { ok: true, post: post };289
const by = post.author484
} catch (err) {290
? "<p><em>by u/" + escapeHtml(post.author) + "</em></p>"485
return { ok: false, reason: err && err.message ? err.message : String(err) };291
: "";486
}292
const html = post.selftext_html487
}293
? sanitizeHtml(post.selftext_html)488
294
: markdownToHtml(post.selftext || "");489
function sourceFooter(label) {295
if (!html) {490
return '<p class="hfy-source"><em>Bron: ' + escapeHtml(label) + "</em></p>";296
return title + by + "<p><em>Deze post heeft geen tekst (verwijderd of een link-post).</em></p>";491
}297
}492
298
return title + by + html;493
function renderChapter(post, sourceLabel) {494
if (!post) {495
return "<p><em>Dit hoofdstuk is niet (meer) beschikbaar.</em></p>" + sourceFooter(sourceLabel);496
}497
const title = post.title ? "<h1>" + escapeHtml(post.title) + "</h1>" : "";498
const by = post.author ? "<p><em>by u/" + escapeHtml(post.author) + "</em></p>" : "";499
const rawHtml = post.selftext_html ? decodeRedditHtml(post.selftext_html) : "";500
const html = rawHtml ? sanitizeHtml(rawHtml) : markdownToHtml(post.selftext || "");501
if (!html) {502
return (503
title +504
by +505
"<p><em>Deze post heeft geen tekst (verwijderd of een link-post).</em></p>" +506
sourceFooter(sourceLabel)507
);299
}508
}509
return title + by + html + sourceFooter(sourceLabel);300
}510
}301
511
302
function escapeHtml(text) {512
function escapeHtml(text) {@@ -308,7 +518,7 @@ function escapeHtml(text) {308
}518
}309
519
310
function sanitizeHtml(html) {520
function sanitizeHtml(html) {311
// Arctic Shift levert al HTML; we strippen scripts en on-event-attributen.521
// Reddit en Arctic Shift leveren HTML; we strippen scripts en on-event-attributen.312
return String(html)522
return String(html)313
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "")523
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "")314
.replace(/\son[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi, "");524
.replace(/\son[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi, "");@@ -5,8 +5,8 @@
5
5
* Laadt de plugin zoals LNReader dat doet: custom require-allowlist,
6
6
* `new Function`, en daarna popularNovels / searchNovels / parseNovel /
7
7
* parseChapter. De index komt van een lokale HTTP-server (testdata of
8
* public/). parseChapter gebruikt een mock van Arctic Shift, plus
9
* optioneel een live verzoek als HFY_LIVE=1.
8
* public/). parseChapter probeert eerst een mock van Reddit-JSON en
9
* valt terug op Arctic Shift; optioneel een live verzoek als HFY_LIVE=1.
10
10
*/
11
11
12
12
const fs = require("fs");
@@ -32,13 +32,16 @@ function mimeFor(file, asImg) {
32
32
return "application/octet-stream";
33
33
}
34
34
35
function startServer(rootDir, chapterHandler) {
35
function startServer(rootDir, chapterHandler, redditHandler) {
36
36
return new Promise((resolve, reject) => {
37
37
const server = http.createServer((req, res) => {
38
38
const url = new URL(req.url, "http://127.0.0.1");
39
39
if (url.pathname.startsWith("/api/posts/ids")) {
40
40
return chapterHandler(url, res);
41
41
}
42
if (redditHandler && /\/r\/HFY\/comments\//i.test(url.pathname) && url.pathname.endsWith(".json")) {
43
return redditHandler(url, res, req);
44
}
42
45
// ?rev=master zoals BlueGit raw-URLs; voor het bestand negeren we de query.
43
46
let rel = decodeURIComponent(url.pathname).replace(/^\/+/, "");
44
47
const file = path.join(rootDir, rel);
@@ -66,6 +69,62 @@ function startServer(rootDir, chapterHandler) {
66
69
});
67
70
}
68
71
72
function redditListingFor(id) {
73
return [
74
{
75
kind: "Listing",
76
data: {
77
children: [
78
{
79
kind: "t3",
80
data: {
81
id,
82
title: "The Last Terran - Part 1",
83
author: "WriterOne",
84
selftext: "It begins.\n\n[Next](https://www.reddit.com/r/HFY/comments/aaa222/x/)",
85
selftext_html: "<div class=\"md\"><p>It begins.</p></div>",
86
permalink: "/r/HFY/comments/" + id + "/",
87
},
88
},
89
],
90
},
91
},
92
{ kind: "Listing", data: { children: [] } },
93
];
94
}
95
96
function loginHtml() {
97
return "<!DOCTYPE html><html><head><title>reddit.com: Log in</title></head><body>Log in to Reddit to continue. <a href=\"https://www.reddit.com/login\">log in</a></body></html>";
98
}
99
100
function blockHtml() {
101
return "<body class=theme-beta><div>Request blocked. reason=lor2</div></body>";
102
}
103
104
function defaultRedditHandler(mode) {
105
return function redditHandler(url, res) {
106
const m = url.pathname.match(/\/comments\/([0-9a-z]{4,10})\//i);
107
const id = m ? m[1].toLowerCase() : "unknown";
108
if (mode === "ok") {
109
res.writeHead(200, { "Content-Type": "application/json; charset=utf-8" });
110
res.end(JSON.stringify(redditListingFor(id)));
111
return;
112
}
113
if (mode === "403") {
114
res.writeHead(403, { "Content-Type": "text/html; charset=utf-8" });
115
res.end(blockHtml());
116
return;
117
}
118
if (mode === "login-html") {
119
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
120
res.end(loginHtml());
121
return;
122
}
123
res.writeHead(500, { "Content-Type": "text/plain" });
124
res.end("reddit mock error");
125
};
126
}
127
69
128
function defaultChapterHandler(url, res) {
70
129
const ids = url.searchParams.get("ids") || "";
71
130
const id = ids.split(",")[0];
@@ -85,8 +144,7 @@ function defaultChapterHandler(url, res) {
85
144
res.end(JSON.stringify(fixture));
86
145
}
87
146
88
async function fetchApi(url, init) {
89
const res = await fetch(url, init);
147
function wrapResponse(res) {
90
148
return {
91
149
ok: res.ok,
92
150
status: res.status,
@@ -102,7 +160,20 @@ async function fetchApi(url, init) {
102
160
};
103
161
}
104
162
105
function loadPlugin(storageMap) {
163
function makeFetchApi(origin) {
164
return async function fetchApi(url, init) {
165
let target = String(url);
166
// Stuur Reddit-JSON naar de lokale testhost, zodat we 200/403/login kunnen simuleren.
167
if (/^https?:\/\/(www\.|old\.)?reddit\.com\//i.test(target)) {
168
const parsed = new URL(target);
169
target = origin + parsed.pathname + parsed.search;
170
}
171
const res = await fetch(target, init);
172
return wrapResponse(res);
173
};
174
}
175
176
function loadPlugin(storageMap, fetchApi) {
106
177
const allow = {
107
178
"@libs/fetch": { fetchApi, fetchText: async (u, i) => (await fetchApi(u, i)).text() },
108
179
"@libs/filterInputs": { FilterTypes },
@@ -147,21 +218,36 @@ function assert(cond, msg) {
147
218
148
219
async function main() {
149
220
const fixtureRoot = path.join(ROOT, "testdata", "index-fixture");
150
const { server, url } = await startServer(fixtureRoot, defaultChapterHandler);
221
const redditState = { mode: "ok", redditHits: 0, arcticHits: 0 };
222
const chapterHandler = (reqUrl, res) => {
223
redditState.arcticHits += 1;
224
return defaultChapterHandler(reqUrl, res);
225
};
226
const redditHandler = (reqUrl, res) => {
227
redditState.redditHits += 1;
228
return defaultRedditHandler(redditState.mode)(reqUrl, res);
229
};
230
const { server, url } = await startServer(fixtureRoot, chapterHandler, redditHandler);
231
const fetchApi = makeFetchApi(url);
151
232
const failures = [];
152
233
try {
153
234
const storageMap = {
154
235
indexBaseUrl: url,
155
236
indexRev: "", // geen ?rev= nodig op de testhost
156
237
chapterSourceUrl: url,
238
chapterSource: "auto",
157
239
};
158
const plugin = loadPlugin(storageMap);
240
const plugin = loadPlugin(storageMap, fetchApi);
159
241
160
242
assert(plugin.id === "hfyNovels", "id");
161
243
assert(plugin.name === "HFY Novels", "name");
162
assert(plugin.version === "0.1.0", "version");
244
assert(plugin.version === "0.2.0", "version");
163
245
assert(plugin.site === "https://www.reddit.com/r/HFY/", "site");
164
246
assert(plugin.pluginSettings && plugin.pluginSettings.indexBaseUrl, "pluginSettings");
247
assert(plugin.pluginSettings.chapterSource && plugin.pluginSettings.chapterSource.type === "Select", "bron-instelling is Select");
248
assert(typeof plugin.resolveUrl === "function", "resolveUrl");
249
assert(plugin.resolveUrl("chapter/aaa111") === "https://www.reddit.com/r/HFY/comments/aaa111/", "resolveUrl hoofdstuk");
250
assert(plugin.resolveUrl("series/aaa111", true) === "https://www.reddit.com/r/HFY/comments/aaa111/", "resolveUrl reeks");
165
251
166
252
const popular = await plugin.popularNovels(1, { showLatestNovels: false, filters: {} });
167
253
assert(Array.isArray(popular) && popular.length >= 1, "popularNovels geeft items");
@@ -213,10 +299,55 @@ async function main() {
213
299
assert(novel.chapters[0].chapterNumber === 1, "hoofdstuknummer");
214
300
assert(novel.status === NovelStatus.Ongoing || novel.status === NovelStatus.OnHiatus || novel.status === NovelStatus.Unknown, "status enum");
215
301
302
redditState.mode = "ok";
303
redditState.redditHits = 0;
304
redditState.arcticHits = 0;
216
305
const html = await plugin.parseChapter("chapter/aaa111");
217
306
assert(/It begins/.test(html), "parseChapter bevat tekst");
218
307
assert(/<h1>/.test(html), "parseChapter heeft titel");
219
308
assert(!/<script/i.test(html), "geen script-tags");
309
assert(/Bron: Reddit/.test(html), "Reddit-ok toont Bron: Reddit");
310
assert(redditState.arcticHits === 0, "bij Reddit-ok geen Arctic Shift-aanroep");
311
assert(redditState.redditHits >= 1, "Reddit-JSON is aangeroepen");
312
313
redditState.mode = "403";
314
redditState.redditHits = 0;
315
redditState.arcticHits = 0;
316
const html403 = await plugin.parseChapter("chapter/aaa111");
317
assert(/It begins/.test(html403), "403 valt terug op Arctic Shift");
318
assert(/Bron: Arctic Shift \(fallback\)/.test(html403), "403 toont fallback-bron");
319
assert(redditState.arcticHits >= 1, "403 roept Arctic Shift aan");
320
assert(redditState.redditHits >= 1, "403 probeert eerst Reddit");
321
322
redditState.mode = "login-html";
323
redditState.redditHits = 0;
324
redditState.arcticHits = 0;
325
const htmlLogin = await plugin.parseChapter("chapter/aaa111");
326
assert(/It begins/.test(htmlLogin), "login-HTML valt terug op Arctic Shift");
327
assert(/Bron: Arctic Shift \(fallback\)/.test(htmlLogin), "login-HTML toont fallback-bron");
328
assert(redditState.arcticHits >= 1, "login-HTML roept Arctic Shift aan");
329
330
storageMap.chapterSource = "reddit";
331
redditState.mode = "403";
332
redditState.arcticHits = 0;
333
let redditOnlyThrew = false;
334
try {
335
await plugin.parseChapter("chapter/aaa111");
336
} catch (err) {
337
redditOnlyThrew = /Reddit/.test(String(err && err.message)) && /WebView/.test(String(err && err.message));
338
}
339
assert(redditOnlyThrew, "modus Reddit faalt zichtbaar bij 403");
340
assert(redditState.arcticHits === 0, "modus Reddit gebruikt geen fallback");
341
342
storageMap.chapterSource = "arctic";
343
redditState.mode = "ok";
344
redditState.redditHits = 0;
345
redditState.arcticHits = 0;
346
const htmlArctic = await plugin.parseChapter("chapter/aaa111");
347
assert(/Bron: Arctic Shift</.test(htmlArctic) && !/fallback/.test(htmlArctic), "modus Arctic Shift slaat Reddit over");
348
assert(redditState.redditHits === 0, "modus Arctic Shift roept Reddit niet aan");
349
assert(redditState.arcticHits >= 1, "modus Arctic Shift gebruikt Arctic Shift");
350
storageMap.chapterSource = "auto";
220
351
221
352
let threw = false;
222
353
try {
@@ -228,7 +359,9 @@ async function main() {
228
359
229
360
// Manifest-vorm controleren.
230
361
const manifest = JSON.parse(fs.readFileSync(path.join(ROOT, ".dist", "plugins.json"), "utf8"));
362
const manifestMin = JSON.parse(fs.readFileSync(path.join(ROOT, ".dist", "plugins.min.json"), "utf8"));
231
363
assert(Array.isArray(manifest) && manifest.length === 1, "plugins.json is een array");
364
assert(manifestMin[0].version === manifest[0].version, "plugins.min.json heeft dezelfde versie");
232
365
const entry = manifest[0];
233
366
for (const key of ["id", "name", "site", "lang", "version", "url", "iconUrl"]) {
234
367
assert(entry[key], "manifest mist " + key);
@@ -248,7 +381,7 @@ async function main() {
248
381
indexRev: "",
249
382
chapterSourceUrl: "https://arctic-shift.photon-reddit.com",
250
383
};
251
const livePlugin = loadPlugin(liveStorage);
384
const livePlugin = loadPlugin(liveStorage, async (reqUrl, init) => wrapResponse(await fetch(reqUrl, init)));
252
385
// Een recent, echt post-id uit de Arctic Shift-probe: willekeurig een
253
386
// bekend kort id heeft geen zin. We vragen een recente HFY-post op.
254
387
const listing = await fetch(
@@ -262,7 +395,8 @@ async function main() {
262
395
const liveId = body.data[0].id;
263
396
const liveHtml = await livePlugin.parseChapter("chapter/" + liveId);
264
397
assert(liveHtml.length > 20, "live parseChapter gaf inhoud");
265
console.log("✔️ live parseChapter via Arctic Shift (" + liveId + ", " + liveHtml.length + " tekens)");
398
const liveSource = /Bron: ([^<]+)/.exec(liveHtml);
399
console.log("✔️ live parseChapter (" + liveId + ", " + liveHtml.length + " tekens, " + ((liveSource && liveSource[1]) || "bron onbekend") + ")");
266
400
}
267
401
} catch (err) {
268
402
failures.push(err);
@@ -5,8 +5,8 @@5
* Laadt de plugin zoals LNReader dat doet: custom require-allowlist,5
* Laadt de plugin zoals LNReader dat doet: custom require-allowlist,6
* `new Function`, en daarna popularNovels / searchNovels / parseNovel /6
* `new Function`, en daarna popularNovels / searchNovels / parseNovel /7
* parseChapter. De index komt van een lokale HTTP-server (testdata of7
* parseChapter. De index komt van een lokale HTTP-server (testdata of8
* public/). parseChapter gebruikt een mock van Arctic Shift, plus8
* public/). parseChapter probeert eerst een mock van Reddit-JSON en9
* optioneel een live verzoek als HFY_LIVE=1.9
* valt terug op Arctic Shift; optioneel een live verzoek als HFY_LIVE=1.10
*/10
*/11
11
12
const fs = require("fs");12
const fs = require("fs");@@ -32,13 +32,16 @@ function mimeFor(file, asImg) {32
return "application/octet-stream";32
return "application/octet-stream";33
}33
}34
34
35
function startServer(rootDir, chapterHandler) {35
function startServer(rootDir, chapterHandler, redditHandler) {36
return new Promise((resolve, reject) => {36
return new Promise((resolve, reject) => {37
const server = http.createServer((req, res) => {37
const server = http.createServer((req, res) => {38
const url = new URL(req.url, "http://127.0.0.1");38
const url = new URL(req.url, "http://127.0.0.1");39
if (url.pathname.startsWith("/api/posts/ids")) {39
if (url.pathname.startsWith("/api/posts/ids")) {40
return chapterHandler(url, res);40
return chapterHandler(url, res);41
}41
}42
if (redditHandler && /\/r\/HFY\/comments\//i.test(url.pathname) && url.pathname.endsWith(".json")) {43
return redditHandler(url, res, req);44
}42
// ?rev=master zoals BlueGit raw-URLs; voor het bestand negeren we de query.45
// ?rev=master zoals BlueGit raw-URLs; voor het bestand negeren we de query.43
let rel = decodeURIComponent(url.pathname).replace(/^\/+/, "");46
let rel = decodeURIComponent(url.pathname).replace(/^\/+/, "");44
const file = path.join(rootDir, rel);47
const file = path.join(rootDir, rel);@@ -66,6 +69,62 @@ function startServer(rootDir, chapterHandler) {66
});69
});67
}70
}68
71
72
function redditListingFor(id) {73
return [74
{75
kind: "Listing",76
data: {77
children: [78
{79
kind: "t3",80
data: {81
id,82
title: "The Last Terran - Part 1",83
author: "WriterOne",84
selftext: "It begins.\n\n[Next](https://www.reddit.com/r/HFY/comments/aaa222/x/)",85
selftext_html: "<div class=\"md\"><p>It begins.</p></div>",86
permalink: "/r/HFY/comments/" + id + "/",87
},88
},89
],90
},91
},92
{ kind: "Listing", data: { children: [] } },93
];94
}95
96
function loginHtml() {97
return "<!DOCTYPE html><html><head><title>reddit.com: Log in</title></head><body>Log in to Reddit to continue. <a href=\"https://www.reddit.com/login\">log in</a></body></html>";98
}99
100
function blockHtml() {101
return "<body class=theme-beta><div>Request blocked. reason=lor2</div></body>";102
}103
104
function defaultRedditHandler(mode) {105
return function redditHandler(url, res) {106
const m = url.pathname.match(/\/comments\/([0-9a-z]{4,10})\//i);107
const id = m ? m[1].toLowerCase() : "unknown";108
if (mode === "ok") {109
res.writeHead(200, { "Content-Type": "application/json; charset=utf-8" });110
res.end(JSON.stringify(redditListingFor(id)));111
return;112
}113
if (mode === "403") {114
res.writeHead(403, { "Content-Type": "text/html; charset=utf-8" });115
res.end(blockHtml());116
return;117
}118
if (mode === "login-html") {119
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });120
res.end(loginHtml());121
return;122
}123
res.writeHead(500, { "Content-Type": "text/plain" });124
res.end("reddit mock error");125
};126
}127
69
function defaultChapterHandler(url, res) {128
function defaultChapterHandler(url, res) {70
const ids = url.searchParams.get("ids") || "";129
const ids = url.searchParams.get("ids") || "";71
const id = ids.split(",")[0];130
const id = ids.split(",")[0];@@ -85,8 +144,7 @@ function defaultChapterHandler(url, res) {85
res.end(JSON.stringify(fixture));144
res.end(JSON.stringify(fixture));86
}145
}87
146
88
async function fetchApi(url, init) {147
function wrapResponse(res) {89
const res = await fetch(url, init);90
return {148
return {91
ok: res.ok,149
ok: res.ok,92
status: res.status,150
status: res.status,@@ -102,7 +160,20 @@ async function fetchApi(url, init) {102
};160
};103
}161
}104
162
105
function loadPlugin(storageMap) {163
function makeFetchApi(origin) {164
return async function fetchApi(url, init) {165
let target = String(url);166
// Stuur Reddit-JSON naar de lokale testhost, zodat we 200/403/login kunnen simuleren.167
if (/^https?:\/\/(www\.|old\.)?reddit\.com\//i.test(target)) {168
const parsed = new URL(target);169
target = origin + parsed.pathname + parsed.search;170
}171
const res = await fetch(target, init);172
return wrapResponse(res);173
};174
}175
176
function loadPlugin(storageMap, fetchApi) {106
const allow = {177
const allow = {107
"@libs/fetch": { fetchApi, fetchText: async (u, i) => (await fetchApi(u, i)).text() },178
"@libs/fetch": { fetchApi, fetchText: async (u, i) => (await fetchApi(u, i)).text() },108
"@libs/filterInputs": { FilterTypes },179
"@libs/filterInputs": { FilterTypes },@@ -147,21 +218,36 @@ function assert(cond, msg) {147
218
148
async function main() {219
async function main() {149
const fixtureRoot = path.join(ROOT, "testdata", "index-fixture");220
const fixtureRoot = path.join(ROOT, "testdata", "index-fixture");150
const { server, url } = await startServer(fixtureRoot, defaultChapterHandler);221
const redditState = { mode: "ok", redditHits: 0, arcticHits: 0 };222
const chapterHandler = (reqUrl, res) => {223
redditState.arcticHits += 1;224
return defaultChapterHandler(reqUrl, res);225
};226
const redditHandler = (reqUrl, res) => {227
redditState.redditHits += 1;228
return defaultRedditHandler(redditState.mode)(reqUrl, res);229
};230
const { server, url } = await startServer(fixtureRoot, chapterHandler, redditHandler);231
const fetchApi = makeFetchApi(url);151
const failures = [];232
const failures = [];152
try {233
try {153
const storageMap = {234
const storageMap = {154
indexBaseUrl: url,235
indexBaseUrl: url,155
indexRev: "", // geen ?rev= nodig op de testhost236
indexRev: "", // geen ?rev= nodig op de testhost156
chapterSourceUrl: url,237
chapterSourceUrl: url,238
chapterSource: "auto",157
};239
};158
const plugin = loadPlugin(storageMap);240
const plugin = loadPlugin(storageMap, fetchApi);159
241
160
assert(plugin.id === "hfyNovels", "id");242
assert(plugin.id === "hfyNovels", "id");161
assert(plugin.name === "HFY Novels", "name");243
assert(plugin.name === "HFY Novels", "name");162
assert(plugin.version === "0.1.0", "version");244
assert(plugin.version === "0.2.0", "version");163
assert(plugin.site === "https://www.reddit.com/r/HFY/", "site");245
assert(plugin.site === "https://www.reddit.com/r/HFY/", "site");164
assert(plugin.pluginSettings && plugin.pluginSettings.indexBaseUrl, "pluginSettings");246
assert(plugin.pluginSettings && plugin.pluginSettings.indexBaseUrl, "pluginSettings");247
assert(plugin.pluginSettings.chapterSource && plugin.pluginSettings.chapterSource.type === "Select", "bron-instelling is Select");248
assert(typeof plugin.resolveUrl === "function", "resolveUrl");249
assert(plugin.resolveUrl("chapter/aaa111") === "https://www.reddit.com/r/HFY/comments/aaa111/", "resolveUrl hoofdstuk");250
assert(plugin.resolveUrl("series/aaa111", true) === "https://www.reddit.com/r/HFY/comments/aaa111/", "resolveUrl reeks");165
251
166
const popular = await plugin.popularNovels(1, { showLatestNovels: false, filters: {} });252
const popular = await plugin.popularNovels(1, { showLatestNovels: false, filters: {} });167
assert(Array.isArray(popular) && popular.length >= 1, "popularNovels geeft items");253
assert(Array.isArray(popular) && popular.length >= 1, "popularNovels geeft items");@@ -213,10 +299,55 @@ async function main() {213
assert(novel.chapters[0].chapterNumber === 1, "hoofdstuknummer");299
assert(novel.chapters[0].chapterNumber === 1, "hoofdstuknummer");214
assert(novel.status === NovelStatus.Ongoing || novel.status === NovelStatus.OnHiatus || novel.status === NovelStatus.Unknown, "status enum");300
assert(novel.status === NovelStatus.Ongoing || novel.status === NovelStatus.OnHiatus || novel.status === NovelStatus.Unknown, "status enum");215
301
302
redditState.mode = "ok";303
redditState.redditHits = 0;304
redditState.arcticHits = 0;216
const html = await plugin.parseChapter("chapter/aaa111");305
const html = await plugin.parseChapter("chapter/aaa111");217
assert(/It begins/.test(html), "parseChapter bevat tekst");306
assert(/It begins/.test(html), "parseChapter bevat tekst");218
assert(/<h1>/.test(html), "parseChapter heeft titel");307
assert(/<h1>/.test(html), "parseChapter heeft titel");219
assert(!/<script/i.test(html), "geen script-tags");308
assert(!/<script/i.test(html), "geen script-tags");309
assert(/Bron: Reddit/.test(html), "Reddit-ok toont Bron: Reddit");310
assert(redditState.arcticHits === 0, "bij Reddit-ok geen Arctic Shift-aanroep");311
assert(redditState.redditHits >= 1, "Reddit-JSON is aangeroepen");312
313
redditState.mode = "403";314
redditState.redditHits = 0;315
redditState.arcticHits = 0;316
const html403 = await plugin.parseChapter("chapter/aaa111");317
assert(/It begins/.test(html403), "403 valt terug op Arctic Shift");318
assert(/Bron: Arctic Shift \(fallback\)/.test(html403), "403 toont fallback-bron");319
assert(redditState.arcticHits >= 1, "403 roept Arctic Shift aan");320
assert(redditState.redditHits >= 1, "403 probeert eerst Reddit");321
322
redditState.mode = "login-html";323
redditState.redditHits = 0;324
redditState.arcticHits = 0;325
const htmlLogin = await plugin.parseChapter("chapter/aaa111");326
assert(/It begins/.test(htmlLogin), "login-HTML valt terug op Arctic Shift");327
assert(/Bron: Arctic Shift \(fallback\)/.test(htmlLogin), "login-HTML toont fallback-bron");328
assert(redditState.arcticHits >= 1, "login-HTML roept Arctic Shift aan");329
330
storageMap.chapterSource = "reddit";331
redditState.mode = "403";332
redditState.arcticHits = 0;333
let redditOnlyThrew = false;334
try {335
await plugin.parseChapter("chapter/aaa111");336
} catch (err) {337
redditOnlyThrew = /Reddit/.test(String(err && err.message)) && /WebView/.test(String(err && err.message));338
}339
assert(redditOnlyThrew, "modus Reddit faalt zichtbaar bij 403");340
assert(redditState.arcticHits === 0, "modus Reddit gebruikt geen fallback");341
342
storageMap.chapterSource = "arctic";343
redditState.mode = "ok";344
redditState.redditHits = 0;345
redditState.arcticHits = 0;346
const htmlArctic = await plugin.parseChapter("chapter/aaa111");347
assert(/Bron: Arctic Shift</.test(htmlArctic) && !/fallback/.test(htmlArctic), "modus Arctic Shift slaat Reddit over");348
assert(redditState.redditHits === 0, "modus Arctic Shift roept Reddit niet aan");349
assert(redditState.arcticHits >= 1, "modus Arctic Shift gebruikt Arctic Shift");350
storageMap.chapterSource = "auto";220
351
221
let threw = false;352
let threw = false;222
try {353
try {@@ -228,7 +359,9 @@ async function main() {228
359
229
// Manifest-vorm controleren.360
// Manifest-vorm controleren.230
const manifest = JSON.parse(fs.readFileSync(path.join(ROOT, ".dist", "plugins.json"), "utf8"));361
const manifest = JSON.parse(fs.readFileSync(path.join(ROOT, ".dist", "plugins.json"), "utf8"));362
const manifestMin = JSON.parse(fs.readFileSync(path.join(ROOT, ".dist", "plugins.min.json"), "utf8"));231
assert(Array.isArray(manifest) && manifest.length === 1, "plugins.json is een array");363
assert(Array.isArray(manifest) && manifest.length === 1, "plugins.json is een array");364
assert(manifestMin[0].version === manifest[0].version, "plugins.min.json heeft dezelfde versie");232
const entry = manifest[0];365
const entry = manifest[0];233
for (const key of ["id", "name", "site", "lang", "version", "url", "iconUrl"]) {366
for (const key of ["id", "name", "site", "lang", "version", "url", "iconUrl"]) {234
assert(entry[key], "manifest mist " + key);367
assert(entry[key], "manifest mist " + key);@@ -248,7 +381,7 @@ async function main() {248
indexRev: "",381
indexRev: "",249
chapterSourceUrl: "https://arctic-shift.photon-reddit.com",382
chapterSourceUrl: "https://arctic-shift.photon-reddit.com",250
};383
};251
const livePlugin = loadPlugin(liveStorage);384
const livePlugin = loadPlugin(liveStorage, async (reqUrl, init) => wrapResponse(await fetch(reqUrl, init)));252
// Een recent, echt post-id uit de Arctic Shift-probe: willekeurig een385
// Een recent, echt post-id uit de Arctic Shift-probe: willekeurig een253
// bekend kort id heeft geen zin. We vragen een recente HFY-post op.386
// bekend kort id heeft geen zin. We vragen een recente HFY-post op.254
const listing = await fetch(387
const listing = await fetch(@@ -262,7 +395,8 @@ async function main() {262
const liveId = body.data[0].id;395
const liveId = body.data[0].id;263
const liveHtml = await livePlugin.parseChapter("chapter/" + liveId);396
const liveHtml = await livePlugin.parseChapter("chapter/" + liveId);264
assert(liveHtml.length > 20, "live parseChapter gaf inhoud");397
assert(liveHtml.length > 20, "live parseChapter gaf inhoud");265
console.log("✔️ live parseChapter via Arctic Shift (" + liveId + ", " + liveHtml.length + " tekens)");398
const liveSource = /Bron: ([^<]+)/.exec(liveHtml);399
console.log("✔️ live parseChapter (" + liveId + ", " + liveHtml.length + " tekens, " + ((liveSource && liveSource[1]) || "bron onbekend") + ")");266
}400
}267
} catch (err) {401
} catch (err) {268
failures.push(err);402
failures.push(err);