Skip to content

Instantly share code, notes, and snippets.

@cfg
Created July 27, 2011 19:22
Show Gist options
  • Save cfg/1110156 to your computer and use it in GitHub Desktop.
Save cfg/1110156 to your computer and use it in GitHub Desktop.
Scroll to the first new tweet on twitter.com
/*
See: http://coreygilmore.com/blog/2011/07/20/bookmarklet-scroll-to-the-first-new-tweet/
*/
javascript:(function(){
if( document.getElementsByClassName ) {
var t=document.getElementsByClassName("last-new-tweet")[0];
if(t) {
window.scrollTo(0, t.offsetTop + t.offsetParent.offsetTop );
}
} else {
var els = document.getElementsByTagName("div"), elsLen = els.length, pattern = new RegExp("(^|\\s)last-new-tweet(\\s|$)");
for (var i = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
window.scrollTo(0, els[i].offsetTop + els[i].offsetParent.offsetTop );
break;
}
}
}
})();
/* Minified:
javascript:(function(){if(document.getElementsByClassName){var t=document.getElementsByClassName("last-new-tweet")[0];if(t){window.scrollTo(0,t.offsetTop+t.offsetParent.offsetTop);}}else{var els=document.getElementsByTagName("div"),elsLen=els.length,pattern=new RegExp("(^|\\s)last-new-tweet(\\s|$)");for(var i=0;i<elsLen;i++){if(pattern.test(els[i].className)){window.scrollTo(0,els[i].offsetTop+els[i].offsetParent.offsetTop);break;}}}})();
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment