Skip to content

Instantly share code, notes, and snippets.

@srescio
Last active August 29, 2015 14:11
Show Gist options
  • Save srescio/33740f40adc387108953 to your computer and use it in GitHub Desktop.
Save srescio/33740f40adc387108953 to your computer and use it in GitHub Desktop.
Keeps the Twitter messages box fixed on the left and auto-updates incoming tweets while keeping the page scroll on currently visible content, like on the smartphone apps; Paste in browser's console and run to use it
(function(){
// Cleanup sidebar to save space
$('.wtf-module').remove();
$('.module.trends').remove();
$('.Footer.module').remove();
// Move tweet box into sidebar
$('.timeline-tweet-box').appendTo('.dashboard-left');
$('.timeline-tweet-box img').remove();
// CSS changes
$('.stream.home-stream').css({borderTop:'1px solid #e1e8ed'});
$('.AppContent.wrapper').css({width:'900px'});
$('#timeline').css({float:'right'});
// Make sidebar fixed to stay visible
$('.dashboard-left').css({position:'fixed'});
})();
setInterval(function(){
//Keep timeline updated and fix scroll to keep current content visible
var newTweets = $('.new-tweets-bar');
//If no new tweet stop
if (newTweets.length===0) return;
var newTweetsY = newTweets.outerHeight(),
latestScroll = $(document).scrollTop(),
latestTweet = $('#stream-items-id>li:first-child');
// render tweets than calc
newTweets.trigger('click');
// Calculate Y diff for new scroll position
var newTweet = $('#stream-items-id>li:first-child'),
newTweetY = newTweet.offset().top,
latestTweetY = latestTweet.offset().top,
diffY = latestTweetY - newTweetY,
scroll = latestScroll + diffY - newTweetsY,
// Reapply scroll difference
loop = setInterval(function(){
$(document).scrollTop(scroll);
},10);
//Clear loop
setTimeout(function(){clearInterval(loop)}, 300);
},1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment