-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlamp.js
More file actions
44 lines (35 loc) · 1.93 KB
/
lamp.js
File metadata and controls
44 lines (35 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*This is the GaragemHacker Checkout Status JS
- It make an asyncronus check on a status.txt file, and change an image
class lampoff to lampon.
To use this you need to create an element on you page with ID lamp.
*/
window.onload=function start() {
var xmlhttp, status, logger; //my vars
//var xmlhttp;
xmlhttp = new XMLHttpRequest();
//xmlhttp.open('GET', 'http://garagemhacker.org/status.txt', true); //this request for outsider's require enable CORS
xmlhttp.open('GET', 'status.txt', true);
xmlhttp.send();
//logger = xmlhttp.responseText;//get the response on status var
console.log(xmlhttp.responseText); //show the response on console.log (for debuger's
xmlhttp.onreadystatechange=function(){
status = xmlhttp.responseText;//get the response on status var
if (xmlhttp.readyState==4 && xmlhttp.status==200){
if(status.trim() == 'fechado'){
//Change element to lamp off
//document.getElementById("lamp").style.backgroundPosition=("-85px 85px");//sample to change position
document.getElementById("lamp").className=("lampoff");//sample to change class
//document.getElementById("lamp").innerHTML=status;//show content of the status.txt file
//console.log(xmlhttp); //Somente para Debug
}
else if (status.trim() == 'aberto') {
//Change element to lamp on
//document.getElementById("lamp").style.backgroundPosition=("10px 85px");
document.getElementById("lamp").className=("lampon");//sample to change class
//document.getElementById("real").innerText=xmlhttp.responseText;//Use para requisicoes sincronas com xmlhttp false
//document.getElementById("lamp").innerHTML=status;//show content of the status.txt file
}
//console.log(xmlhttp);//uncoment for a fully debug for if end else if condition
}//close the xmlhttp.reasState if
}//close the xmlhttp.onreadystatechange
}//close start