From 679724fc56b617817ec9c156ff082a2ebcf8d36c Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Wed, 18 Oct 2017 21:29:29 +0100 Subject: [PATCH] Use last link on page to reduce need for hardcoding --- src/excmds_content.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/excmds_content.ts b/src/excmds_content.ts index 6ea50155..17e13295 100644 --- a/src/excmds_content.ts +++ b/src/excmds_content.ts @@ -51,17 +51,18 @@ const commands = new Map([ }, function clicknext(dir = "next"){ let linkarray = Array.from(getlinks()) - // The desired one let regarray = [/\bnext|^>$|^(>>|»)$|^(>|»)|(>|»)$|\bmore\b/i, /\bprev\b|\bprevious\b|^<$|^(<<|«)$|^(<|«)|(<|«)$/i] - // RPS is hardcoded because it never worked in Vimperator and it always annoyed me regarray = window.location.href.match(/rockpapershotgun/) ? [/newer/i,/older/i] : regarray - let nextreg = (dir == "next") ? regarray[0] : regarray[1] // Might need to add more cases to this as we look at more sites let nextlinks = linkarray.filter((link) => (link.innerText.match(nextreg) || link.rel.match(nextreg))) - window.location.href = nextlinks[0].href + + // Use the last link that matches because next/prev buttons tend to be at the end of the page + // whereas lots of blogs have "VIEW MORE" etc. plastered all over their pages. + // Stops us from having to hardcode in RPS and reddit, for example. + window.location.href = nextlinks.slice(-1)[0].href } ].map((command):any => [command.name, command]))