Created
January 19, 2010 09:00
-
-
Save mgng/280787 to your computer and use it in GitHub Desktop.
なんか
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
(function(){ | |
var token=(parseInt(Math.random()*10000000000)+'').substr(0,9); | |
if(document.getElementById(token) == undefined){ | |
var r = document.createElement('div'); | |
var b = document.createElement('button'); | |
r.id=token; | |
b.clicked=false; | |
b.innerHTML='GET'; | |
b.onclick=function(){ | |
var url = b.clicked ? '/sets/'+token+'/next.json?mix_id='+mix.id : '/sets/'+token+'/play.json?mix_id='+mix.id ; | |
aj(url, callback); | |
}; | |
var head = document.getElementById('head'); | |
head.appendChild(b); | |
head.appendChild(r); | |
} | |
function cl(o){ | |
var a = document.createElement('a'); | |
a.href=o.item; | |
a.appendChild(document.createTextNode(o.contributor+' -- '+o.title)); | |
var div = document.createElement('div'); | |
div.appendChild(a); | |
return div; | |
} | |
function callback(res, status){ | |
if (res == '' || status != 200) { | |
return; // ooohhhh | |
} | |
var j,o; | |
eval("j="+res); | |
if(j.track.trackId==0){ | |
b.disabled=true; | |
b.style.display='none'; | |
return; | |
} | |
o=j.track; | |
document.getElementById(token).appendChild(cl(o)); | |
b.clicked=true; | |
} | |
function aj(url, func){ | |
var xhr =(window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP"); | |
xhr.onreadystatechange=function(){if(xhr.readyState==4){func(xhr.responseText, xhr.status);}} | |
xhr.open("GET", url); | |
xhr.send(null); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment