Detect "Next Chapter" links better

This commit is contained in:
Domenic Denicola 2015-05-06 00:58:52 +02:00
commit 925dcc6861

View file

@ -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 <a> 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;
}