Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Endless Summer on Tumblr Dashboard
// ==UserScript==
// @name Endless Summer on dsbd
// @namespace http://www.tumblr.com/
// @description random next link on tumblr dashboard
// @include http://www.tumblr.com/dashboard/1*
// @include http://www.tumblr.com/show/*/1*
// @require https://raw.github.com/gist/3242
// @require https://raw.github.com/gist/198443
// @require https://raw.github.com/gist/34615
// @version 0.0.4.0.7
// ==/UserScript==
// requires AutoPagerize http://userscripts.org/scripts/show/8551 by swdyh
// requires fix of AutoPagerize http://d.hatena.ne.jp/t_f_m/20111121/1321886246a by t_f_m
// requires sharedObject http://exe.tyo.ro/2011/11/greasemonkey0912minibufferldrize.html
// using $X() https://gist.github.com/3242 by os0x
// using createDocumentFromString https://gist.github.com/198443 by os0x
// using wedata utility for GM https://gist.github.com/34615 by youpy
// notice: put this script ABOVE AutoPagerize
// endlesSummeRize fire on http://www.tumblr.com/dashboard/1000 or http://www.tumblr.com/show/photos/by/everyone/1000 or ...
(function(){
var dsbd = 'http://www.tumblr.com/dashboard';
var DATABASE_URL = 'http://wedata.net/items/54652.json';
var database = new Wedata.Database(DATABASE_URL);
var getId = function(info){
var opt = {
method: 'GET',
url: dsbd,
headers : {
},
onload: function(res) {
var i = $X(info.nextLink, createDocumentFromString(res.responseText));
if(i.length){
i = i[0];
}else{
return;
}
var cacheInfo = {
postNo : i.href.match(/.*\/\d+\/(\d+)/)[1],
nextLink : info.nextLink
};
GM_setValue('cacheInfo', JSON.stringify(cacheInfo));
}
};
GM_xmlhttpRequest(opt);
};
var endlessSummer = function(doc, url, info){
var cacheInfo = JSON.parse(GM_getValue('cacheInfo'));
if (!cacheInfo){
return;
}
var a = $X(cacheInfo.nextLink, doc);
if (a.length) {
a = a[0];
}else{
return;
}
a.href = location.pathname.replace(/(\/[^\/]+\/\d+)(\/\d+)/,'$1') + '?offset=' + draw(72997, cacheInfo.postNo);
a.textContent = 'Searching for The Endless Summer \u2192 ';
a.style.background='none repeat scroll 0 0 #4AADF0';
};
// Exponential Endless Summer 2013
var draw = function(oldestID, newestID) {
var oldestUTime = getUnixTimeFromPostID(oldestID);
var newestUTime = getUnixTimeFromPostID(newestID);
var drawnUTime = oldestUTime + Math.floor((newestUTime - oldestUTime) * Math.random());
return getPostIDFromUnixTime(drawnUTime);
}
var getPostIDFromUnixTime = function(utime) {
if (utime < 1149465600000) {
return;
} else if (utime === Number.POSITIVE_INFINITY) {
return Number.POSITIVE_INFINITY;
}
for (var i = 0; i < params.length; i++) {
if (utime <= params[i].upperBound) {
return Math.ceil(params[i].coefA * Math.exp(params[i].coefB * utime));
}
}
}
var getUnixTimeFromPostID = function(postID) {
if (postID < 1) { return; }
for (var i = 0; i < params.length; i++) {
if (postID <= getPostIDFromUnixTime(params[i].upperBound)) {
return Math.floor(Math.log(postID/params[i].coefA)/params[i].coefB);
}
}
}
var params = [
// f_i(t) = A_i * exp(B_i * t)
{coefA: 2.374 * Math.pow(10, -268), coefB: 5.342 * Math.pow(10, -10), upperBound: 1182114958836},
{coefA: 2.292 * Math.pow(10, -63), coefB: 1.349 * Math.pow(10, -10), upperBound: 1193135035175},
{coefA: 1.214 * Math.pow(10, -11), coefB: 3.509 * Math.pow(10, -11), upperBound: 1241622616806},
{coefA: 1.259 * Math.pow(10, -22), coefB: 5.546 * Math.pow(10, -11), upperBound: 1283088065116},
{coefA: 3.805 * Math.pow(10, -29), coefB: 6.716 * Math.pow(10, -11), upperBound: 1291075200000},
{coefA: 5.579 * Math.pow(10, -28), coefB: 6.521 * Math.pow(10, -11), upperBound: 1292241600000},
{coefA: 4.482 * Math.pow(10, -28), coefB: 6.541 * Math.pow(10, -11), upperBound: 1307576237375},
{coefA: 2.424 * Math.pow(10, -28), coefB: 6.588 * Math.pow(10, -11), upperBound: 1313586050187},
{coefA: 3.923 * Math.pow(10, -13), coefB: 3.922 * Math.pow(10, -11), upperBound: 1340572542928},
{coefA: 2.157 * Math.pow(10, -3), coefB: 2.249 * Math.pow(10, -11), upperBound: Number.POSITIVE_INFINITY},
]
GM_registerMenuCommand('endless summer - clear cache', function() {
GM_setValue('cacheInfo', '');
database.clearCache();
});
database.get(function(items) {
getId(items.data);
});
endlessSummer(document, '', '');
setTimeout(function(){
if (sharedObject.AutoPagerize && sharedObject.AutoPagerize.addDocumentFilter){
sharedObject.AutoPagerize.addDocumentFilter(endlessSummer);
}
},0);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment