Last active
August 29, 2015 14:06
-
-
Save sheodox/e6afe09e243df6566160 to your computer and use it in GitHub Desktop.
Twitter auto-show mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (function () { | |
var newTweets = 0, | |
modes = []; | |
function addMode(modeName) { | |
var title = 'Tweets ['; | |
modes.push(modeName); | |
title += modes.join(', ') + ']'; | |
$('#content-main-heading').text(title); | |
} | |
if (!window.addMode) { | |
window.addMode = addMode; | |
} | |
function filteredNewNodeCallback(root, selector, callback) { | |
var obs, i; | |
if (!root || !selector || !callback) { | |
return; | |
} | |
function filterAndCallback(node) { | |
var matches = [], | |
childMatches; | |
if (node.matches(selector)) { | |
matches.push(node); | |
} | |
childMatches = node.querySelectorAll(selector); | |
if (childMatches.length !== 0) { | |
matches = matches.concat([].slice.call(childMatches)) | |
} | |
matches.map(callback); | |
} | |
obs = new MutationObserver(function (mutations) { | |
mutations.forEach(function (mutation) { | |
for (i = 0; i < mutation.addedNodes.length; i++) { | |
if (mutation.addedNodes[i].nodeType === 1) { | |
filterAndCallback(mutation.addedNodes[i]); | |
} | |
} | |
}) | |
}); | |
obs.observe(root, { | |
childList: true, | |
subtree: true | |
}); | |
} | |
function updateTitle() { | |
var title = 'Twitter'; | |
if (newTweets > 0) { | |
title += ' (' + newTweets + ')'; | |
} | |
document.title = title; | |
} | |
$('<style>.new-tweet.js-stream-item{background: #FEB !important;}.js-new-items-bar-container{height:0 !important;}</style>').appendTo('body'); | |
$('.home-stream').on('mouseover', '.new-tweet', function () { | |
$(this).removeClass('new-tweet'); | |
newTweets--; | |
updateTitle(); | |
}); | |
filteredNewNodeCallback($('.js-new-items-bar-container')[0], '.js-new-tweets-bar', function (newTweetsBar) { | |
newTweetsBar.click(); | |
}); | |
filteredNewNodeCallback($('.stream-container')[0], '.js-stream-item', function (tweet) { | |
tweet.classList.add('new-tweet'); | |
newTweets++; | |
updateTitle(); | |
}); | |
window.addMode('auto-show'); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment