-
-
Save saitamanodoruji/2931824 to your computer and use it in GitHub Desktop.
Endless Summer on Tumblr Dashboard
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
// ==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* | |
// @include https://www.tumblr.com/dashboard/1* | |
// @include https://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.9 | |
// @update 2014-08-15 | |
// ==/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 | |
// 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.08 | |
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].coefAlpha * Math.exp(params[i].coefBeta * (utime - 1136073600000))); | |
} | |
} | |
} | |
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].coefAlpha)/params[i].coefBeta) + 1136073600000; | |
} | |
} | |
} | |
var params = [ | |
// f_i(t) = Alpha_i * exp[Beta_i * (t - t_0)] | |
// t: Unix time [msec] | |
// t_0 = 1136073600000 [msec] (2006-01-01T00:00:00+09:00) | |
{coefAlpha: 1.211 * Math.pow(10, -1), coefBeta: 1.571 * Math.pow(10, -10), upperBound: 1160012789359}, | |
{coefAlpha: 3.619 * Math.pow(10, -13), coefBeta: 1.266 * Math.pow(10, -9), upperBound: 1163269541924}, | |
{coefAlpha: 2.120 * Math.pow(10, 0), coefBeta: 1.846 * Math.pow(10, -10), upperBound: 1172120791893}, | |
{coefAlpha: 1.179 * Math.pow(10, -49), coefBeta: 3.331 * Math.pow(10, -9), upperBound: 1173392561265}, | |
{coefAlpha: 4.702 * Math.pow(10, -7), coefBeta: 7.024 * Math.pow(10, -10), upperBound: 1176405323219}, | |
{coefAlpha: 5.338 * Math.pow(10, 1), coefBeta: 2.425 * Math.pow(10, -10), upperBound: 1182930300850}, | |
{coefAlpha: 8.255 * Math.pow(10, 3), coefBeta: 1.349 * Math.pow(10, -10), upperBound: 1193299359828}, | |
{coefAlpha: 2.496 * Math.pow(10, 6), coefBeta: 3.509 * Math.pow(10, -11), upperBound: 1241622616806}, | |
{coefAlpha: 2.907 * Math.pow(10, 5), coefBeta: 5.546 * Math.pow(10, -11), upperBound: 1283088065116}, | |
{coefAlpha: 5.206 * Math.pow(10, 4), coefBeta: 6.716 * Math.pow(10, -11), upperBound: 1291075200000}, | |
{coefAlpha: 8.329 * Math.pow(10, 4), coefBeta: 6.521 * Math.pow(10, -11), upperBound: 1292241600000}, | |
{coefAlpha: 8.396 * Math.pow(10, 4), coefBeta: 6.541 * Math.pow(10, -11), upperBound: 1307576237376}, | |
{coefAlpha: 7.746 * Math.pow(10, 4), coefBeta: 6.588 * Math.pow(10, -11), upperBound: 1313586050187}, | |
{coefAlpha: 8.798 * Math.pow(10, 6), coefBeta: 3.922 * Math.pow(10, -11), upperBound: 1340572542928}, | |
{coefAlpha: 2.693 * Math.pow(10, 8), coefBeta: 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