Created
July 27, 2020 03:21
-
-
Save rlaace423/8361507107a4b36f58647d467b7501b7 to your computer and use it in GitHub Desktop.
Case-sensitive Finder for Chrome
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
# Create bookmark like | |
## name: (whatever you want) | |
## URL: (copy & paste codes below) | |
javascript: (function () { | |
var text = prompt('Search for:', ''); | |
if (text == null || text.length == 0) return; | |
var spans = document.getElementsByClassName('labnol'); | |
if (spans) { | |
for (var i = 0; i < spans.length; i++) { | |
spans[i].style.backgroundColor = 'transparent'; | |
} | |
} | |
function searchWithinNode(node, te, len) { | |
var pos, skip, spannode, middlebit, endbit, middleclone; | |
skip = 0; | |
if (node.nodeType == 3) { | |
pos = node.data.indexOf(te); | |
if (pos >= 0) { | |
spannode = document.createElement('span'); | |
spannode.setAttribute('class', 'labnol'); | |
spannode.style.backgroundColor = 'yellow'; | |
middlebit = node.splitText(pos); | |
endbit = middlebit.splitText(len); | |
middleclone = middlebit.cloneNode(true); | |
spannode.appendChild(middleclone); | |
middlebit.parentNode.replaceChild(spannode, middlebit); | |
skip = 1; | |
} | |
} else if (node.nodeType == 1 && node.childNodes && node.tagName.toUpperCase() != 'SCRIPT' && node.tagName.toUpperCase != 'STYLE') { | |
for (var child = 0; child < node.childNodes.length; ++child) { | |
child = child + searchWithinNode(node.childNodes[child], te, len); | |
} | |
} | |
return skip; | |
} | |
searchWithinNode(document.body, text, text.length); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment