// ==UserScript== // @name Tumblr Shoutr // @namespace moz // @description Shout out the stuff you really want to see // @include http://www.tumblr.com/dashboard // @include http://www.tumblr.com/dashboard/* // @include http://www.tumblr.com/show/* // @include http://www.tumblr.com/tagged/* // ==/UserScript== /* made because lmotep said that Tumblr Saviour (savur?) is weaksauce */ /* N.B.: if a post is highlighted, it will not be darkened. */ "use strict"; var dark_style, light_style; var dark_words, undark_words, light_words, unlight_words; var ssheet, old_last_li; // -- config -- /* TODO: put these into a floaty config div block */ dark_style = '.moz_hide {display:none;}'; light_style = '.moz_bright {background:#FFFFFF; color:#CC0000; font-size:125%;}'; dark_words = '#spoilers, #sj'; undark_words = '#kills-dumbledore, #sjsally'; light_words = 'iphone, #homestuck'; unlight_words = '#iphone-sucks, eridan'; // -- main() -- ssheet = document.styleSheets[0]; ssheet.insertRule(dark_style); ssheet.insertRule(light_style); old_last_li = 0; function cook(){ var dark_re, undark_re, light_re, unlight_re, li_items; var current_last_li, i, li_text; dark_re = '\\b' + dark_words.replace(/, ?/,'\\b|\\b') + '\\b'; dark_re = new RegExp(dark_re, "i"); undark_re = '\\b' + undark_words.replace(/, ?/,'\\b|\\b') + '\\b'; undark_re = new RegExp(undark_re, "i"); light_re = '\\b' + light_words.replace(/, ?/,'\\b|\\b') + '\\b'; light_re = new RegExp(light_re, "i"); unlight_re = '\\b' + unlight_words.replace(/, ?/,'\\b|\\b') + '\\b'; unlight_re = new RegExp(unlight_re, "i"); li_items = document.getElementsByTagName('li'); current_last_li = li_items.length; for(i=current_last_li; i>=old_last_li; i--) { if( ! li_items[i].id.match(/^post/) || li_items[i].className.match(/\.moz_bright$|\.moz_dark$/)) { continue; } li_text = li_items[i].textContent; if( light_re.test(li_text) && ! unlight_re.test(li_text) ) { li_items[i].className = li_items[i].className + ' .moz_bright'; } else if( dark_re.test(li_text) && ! undark_re.test(li_text) ) { li_items[i].className = li_items[i].className + ' .moz_dark'; } } old_last_li = current_last_li; } /* setInterval() because tumblr likes 'endless-scrolling' pages */ setInterval(cook, 300);