By cxx
—
Last update
Feb 27, 2008
—
Installed
181 times.
// ==UserScript==
// @name Tumblr Reblog Count
// @namespace http://cxx.tumblr.com/
// @include http://*.tumblr.com/post/*
// @version 0.2
// ==/UserScript==
var id = Number( window.location.pathname.match(/\d+/)[0] );
var db_uri = 'http://www.tumblr.com/dashboard/2/' + (id+1);
var node = document.evaluate(
'//div[contains(concat(" ",@class," ")," post ")]',
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null
).singleNodeValue;
var new_elem = document.createElement('div');
new_elem.className = 'reblog_info';
new_elem.innerHTML = 'Loading...';
node.appendChild(new_elem);
GM_xmlhttpRequest( {
method: 'GET',
url: db_uri,
onload: function(res) {
var db_doc = (new DOMParser()).parseFromString(
res.responseText.replace(/<img([^>]*[^\/])>/gm, '<img$1/>').replace(/<noscript>(.|\n)*<\/noscript>/gm, ''),
'application/xhtml+xml');
var post = db_doc.getElementById('post' + id);
if (post) {
var divs = post.getElementsByTagName('div');
var count = 0;
var notes_uri;
for (var i = 0; i < divs.length; ++i) {
if (divs[i].className == 'reblog_info') {
var result;
var info = divs[i].innerHTML.replace(/<[^>]*>/gm, '').replace(/\s+/gm, ' ');
if (!info.match(/reblogged/))
count = Number(info.match(/and (\d+)/)[1]);
else if (result = info.match(/and (\d+)/))
count = Number(result[1]) + 1;
else if (result = info.match(/(\d+) other/))
count = Number(result[1]);
else
count = 1;
var result = divs[i].innerHTML.match(/\/dashboard\/notes\/\d*\/\w*/);
if (result)
notes_uri = 'http://www.tumblr.com' + result[0];
}
}
if (notes_uri)
new_elem.innerHTML = '<a href="' + notes_uri + '">' + count + ' reblogged</a>';
else
new_elem.innerHTML = count + ' reblogged';
}
else {
new_elem.innerHTML = 'You have not followed this user yet.';
}
}
} );