Hatena::Groupkeysnail

hogelogの日記

 | 

2010-02-22

アレが欲しいこれが欲しいとかちょっとずつ

06:17

2010-02-20 - きすねた(ん) - keysnailグループを受けて、ちょっとずつ自分に最適化。まず[ [と] ]相当の機能をそれっぽく。

plugins.options["follow-link.targets"] = '//a[@href],//input[not(@value="hidden")],//button';
plugins.options["follow-link.nextpattern"] = "^次へ|進む|^次.*|続|→|\\bnext|>>|≫";
plugins.options["follow-link.prevpattern"] = "\\bback|戻る|^前.*|←|\\bprev|<<|≪";

function followRel(doc, pattern) {
    let regex = RegExp(pattern);
    for each (target in plugins.options["follow-link.targets"].split(",")) {
        let result = doc.evaluate(target, doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
        for (let i = 0;i < result.snapshotLength; ++i) {
            let elem = result.snapshotItem(i);
            if (regex.test(elem.textContent) || regex.test(elem.value)) {
                plugins.hok.followLink(elem, plugins.hok.CURRENT_TAB)
                return elem;
            }
        }
    }
    return false;
}
 
ext.add("follow-next-link", function () { followRel(content.document, plugins.options["follow-link.nextpattern"]); }, "follow next link");
ext.add("follow-prev-link", function () { followRel(content.document, plugins.options["follow-link.prevpattern"]); }, "follow previous link");

CSS Selector慣れてないのでついXPathにしたけど、する必要は無かったか。結局正規表現で一個ずつ見てるわけだし。

ちなみにvimperatorの[ [, ] ]はinputを叩いてくれない。

KellsieKellsie2011/10/06 02:39Haha. I woke up down today. You've cehered me up!

vskomrsvskomrs2011/10/06 16:11oGAPBx <a href="http://jbgllvilzsen.com/">jbgllvilzsen</a>

piofalxeigpiofalxeig2011/10/08 00:08fwcxQ1 <a href="http://fdqegzneoyvi.com/">fdqegzneoyvi</a>

xaxwhlpexaxwhlpe2011/10/12 23:24QIh1RS , [url=http://ngzfsmkwadee.com/]ngzfsmkwadee[/url], [link=http://zbxnpmccsdza.com/]zbxnpmccsdza[/link], http://sgwojfuxlydo.com/

DealgunlugarDealgunlugar2013/02/10 23:14Knowledge wants to be free, just like these articels!

vfzscpqfjlqvfzscpqfjlq2013/02/11 23:125EFLpr <a href="http://qjuwlapvprtp.com/">qjuwlapvprtp</a>

rhibzxtyyerhibzxtyye2013/02/14 00:47jjd6IZ <a href="http://osgktmuidgsp.com/">osgktmuidgsp</a>

 |