Last active
September 8, 2015 22:21
-
-
Save KenshoFujisaki/768b8f25e0822b8f3974 to your computer and use it in GitHub Desktop.
ページ内のすべてのURLについて,正規表現`url_regex`にマッチするものを紫色で強調 for vimperator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"==============================================================================" | |
" Hightlight matched URLs " | |
" usage(example): " | |
" :highlightUrls [regex] " | |
" :highlightUrls github|gitlab " | |
"==============================================================================" | |
js <<EOM | |
commands.addUserCommand( | |
["highlightUrls"], | |
"Highlight matched URLs", | |
function(args){ | |
let url_regex = new RegExp(args.join("")); | |
let iterator = gBrowser.contentDocument.evaluate( | |
"//a", | |
gBrowser.contentDocument, | |
null, | |
XPathResult.ORDERED_NODE_ITERATOR_TYPE, | |
null); | |
let highlighter = function(elm) { | |
elm.style = | |
"font-weight:900;" + | |
"color:white;" + | |
"background-color:purple;"; | |
}; | |
let node; | |
while ( node = iterator.iterateNext() ) { | |
if ( node.href.match(url_regex) ) { | |
setTimeout(function(_node){highlighter(_node)}, 0, node); | |
} | |
} | |
}, | |
{}, | |
true | |
); | |
EOM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment