Created
December 11, 2019 15:37
-
-
Save eviltester/28d229f7f5f5724ec74f6369e9cc8cc2 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
var xhttp = new XMLHttpRequest(); | |
xhttp.open("GET","https://bitbloxs.herokuapp.com/boxes?api_key=thisistheapikey"); | |
xhttp.onload = (e)=>{ | |
console.log(xhttp.status); | |
console.log(xhttp.responseText); | |
} | |
xhttp.send(null); | |
--- | |
for(var i=1;i<=400;i++){ | |
const myint=i; | |
setTimeout(function(){ | |
console.log("sending") | |
var myxhttp = new XMLHttpRequest(); | |
myxhttp.open("POST","https://bitbloxs.herokuapp.com/change/"+myint+"/blue?api_key=thisistheapikey"); | |
myxhttp.send(); | |
},200); | |
} | |
--- | |
function changeMyColour(verb, mycolor, myindex){ | |
console.log(verb + " " + myindex + " " + mycolor); | |
var myxhttp = new XMLHttpRequest(); | |
myxhttp.open(verb,"https://bitbloxs.herokuapp.com/change/"+myindex+"/"+mycolor+"?api_key=thisistheapikey"); | |
myxhttp.send(); | |
} | |
function changeAllColoursTo(mycolor, delay){ | |
var xhttp = new XMLHttpRequest(); | |
xhttp.open("GET","https://bitbloxs.herokuapp.com/boxes?api_key=thisistheapikey"); | |
xhttp.onload = (e)=>{ | |
console.log(xhttp.status); | |
console.log(xhttp.responseText); | |
var boxes = JSON.parse(xhttp.responseText); | |
for(var i=1;i<=400;i++){ | |
var box=boxes["box_"+i]; | |
var myindex = i; | |
if(box.color=="white"){ // set to my colour | |
setTimeout(changeMyColour, i*delay, "POST", mycolor, myindex); | |
} | |
if(box.color!=mycolor){ // change it | |
setTimeout(changeMyColour, i*delay, "PUT", mycolor, myindex); | |
} | |
} | |
} | |
xhttp.send(null); | |
} | |
changeAllColoursTo("blue", 100); | |
--- | |
myColourBot = window.setInterval(function(){changeAllColoursTo("blue",100)},4000); // runs every 4 seconds | |
// window.clearInterval(myColourBot) | |
// yellow, blue, green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment