Created
July 28, 2014 05:43
-
-
Save kennyyu/1b9e1940d9b587cd3ecc to your computer and use it in GitHub Desktop.
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
// Taken from: http://theclearingband.com/tumblr/tagcloud2.js | |
var postcount = 0; | |
var postmax = 400; | |
var posttotal = 0; | |
var tmap = new Object(); | |
var tvals = new Object(); | |
var vstr = ""; | |
var tdiv = document.getElementById("tagcloud"); | |
tdiv.innerHTML = "Loading cloud..."; | |
if (window.XMLHttpRequest) | |
{ | |
document.xhttp=new XMLHttpRequest(); | |
} | |
else // IE 5/6 | |
{ | |
document.xhttp=new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
var loc = document.location.href.split("/")[2]; | |
document.xhttp.open("GET","http://" + loc + "/api/read?num=50&start=" + postcount,true); | |
document.xhttp.onreadystatechange = proc; | |
document.xhttp.send(); | |
function proc(aEvt) { | |
if (document.xhttp.readyState == 4) | |
{ | |
if(document.xhttp.status == 200) | |
{ | |
postcount += 50; | |
xmlDoc=document.xhttp.responseXML; | |
var tags = xmlDoc.getElementsByTagName("tag"); | |
var posts = xmlDoc.getElementsByTagName("posts"); | |
posttotal = posts[0].getAttribute("total") - 0; | |
for(var t = 0; t < tags.length; t++) | |
{ | |
var mval = tags[t].textContent.replace(" ", ""); | |
if(tmap[mval]) | |
{ | |
tmap[mval]++; | |
} | |
else | |
{ | |
tmap[mval] = 1; | |
tvals[mval] = tags[t].textContent; | |
} | |
} | |
if(postcount < Math.min(posttotal,postmax)) | |
{ | |
document.xhttp.open("GET","http://" + loc + "/api/read?num=50&start=" + postcount,true); | |
document.xhttp.send(); | |
} | |
else | |
{ | |
for(var m in tmap) | |
{ | |
if(tmap[m] > 1) | |
{ | |
vstr += "<a href='/tagged/"+tvals[m]+"' style='font-size:"+(tmap[m] + 8)+"px;'>"+tvals[m]+"</a> "; | |
} | |
} | |
tdiv.innerHTML = vstr; | |
} | |
} | |
else | |
{ | |
tdiv.innerHTML = "tag cloud failure"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment