From 925dcc6861dac9372b239652b335a61fac406a60 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Wed, 6 May 2015 00:58:52 +0200 Subject: [PATCH] Detect "Next Chapter" links better --- lib/worm-scraper.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/worm-scraper.js b/lib/worm-scraper.js index da21d48..fa2d224 100644 --- a/lib/worm-scraper.js +++ b/lib/worm-scraper.js @@ -117,6 +117,15 @@ function cleanContentEl(el) { } function getNextChapterUrl(rawChapterDoc) { - const nextEl = rawChapterDoc.querySelector("a[title=\"Next Chapter\"]"); - return nextEl && nextEl.href; + // a[title="Next Chapter"] doesn't always work (e.g. https://parahumans.wordpress.com/2011/09/27/shell-4-2/) + // So instead search for the first within the main content area starting with "Next". + + const aEls = rawChapterDoc.querySelectorAll(".entry-content a"); + for (let i = 0; i < aEls.length; ++i) { + if (aEls[i].textContent.startsWith("Next")) { + return aEls[i].href; + } + } + + return null; }