40 lines
571 B
JavaScript
40 lines
571 B
JavaScript
var i=0;
|
|
var update = null;
|
|
function timedCount(){
|
|
|
|
onmessage = (e) => {
|
|
|
|
|
|
if(e.data[0] == "on"){
|
|
// console.log("on");
|
|
update = "1";
|
|
}
|
|
|
|
if(e.data[0] == "off"){
|
|
clearInterval(update);
|
|
}
|
|
// console.log(e.data);
|
|
if(e.data[0] == "changespeed"){
|
|
if(update){
|
|
clearInterval(update);
|
|
if(e.data[1] == 0){
|
|
|
|
}else{
|
|
let speed = 900/e.data[1];
|
|
update = setInterval("stationupdate()", speed);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
function stationupdate(){
|
|
|
|
postMessage("up");
|
|
}
|
|
|
|
timedCount();
|