refactor(userscript): thread seriesId through latest-chapter scan
This commit is contained in:
@@ -311,9 +311,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Highest chapter the site lists, or null when the markup yields nothing.
|
// Highest chapter the site lists, or null when the markup yields nothing.
|
||||||
function computeLatestChapter(site, anchors) {
|
// seriesId is only consulted by adapters whose pages carry other series'
|
||||||
|
// chapter links; the rest ignore it.
|
||||||
|
function computeLatestChapter(site, anchors, seriesId) {
|
||||||
const a = adapterFor(site);
|
const a = adapterFor(site);
|
||||||
return a ? a.latestChapterFromAnchors(anchors) : null;
|
return a ? a.latestChapterFromAnchors(anchors, seriesId) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function currentSite() {
|
function currentSite() {
|
||||||
@@ -834,7 +836,7 @@
|
|||||||
if (!existing) return;
|
if (!existing) return;
|
||||||
applyLatestChapterIfChanged(
|
applyLatestChapterIfChanged(
|
||||||
existing,
|
existing,
|
||||||
computeLatestChapter(p.site, anchorsFromDocument(document))
|
computeLatestChapter(p.site, anchorsFromDocument(document), p.seriesId)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,7 +866,7 @@
|
|||||||
const res = await fetch(bm.series_url, { credentials: "same-origin" });
|
const res = await fetch(bm.series_url, { credentials: "same-origin" });
|
||||||
if (!res.ok) continue;
|
if (!res.ok) continue;
|
||||||
const html = await res.text();
|
const html = await res.text();
|
||||||
const latest = computeLatestChapter(bm.site, anchorsFromHTML(html));
|
const 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 */
|
||||||
|
|||||||
@@ -264,6 +264,16 @@ test("comix latest returns null when no chapter links are present", () => {
|
|||||||
assert.equal(comix.latestChapterFromAnchors(anchorsFromHTML("<a href='/browse'>x</a>"), "n8we"), null);
|
assert.equal(comix.latestChapterFromAnchors(anchorsFromHTML("<a href='/browse'>x</a>"), "n8we"), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("asura and demonic ignore the seriesId argument", () => {
|
||||||
|
const asuraAnchors = anchorsFromHTML(
|
||||||
|
`<a href="/comics/x-aabbccdd/chapter/12"><span>Chapter 12</span></a>`
|
||||||
|
);
|
||||||
|
assert.deepEqual(asura.latestChapterFromAnchors(asuraAnchors, "ignored"), {
|
||||||
|
num: 12,
|
||||||
|
label: "Chapter 12",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// Shared helpers
|
// Shared helpers
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user