From 076e8bb5d82bfc660cf8dd86c85c7461e7a46674 Mon Sep 17 00:00:00 2001 From: Sulthan Zaki Date: Mon, 3 Aug 2026 17:12:22 +0700 Subject: [PATCH] feat(userscript): refresh kagane latest chapters through its API --- userscript/manga-bookmark.user.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/userscript/manga-bookmark.user.js b/userscript/manga-bookmark.user.js index 027f44e..28caa27 100644 --- a/userscript/manga-bookmark.user.js +++ b/userscript/manga-bookmark.user.js @@ -919,10 +919,11 @@ ); } - // Everything else is only learned by fetching a series page. Same-origin - // only: these requests carry the session that gets us past the site's bot - // checks, which a request to the other site (or from a server) would not. - // One series per navigation keeps it indistinguishable from browsing. + // Everything else is only learned by fetching a series page — or, where the + // site offers one, its JSON API. Same-origin only: these requests carry the + // session that gets us past the site's bot checks, which a request to the + // other site (or from a server) would not. A few series per navigation keeps + // it indistinguishable from browsing. async function backgroundRefreshLatest() { const site = currentSite(); if (!site) return; @@ -937,15 +938,21 @@ .slice(0, LATEST_CHECK_BATCH); if (due.length === 0) return; + const adapter = adapterFor(site); for (const bm of due) { // Recorded even when the fetch fails, so a broken series is retried on // the next throttle window rather than on every single page load. checked[bm.key] = Date.now(); try { - const res = await fetch(bm.series_url, { credentials: "same-origin" }); - if (!res.ok) continue; - const html = await res.text(); - const latest = computeLatestChapter(bm.site, anchorsFromHTML(html), bm.series_id); + let latest; + if (adapter && adapter.latestChapterFromApi) { + latest = await adapter.latestChapterFromApi(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); } catch (e) { /* offline or blocked — try again after the throttle window */