Skip to content

Instantly share code, notes, and snippets.

@hogelog
Created February 22, 2010 08:12
Show Gist options
  • Save hogelog/310923 to your computer and use it in GitHub Desktop.
Save hogelog/310923 to your computer and use it in GitHub Desktop.
plugins.options["follow-link.targets"] = 'a[href], input:not([type="hidden"]), button';
plugins.options["follow-link.nextpattern"] = "^次へ|進む|^次.*|続|→|\\bnext|>>|≫";
plugins.options["follow-link.prevpattern"] = "\\bback|戻る|^前.*|←|\\bprev|<<|≪";
function findPattern(doc, pattern) {
let target = plugins.options["follow-link.targets"];
let regex = RegExp(pattern);
let result = doc.querySelectorAll(target);
for (let i=result.length-1;i>=0;--i) {
let elem = result[i];
if (regex.test(elem.textContent) || regex.test(elem.value)) {
return elem;
}
}
return false;
}
function findRel(doc, rel) {
for each(let query in ['a[rel~="%s"]', 'link[rel~="%s"]']) {
let link = doc.querySelector(util.format(query, rel));
if (link)
return link;
}
return false;
}
function followLink(doc, rel, pattern) {
let link = findRel(doc, rel) || findPattern(doc, pattern);
if (link);
plugins.hok.followLink(link, plugins.hok.CURRENT_TAB)
}
ext.add("follow-next-link", function () { followLink(content.document, "next", plugins.options["follow-link.nextpattern"]); }, "follow next link");
ext.add("follow-prev-link", function () { followLink(content.document, "prev", plugins.options["follow-link.prevpattern"]); }, "follow previous link");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment