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:
+34
-34
@@ -6,23 +6,25 @@ 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) {
|
||||||
initialHours = initialHoursLocal;
|
initialHours = initialHoursLocal;
|
||||||
logMessage("Core", "Found initialHours in localStorage.")
|
logMessage("Core", "Found initialHours in localStorage.")
|
||||||
} else {
|
} else {
|
||||||
initialHours = initialHoursConfig;
|
initialHours = initialHoursConfig;
|
||||||
}
|
}
|
||||||
var initialMinutesLocal = window.localStorage.getItem('initialMinutes')
|
var initialMinutesLocal = window.localStorage.getItem('initialMinutes')
|
||||||
if(initialMinutesLocal !== null) {
|
if (initialMinutesLocal !== null) {
|
||||||
initialMinutes = initialMinutesLocal;
|
initialMinutes = initialMinutesLocal;
|
||||||
logMessage("Core", "Found initialMinutes in localStorage.")
|
logMessage("Core", "Found initialMinutes in localStorage.")
|
||||||
} else {
|
} else {
|
||||||
initialMinutes = initialMinutesConfig;
|
initialMinutes = initialMinutesConfig;
|
||||||
}
|
}
|
||||||
var initialSecondsLocal = window.localStorage.getItem('initialSeconds')
|
var initialSecondsLocal = window.localStorage.getItem('initialSeconds')
|
||||||
if(initialSecondsLocal !== null) {
|
if (initialSecondsLocal !== null) {
|
||||||
initialSeconds = initialSecondsLocal;
|
initialSeconds = initialSecondsLocal;
|
||||||
logMessage("Core", "Found initialSeconds in localStorage.")
|
logMessage("Core", "Found initialSeconds in localStorage.")
|
||||||
} else {
|
} else {
|
||||||
@@ -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,26 +54,25 @@ resetBtn.addEventListener("click", function(){
|
|||||||
logMessage("Core", "Timer Reset.");
|
logMessage("Core", "Timer Reset.");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
startBtn.addEventListener("click", function(){
|
startBtn.addEventListener("click", function(){
|
||||||
|
|
||||||
if(paused){
|
if (paused){
|
||||||
var initialHoursLocal = window.localStorage.getItem('initialHours')
|
var initialHoursLocal = window.localStorage.getItem('initialHours')
|
||||||
if(initialHoursLocal !== null) {
|
if (initialHoursLocal !== null) {
|
||||||
initialHours = initialHoursLocal;
|
initialHours = initialHoursLocal;
|
||||||
logMessage("Core", "Found initialHours in localStorage.")
|
logMessage("Core", "Found initialHours in localStorage.")
|
||||||
} else {
|
} else {
|
||||||
initialHours = initialHoursConfig;
|
initialHours = initialHoursConfig;
|
||||||
}
|
}
|
||||||
var initialMinutesLocal = window.localStorage.getItem('initialMinutes')
|
var initialMinutesLocal = window.localStorage.getItem('initialMinutes')
|
||||||
if(initialMinutesLocal !== null) {
|
if (initialMinutesLocal !== null) {
|
||||||
initialMinutes = initialMinutesLocal;
|
initialMinutes = initialMinutesLocal;
|
||||||
logMessage("Core", "Found initialMinutes in localStorage.")
|
logMessage("Core", "Found initialMinutes in localStorage.")
|
||||||
} else {
|
} else {
|
||||||
initialMinutes = initialMinutesConfig;
|
initialMinutes = initialMinutesConfig;
|
||||||
}
|
}
|
||||||
var initialSecondsLocal = window.localStorage.getItem('initialSeconds')
|
var initialSecondsLocal = window.localStorage.getItem('initialSeconds')
|
||||||
if(initialSecondsLocal !== null) {
|
if (initialSecondsLocal !== null) {
|
||||||
initialSeconds = initialSecondsLocal;
|
initialSeconds = initialSecondsLocal;
|
||||||
logMessage("Core", "Found initialSeconds in localStorage.")
|
logMessage("Core", "Found initialSeconds in localStorage.")
|
||||||
} else {
|
} else {
|
||||||
@@ -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){
|
||||||
@@ -105,7 +114,7 @@ Mousetrap.bind(randomHourShort, async function(e){
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function specialHourHandler(type){
|
async function specialHourHandler(type){
|
||||||
if((type === 'Happy' && happy_hour) || (type === 'Random' && random_hour)){
|
if ((type === 'Happy' && happy_hour) || (type === 'Random' && random_hour)){
|
||||||
specialHourFunc(type)
|
specialHourFunc(type)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -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,17 +182,18 @@ 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));
|
||||||
window.localStorage.setItem('initialMinutes', timeFunc.getMinutes(differenceTime));
|
window.localStorage.setItem('initialMinutes', timeFunc.getMinutes(differenceTime));
|
||||||
window.localStorage.setItem('initialSeconds', timeFunc.getSeconds(differenceTime));
|
window.localStorage.setItem('initialSeconds', timeFunc.getSeconds(differenceTime));
|
||||||
|
|
||||||
if(randHappy && happy_hour && !randomHappyBool){
|
if (randHappy && happy_hour && !randomHappyBool){
|
||||||
randomHappyBool = true
|
randomHappyBool = true
|
||||||
setTimeout(randomHappy,1000)
|
setTimeout(randomHappy,1000)
|
||||||
}
|
}
|
||||||
if(scheduleHappy && happy_hour && !scheduleHappyBool){
|
if (scheduleHappy && happy_hour && !scheduleHappyBool){
|
||||||
scheduleHappyBool = true
|
scheduleHappyBool = true
|
||||||
scheduleHappyFunc()
|
scheduleHappyFunc()
|
||||||
}
|
}
|
||||||
@@ -195,13 +202,9 @@ 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)){
|
||||||
logMessage("RandomHappy","It's not rigged!")
|
logMessage("RandomHappy","It's not rigged!")
|
||||||
specialHourFunc()
|
specialHourFunc()
|
||||||
setTimeout(specialHourFunc, 3600000)
|
setTimeout(specialHourFunc, 3600000)
|
||||||
@@ -212,9 +215,9 @@ function randomHappy(){
|
|||||||
|
|
||||||
function scheduleHappyFunc(){
|
function scheduleHappyFunc(){
|
||||||
let now = new Date()
|
let now = new Date()
|
||||||
if(now.getDay() == scheduleHappyDay){
|
if (now.getDay() == scheduleHappyDay){
|
||||||
if(now.getUTCHours() == scheduleHappyHour){
|
if (now.getUTCHours() == scheduleHappyHour){
|
||||||
if(now.getUTCMinutes() == 00){
|
if (now.getUTCMinutes() == 00){
|
||||||
logMessage("Schedule","It's time!")
|
logMessage("Schedule","It's time!")
|
||||||
specialHourFunc()
|
specialHourFunc()
|
||||||
setTimeout(specialHourFunc, 3600000)
|
setTimeout(specialHourFunc, 3600000)
|
||||||
@@ -231,13 +234,13 @@ var timeoutID;
|
|||||||
|
|
||||||
const addTime = async (time, s) => {
|
const addTime = async (time, s) => {
|
||||||
let addedTime = Math.floor(s);
|
let addedTime = Math.floor(s);
|
||||||
if(!bulk_enabled) {
|
if (!bulk_enabled) {
|
||||||
endingTimeBeforeCounter = time;
|
endingTimeBeforeCounter = time;
|
||||||
addedTimeCounter = addedTime;
|
addedTimeCounter = addedTime;
|
||||||
addTimeInternal();
|
addTimeInternal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(firstSub) {
|
if (firstSub) {
|
||||||
firstSub = false;
|
firstSub = false;
|
||||||
endingTimeBeforeCounter = time;
|
endingTimeBeforeCounter = time;
|
||||||
addedTimeCounter = addedTime;
|
addedTimeCounter = addedTime;
|
||||||
@@ -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";
|
||||||
@@ -268,7 +268,7 @@ const addTimeInternal = async () => {
|
|||||||
addedTime.style.left = `${randomInRange(35, 65)}%`;
|
addedTime.style.left = `${randomInRange(35, 65)}%`;
|
||||||
addedTime.style.top = `${randomInRange(15, 40)}%`;
|
addedTime.style.top = `${randomInRange(15, 40)}%`;
|
||||||
addedTime.style.opacity = "1";
|
addedTime.style.opacity = "1";
|
||||||
while(s > 0){
|
while (s > 0){
|
||||||
timeStep = s > 60 ? s/30 : 2
|
timeStep = s > 60 ? s/30 : 2
|
||||||
endingTime = timeFunc.addSeconds(time, timeStep)
|
endingTime = timeFunc.addSeconds(time, timeStep)
|
||||||
await sleep(50);
|
await sleep(50);
|
||||||
|
|||||||
Reference in New Issue
Block a user