Browse Source

Fix beeper to work even today off-tab

master
Sofia 1 year ago
parent
commit
076543f3d0
  1. 13
      src/resources/beeping/main.js

13
src/resources/beeping/main.js

@ -4,6 +4,7 @@ var beepTimeCounter = 0;
var intervalId = 0;
var timeChangedWhileBegun = false;
var lastSec = -1;
var lastTimestampMs = 0;
var showBeep = 0;
@ -114,6 +115,7 @@ function toggle() {
beeperBegun = !beeperBegun;
if (beeperBegun) {
button.innerText = "Stop!";
lastTimestampMs = Date.now();
intervalId = setInterval(update, 10);
} else {
button.innerText = "Begin!";
@ -134,9 +136,14 @@ function update() {
var seconds = document.getElementById("seconds");
var milliseconds = document.getElementById("milliseconds");
beepTimeCounter -= 0.01;
showBeep -= 0.1;
var currentTimestampMs = Date.now();
var delta = currentTimestampMs - lastTimestampMs;
lastTimestampMs = currentTimestampMs;
beepTimeCounter -= (delta / 1000);
showBeep -= (delta / 1000);
if (beepTimeCounter <= 0) {
console.log(beepTimeCounter);
beepTimeCounter = beepInterval;
showBeep = 0.5;
document.getElementById("audio").fastSeek(0)
@ -154,7 +161,7 @@ function update() {
if (showBeep > 0) {
document.title = "Beeeep!";
} else {
document.title = "Beeper - " + sec;
document.title = "Beeper | " + sec;
}
}
}
Loading…
Cancel
Save