Skip to content

Instantly share code, notes, and snippets.

@robo-corg
Created April 14, 2010 22:03
Show Gist options
  • Save robo-corg/366397 to your computer and use it in GitHub Desktop.
Save robo-corg/366397 to your computer and use it in GitHub Desktop.
Bookmarklet for in page search
(function () {
var result=0;
var text = prompt("Find",'');
function find (node) {
if (node.nodeType == 1) {
var children = node.childNodes;
for (var i=0;i<children.length;i++) {
var child = children[i];
var res = find(child);
if (res !== undefined) {
return (res.nodeType == 1) ? res : node;
}
}
}
else if (node.nodeType == 3 && node.nodeValue !== null) {
if (node.nodeValue.indexOf(text) != -1)
return node;
}
}
var result = find(document.body);
if (result !== undefined) {
window.scrollTo(0,result.offsetTop);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment