Created
April 28, 2017 20:28
-
-
Save m0rsecode/3b7cca91397b127f238bec25c1ae4c6a 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 startTimer(duration, display) { | |
var timer = duration, minutes, seconds; | |
setInterval(function () { | |
minutes = parseInt(timer / 60, 10); | |
seconds = parseInt(timer % 60, 10); | |
minutes = minutes < 10 ? "0" + minutes : minutes; | |
seconds = seconds < 10 ? "0" + seconds : seconds; | |
display.textContent = minutes + ":" + seconds; | |
if (--timer < 0) { | |
timer = duration; | |
} | |
}, 1000); | |
}; | |
function checkForGame(p) { | |
var time = 25; | |
var gameChecker = setInterval(function() { | |
var gamePage = document.getElementById('game-page'); | |
console.log("Looking for game.."); | |
if (gamePage) { | |
startTimer(time, p); | |
clearInterval(gameChecker); | |
} | |
}, 500); | |
}; | |
var p = document.createElement("p"); | |
p.style.color = 'white'; | |
p.style.fontSize = '30px'; | |
p.style.padding = '10px'; | |
p.style.position = 'absolute'; | |
p.style.backgroundColor = 'black'; | |
p.style.marginTop = '100px'; | |
p.style.zIndex = '9999'; | |
p.innerHTML = "Waiting..."; | |
document.body.insertBefore(p, document.body.firstChild); | |
console.log("Loaded..."); | |
checkForGame(p); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment