

Show HN: Top Comment Highlighter - AndrewHampton

I wrote a quick and dirty script that I wanted to share with HN.  This bookmarklet will put a border around the top 10 comments on any comments page so you can quickly see what comments other readers find valueable. Just create a new bookmark and copy the text below into the URL field.<p>javascript:(function(){var%20s=document.createElement('script'),el=document.createElement('div'),b=document.getElementsByTagName('body')[0];var%20otherlib=false,startCounter=tryCounter=10,delay=250,msg='';s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js');el.style.position='fixed';el.style.height='32px';el.style.width='220px';el.style.marginLeft='-110px';el.style.top='0';el.style.left='50%';el.style.padding='5px%2010px%205px%2010px';el.style.fontSize='12px';el.style.color='#222';el.style.backgroundColor='#f99';if(typeof%20jQuery!='undefined'){msg='This%20page%20already%20using%20jQuery%20v'+jQuery.fn.jquery;}else{if(typeof%20$=='function'){otherlib=true;}%20document.getElementsByTagName('head')[0].appendChild(s);}%20var%20tryjQuery=function(){setTimeout(function(){if(typeof%20jQuery=='undefined'){if(tryCounter){tryCounter--;tryjQuery();}else{msg='Sorry,%20but%20after%20'+startCounter+'%20attempts,%20jQuery%20hasn\'t%20loaded';}}else{msg='This%20page%20is%20now%20jQuerified%20with%20v'+jQuery.fn.jquery;if(otherlib){msg+='%20and%20noConflict().%20Use%20$jq(),%20not%20$().';}var%20top%20=%20[];function%20sorter(a,%20b){return%20a[0]%20-%20b[0];}function%20process(i,%20el){%20var%20rating%20=%20parseInt($(el).text().split("%20")[0]);if%20(top.length%20&#60;%2010){top.push([rating,%20el]);top%20=%20top.sort(sorter);}else%20if%20(rating%20&#62;%20top[0][0]){top[0]%20=%20[rating,%20el];top%20=%20top.sort(sorter);}}function%20highlight(i,%20el){$(el).parent().parent().parent().css('border',%20'1px%20solid%20#FF6600');}var%20comments%20=%20$(".comhead%20&#62;%20span");comments.each(process);$(top).each(highlight);}},delay);};tryjQuery();})();<p>A lot of the script is pulled from the jQuerify bookmarklet from the Learning jQuery blog(http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet/), so thanks to them for that code.<p>Here's a link to what I wrote: https://gist.github.com/732292
======
AndrewHampton
Here's a picture of what it looks like: <http://twitpic.com/3dupcl>

------
gasull
Cool. A Greasemonkey script would also be useful.

