feat(userscript): refresh kagane latest chapters through its API

This commit is contained in:
2026-08-03 17:12:22 +07:00
parent a5c5e11c21
commit 076e8bb5d8
+15 -8
View File
@@ -919,10 +919,11 @@
); );
} }
// Everything else is only learned by fetching a series page. Same-origin // Everything else is only learned by fetching a series page — or, where the
// only: these requests carry the session that gets us past the site's bot // site offers one, its JSON API. Same-origin only: these requests carry the
// checks, which a request to the other site (or from a server) would not. // session that gets us past the site's bot checks, which a request to the
// One series per navigation keeps it indistinguishable from browsing. // other site (or from a server) would not. A few series per navigation keeps
// it indistinguishable from browsing.
async function backgroundRefreshLatest() { async function backgroundRefreshLatest() {
const site = currentSite(); const site = currentSite();
if (!site) return; if (!site) return;
@@ -937,15 +938,21 @@
.slice(0, LATEST_CHECK_BATCH); .slice(0, LATEST_CHECK_BATCH);
if (due.length === 0) return; if (due.length === 0) return;
const adapter = adapterFor(site);
for (const bm of due) { for (const bm of due) {
// Recorded even when the fetch fails, so a broken series is retried on // Recorded even when the fetch fails, so a broken series is retried on
// the next throttle window rather than on every single page load. // the next throttle window rather than on every single page load.
checked[bm.key] = Date.now(); checked[bm.key] = Date.now();
try { try {
const res = await fetch(bm.series_url, { credentials: "same-origin" }); let latest;
if (!res.ok) continue; if (adapter && adapter.latestChapterFromApi) {
const html = await res.text(); latest = await adapter.latestChapterFromApi(bm.series_id);
const latest = computeLatestChapter(bm.site, anchorsFromHTML(html), bm.series_id); } else {
const res = await fetch(bm.series_url, { credentials: "same-origin" });
if (!res.ok) continue;
const html = await res.text();
latest = computeLatestChapter(bm.site, anchorsFromHTML(html), bm.series_id);
}
await applyLatestChapterIfChanged(state.byKey[bm.key] || bm, latest); await applyLatestChapterIfChanged(state.byKey[bm.key] || bm, latest);
} catch (e) { } catch (e) {
/* offline or blocked — try again after the throttle window */ /* offline or blocked — try again after the throttle window */