Update script.js for fixes
Bug Fixes: - Fixed bug in which reset button did not work when Timer has ended. - Fixed bug in which timer could end while being paused. Added: - Happy and Random Hour now deactivates when Timer reset.
This commit is contained in:
+15
-15
@@ -6,6 +6,8 @@ var initialSeconds;
|
|||||||
var paused = false;
|
var paused = false;
|
||||||
var happy_hour_active = false;
|
var happy_hour_active = false;
|
||||||
var random_hour_active = false;
|
var random_hour_active = false;
|
||||||
|
let countdownEnded = false;
|
||||||
|
let countdownUpdater = null;
|
||||||
|
|
||||||
var initialHoursLocal = window.localStorage.getItem('initialHours')
|
var initialHoursLocal = window.localStorage.getItem('initialHours')
|
||||||
if (initialHoursLocal !== null) {
|
if (initialHoursLocal !== null) {
|
||||||
@@ -31,6 +33,10 @@ if(initialSecondsLocal !== null) {
|
|||||||
|
|
||||||
resetBtn.addEventListener("click", function(){
|
resetBtn.addEventListener("click", function(){
|
||||||
|
|
||||||
|
if (happy_hour_active) specialHourHandler('Happy');
|
||||||
|
if (random_hour_active) specialHourHandler('Random');
|
||||||
|
countdownEnded = false;
|
||||||
|
|
||||||
initialHours = initialHoursConfig;
|
initialHours = initialHoursConfig;
|
||||||
initialMinutes = initialMinutesConfig;
|
initialMinutes = initialMinutesConfig;
|
||||||
initialSeconds = initialSecondsConfig;
|
initialSeconds = initialSecondsConfig;
|
||||||
@@ -48,7 +54,6 @@ resetBtn.addEventListener("click", function(){
|
|||||||
logMessage("Core", "Timer Reset.");
|
logMessage("Core", "Timer Reset.");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
startBtn.addEventListener("click", function(){
|
startBtn.addEventListener("click", function(){
|
||||||
|
|
||||||
if (paused){
|
if (paused){
|
||||||
@@ -86,14 +91,18 @@ startBtn.addEventListener("click", function(){
|
|||||||
|
|
||||||
paused = false;
|
paused = false;
|
||||||
|
|
||||||
});
|
countdownUpdater = setInterval(() => {
|
||||||
|
getNextTime();
|
||||||
|
}, 1);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
Mousetrap.bind(pauseShort, function(e) {
|
Mousetrap.bind(pauseShort, function(e) {
|
||||||
paused = true;
|
paused = true;
|
||||||
logMessage("Core", "Timer was paused");
|
logMessage("Core", "Timer was paused");
|
||||||
document.getElementById("startPage").style.visibility = "visible";
|
document.getElementById("startPage").style.visibility = "visible";
|
||||||
document.getElementById("container").style.visibility = "hidden";
|
document.getElementById("container").style.visibility = "hidden";
|
||||||
|
clearInterval(countdownUpdater);
|
||||||
});
|
});
|
||||||
|
|
||||||
Mousetrap.bind(happyHourShort, async function(e){
|
Mousetrap.bind(happyHourShort, async function(e){
|
||||||
@@ -147,12 +156,9 @@ async function specialHourFunc(type){
|
|||||||
document.getElementById("SpecialHourText").style.opacity = "0";
|
document.getElementById("SpecialHourText").style.opacity = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let countdownEnded = false;
|
|
||||||
let users = [];
|
let users = [];
|
||||||
let time;
|
let time;
|
||||||
|
|
||||||
|
|
||||||
let endingTime = new Date(Date.now());
|
let endingTime = new Date(Date.now());
|
||||||
endingTime = timeFunc.addHours(endingTime, initialHours);
|
endingTime = timeFunc.addHours(endingTime, initialHours);
|
||||||
endingTime = timeFunc.addMinutes(endingTime, initialMinutes);
|
endingTime = timeFunc.addMinutes(endingTime, initialMinutes);
|
||||||
@@ -176,6 +182,7 @@ const getNextTime = () => {
|
|||||||
clearInterval(countdownUpdater);
|
clearInterval(countdownUpdater);
|
||||||
countdownEnded = true;
|
countdownEnded = true;
|
||||||
time = "00:00:00";
|
time = "00:00:00";
|
||||||
|
logMessage("Core", "Timer Ended");
|
||||||
}
|
}
|
||||||
if (!paused){
|
if (!paused){
|
||||||
window.localStorage.setItem('initialHours', timeFunc.getHours(differenceTime));
|
window.localStorage.setItem('initialHours', timeFunc.getHours(differenceTime));
|
||||||
@@ -195,10 +202,6 @@ const getNextTime = () => {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let countdownUpdater = setInterval(() => {
|
|
||||||
getNextTime();
|
|
||||||
}, 1);
|
|
||||||
|
|
||||||
function randomHappy(){
|
function randomHappy(){
|
||||||
if (!happy_hour_active){
|
if (!happy_hour_active){
|
||||||
if ((getRandomInt(0,10000) == 127)){
|
if ((getRandomInt(0,10000) == 127)){
|
||||||
@@ -255,12 +258,9 @@ const addTimeInternal = async () => {
|
|||||||
firstSub = true;
|
firstSub = true;
|
||||||
|
|
||||||
let addedTime = document.createElement("p");
|
let addedTime = document.createElement("p");
|
||||||
if(happy_hour_active) {
|
|
||||||
addedTime.classList = "gold";
|
happy_hour_active ? addedTime.classList = "gold" : addedTime.classList = "addedTime";
|
||||||
}
|
|
||||||
else {
|
|
||||||
addedTime.classList = "addedTime";
|
|
||||||
}
|
|
||||||
addedTime.innerText = `+${s}s`;
|
addedTime.innerText = `+${s}s`;
|
||||||
document.body.appendChild(addedTime);
|
document.body.appendChild(addedTime);
|
||||||
addedTime.style.display = "block";
|
addedTime.style.display = "block";
|
||||||
|
|||||||
Reference in New Issue
Block a user