Created
October 17, 2011 21:48
-
-
Save morrow/1293929 to your computer and use it in GitHub Desktop.
Search HN Comments
This file contains hidden or 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
| javascript:var query=/^username$/;var color="#FF3300";var offset=-10;if(!window.hnComments||!window.hnComments.length){window.hnComments=[];window.hnIndex=0;}for(x=0;x<document.getElementsByClassName("comhead").length;x++){var element=document.getElementsByClassName("comhead")[x].childNodes[0];var username=element.innerHTML;if(username&&username.match(query)&&window.hnComments.indexOf(element)<0){window.hnComments.push(element);element.style.color=color;}}if(window.hnComments&&typeof(window.hnComments[window.hnIndex])=="object"){window.hnComments[window.hnIndex].scrollIntoView();window.setTimeout("window.scrollBy(0,"+offset+");",1);window.hnIndex++;if((window.hnIndex)>=window.hnComments.length){window.hnIndex=0;}} |
This file contains hidden or 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
| // Which usernames to search for | |
| var query = /^username$/; | |
| // What color to highlight the username with (set to "" for no highlighting) | |
| var color = "#FF3300"; | |
| // How far up to scroll the window from the comment (for aesthetics) | |
| var offset = -10; | |
| // Initialize comment array and index | |
| if(!window.hnComments || !window.hnComments.length) { | |
| window.hnComments = []; | |
| window.hnIndex = 0; | |
| } | |
| // Populate hnComments array with comments that match the query, stylize comment usernames | |
| for (x = 0; x < document.getElementsByClassName("comhead").length; x++) { | |
| var element = document.getElementsByClassName("comhead")[x].childNodes[0]; | |
| var username = element.innerHTML; | |
| if (username && username.match(query) && window.hnComments.indexOf(element) < 0){ | |
| window.hnComments.push(element); | |
| element.style.color = color; | |
| } | |
| } | |
| // Scroll through matches to the query, cycle back to start if end is reached | |
| if(window.hnComments && typeof(window.hnComments[window.hnIndex]) == "object") { | |
| window.hnComments[window.hnIndex].scrollIntoView(); | |
| window.setTimeout("window.scrollBy(0,"+offset+");", 1); | |
| window.hnIndex++; | |
| if((window.hnIndex) >= window.hnComments.length){ | |
| window.hnIndex = 0; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment