Skip to content

Instantly share code, notes, and snippets.

@tzmartin
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzmartin/b992800d622fe737db6f to your computer and use it in GitHub Desktop.
Save tzmartin/b992800d622fe737db6f to your computer and use it in GitHub Desktop.
HN Hightlight

Bookmarklet

img

Drag this link to your bookmarks bar: HN Highlight

javascript:void%20function(){function%20e(e,t,a){var%20n=%22.%22+e+'{%20padding-left:%2030px;background-image:%20url(%22http://www.fasttrackcalltaxi.co.in/ft_clickyourtaxi/App_Images/new_icon.gif%22);%20background-repeat:%20no-repeat;%20}',c=document.head||document.getElementsByTagName(%22head%22)[0],d=document.createElement(%22style%22);d.type=%22text/css%22,d.styleSheet%3Fd.styleSheet.cssText=n:d.appendChild(document.createTextNode(n)),c.appendChild(d);var%20o=[%22second%22,%22seconds%22,%22minute%22,%22minutes%22,%22hour%22,%22hours%22,%22day%22,%22days%22];o=o.slice(0,o.indexOf(a)+1);for(var%20r=document.querySelectorAll('a[href*=%22item%3Fid%22]'),i=0;i%3Cr.length;i++){var%20s=r.item(i);try{var%20l=parseInt(s.innerHTML.match(/^\d+/)),u=s.innerHTML.match(/^\d+%20(.+%3F)%20ago$/)[1]}catch(m){continue}-1!==o.indexOf(u)%26%26(a===u%26%26l%3Et||(s.parentNode.className+=%22%20%22+e))}}e(%22newpost%22,3,%22hours%22)}();
function highlight(className, number, type) {
// append style
var css = '.'+className+'{ padding-left: 30px;background-image: url("http://www.fasttrackcalltaxi.co.in/ft_clickyourtaxi/App_Images/new_icon.gif"); background-repeat: no-repeat; }',
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
head.appendChild(style);
var types = ['second', 'seconds',
'minute', 'minutes',
'hour', 'hours',
'day', 'days'];
// Types are inclusive, so if we filtered to 'minutes', then
// we always want posts that were made 'seconds' ago.
types = types.slice(0, types.indexOf(type) + 1);
// Any link with 'item?id' is assumed to be a timestamp.
var posts = document.querySelectorAll('a[href*="item?id"]');
// Loop through the number of posts, since we need to access
// each post using NodeList#item.
for(var i = 0; i < posts.length; i++) {
var post = posts.item(i);
try {
// The leftmost integer.
var label_number = parseInt(post.innerHTML.match(/^\d+/));
// The label (a value that maps up to the types array).
var label_type = post.innerHTML.match(/^\d+ (.+?) ago$/)[1];
}
catch(e) {
// If either of the matches fail, it's due to an
// irrelevant link.
continue;
}
// Continue if the label is out of bounds.
// For instance, 'days' when filtering by 'minutes'.
if(types.indexOf(label_type) === -1) continue;
// Continue if the label type matches, but the number
// is larger than what we're filtering for.
if(type === label_type && label_number > number) continue;
// td > div > span > a
post.parentNode.className += ' ' + className;
}
}
highlight('newpost', 3, 'hours');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment