Created
March 13, 2012 12:53
-
-
Save spudtrooper/2028580 to your computer and use it in GitHub Desktop.
Only display twitter updates in batches of certain numbers. By default the minimum number of item required to show is 10, this can be changed via localStorage to, say, N, e.g. localStorage.setItem('batch.number',N)
This file contains 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
// ==UserScript== | |
// @name Twitter Batch | |
// @namespace http://jeffpalm.com/twitterbatch | |
// @description Only display twitter updates in batches of certain numbers. | |
// By default the minimum number of item required to show is | |
// 10, this can be changed via localStorage to, say, N, e.g. | |
// localStorage.setItem('batch.number',N) | |
// @include https://twitter.com | |
// @include https://www.twitter.com | |
// @include https://twitter.com/* | |
// @include https://www.twitter.com/* | |
// ==/UserScript== | |
(function() { | |
const BATCH_NUMBER_KEY = 'batch.number'; | |
const BATCH_NUMBER_DEFAULT = 10; | |
function note(msg) { | |
try { | |
console.log(msg); | |
} catch (_) {} | |
} | |
function getBatchNumber() { | |
var key = BATCH_NUMBER_KEY; | |
var res = BATCH_NUMBER_DEFAULT; | |
try { | |
var num = parseInt(localStorage.getItem(key)); | |
if (!isNaN(num) && num > 0) res = num; | |
} catch (_) {} | |
return res; | |
} | |
function Checker() { | |
this.ignoreNextChange = false; | |
this.hideNumTweetsSignTries = 0; | |
} | |
const HIDE_NUM_TWEETS_TRIES = 5; | |
Checker.prototype = { | |
hideNumTweetsSign: function() { | |
var removed = false; | |
var divs = document.getElementsByTagName('DIV'); | |
for (var i in divs) { | |
var div = divs[i]; | |
if (!!div.className && div.className.match(/new-tweets-bar/)) { | |
div.parentNode.removeChild(div); | |
removed = true; | |
break; | |
} | |
} | |
if (!removed) { | |
if (this.hideNumTweetsSignTries-- > 0) { | |
var thiz = this; | |
setTimeout(function(){thiz.hideNumTweetsSign();},500); | |
} | |
} | |
}, | |
checkNumTweets: function() { | |
if (this.ignoreNextChange) { | |
this.ignoreNextChange = false; | |
return; | |
} | |
var title = String(document.title); | |
var total = 0; | |
var res; | |
if (res = title.match(/\(([\d,]+)\)/)) { | |
total = parseInt(res[1].replace(/\D/g,'')); | |
} | |
var min = getBatchNumber(); | |
note('checkNumTweets: total='+total + ',min='+min); | |
if (total == 0) return; | |
if (total < min) { | |
this.ignoreNextChange = true; | |
document.title = title.replace(/\s*\([\d,]+\)\s*/g,''); | |
this.hideNumTweetsSignTries = HIDE_NUM_TWEETS_TRIES; | |
this.hideNumTweetsSign(); | |
} | |
} | |
}; | |
function main() { | |
var titleEl = document.getElementsByTagName('title')[0]; | |
var docEl = document.documentElement; | |
var c = new Checker(); | |
if (docEl && docEl.addEventListener) { | |
docEl.addEventListener('DOMSubtreeModified', function(evt) { | |
var t = evt.target; | |
if (t === titleEl || | |
(t.parentNode && t.parentNode === titleEl)) { | |
c.checkNumTweets(); | |
} | |
}, false); | |
} else { | |
document.onpropertychange = function() { | |
if (window.event.propertyName == 'title') { | |
c.checkNumTweets(); | |
} | |
}; | |
} | |
c.checkNumTweets(); | |
} | |
main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment