Skip to content

Commit

Permalink
翻页快捷键支持根据目标链接地址去重 (brookhong#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
amzyang authored and brookhong committed Jan 20, 2020
1 parent 77f21db commit 325b7ee
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions content_scripts/content_scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function walkPageUrl(step) {
}

function previousPage() {
var prevLinks = getClickableElements("[rel=prev]", runtime.conf.prevLinkRegex);
var prevLinks = uniqueLinks(getClickableElements("[rel=prev]", runtime.conf.prevLinkRegex));
if (prevLinks.length) {
clickOn(prevLinks);
return true;
Expand All @@ -207,7 +207,7 @@ function previousPage() {
}

function nextPage() {
var nextLinks = getClickableElements("[rel=next]", runtime.conf.nextLinkRegex);
var nextLinks = uniqueLinks(getClickableElements("[rel=next]", runtime.conf.nextLinkRegex));
if (nextLinks.length) {
clickOn(nextLinks);
return true;
Expand All @@ -216,6 +216,17 @@ function nextPage() {
}
}

function uniqueLinks(links) {
let unique = {};
links.forEach(function(link) {
let href = link.getAttribute('href');
if (!unique[href]) {
unique[href] = link;
}
});
return Object.values(unique);
}

function searchSelectedWith(se, onlyThisSite, interactive, alias) {
Clipboard.read(function(response) {
var query = window.getSelection().toString() || response.data;
Expand Down

0 comments on commit 325b7ee

Please sign in to comment.