This script searches the selected text in the page for links, and follows the first one found. Very handy when combined with searching.
(function() {
var selection = window.getSelection().getRangeAt(0);
var container = document.createElement('div');
var elements;
var idx;
if('' + selection){
// Check for links contained within the selection
container.appendChild(selection.cloneContents());
elements = container.getElementsByTagName('a');
for(idx in elements){
if(elements[idx].href){
document.location.href = elements[idx].href;
return;
}
}
// Check for links which contain the selection
container = selection.startContainer;
while(container != document){
if(container.href){
document.location.href = container.href;
return;
}
container = container.parentNode;
}
}
})();
I find it useful to bind it to ctrl+return like so:
@cbind <Ctrl><Return> = script @scripts_dir/followSelected.js
Then I can search for the text of the link and hit ctrl+return when I get to it. Just like text-based browsers and vimperator.
Got the idea from this post.