Last active
August 29, 2015 14:04
-
-
Save dim0xff/3937914013dba7069637 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
javascript:(function(){ | |
var getXmlHttp = function () { | |
var xmlhttp; | |
try { | |
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); | |
} catch (e) { | |
try { | |
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
} catch (e) { | |
xmlhttp = false; | |
} | |
} | |
if (!xmlhttp && typeof XMLHttpRequest!='undefined') { | |
xmlhttp = new XMLHttpRequest(); | |
} | |
return xmlhttp; | |
}; | |
var initGame = function (cb) { | |
var xmlhttp = getXmlHttp(); | |
xmlhttp.open('GET', '/game/AjaxPlayGame.do?gameId=81901', true); | |
xmlhttp.onreadystatechange = function() { | |
if (xmlhttp.readyState == 4) { | |
if(xmlhttp.status == 200) { | |
var res = JSON.parse(xmlhttp.responseText); | |
var cd = 60; | |
var cdInterval; | |
cdInterval = setInterval ( function () { | |
document.getElementsByTagName("h1")[0].innerHTML = cd--; | |
if ( cd <= 0 ) { | |
clearInterval(cdInterval); | |
cb(res); | |
} | |
}, 1000); | |
} | |
} | |
}; | |
xmlhttp.send(null); | |
}; | |
var play; | |
play = function () { | |
initGame(function (res) { | |
if (!res.success) { | |
alert('Done'); | |
return; | |
} | |
var playRecordId = res.playRecordId; | |
var xmlhttp = getXmlHttp(); | |
xmlhttp.open('GET', '/game/AjaxFinishGame.do?score=200&playRecordId=' + playRecordId, true); | |
xmlhttp.onreadystatechange = function() { | |
if (xmlhttp.readyState == 4) { | |
if(xmlhttp.status == 200) { | |
var res = JSON.parse(xmlhttp.responseText); | |
setTimeout(function () {play()}, 3000); | |
} | |
} | |
}; | |
xmlhttp.send(null); | |
}); | |
}; | |
play(); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Holy Macaroni! Need 4 (four!!!) minutes to win points. Seems it's coffee time! ;-)