Add random hour visual toggle

This commit is contained in:
Danilo Titato
2023-03-01 16:33:46 -03:00
parent 386fee2a84
commit 5a89ede16b
4 changed files with 57 additions and 50 deletions
+2
View File
@@ -1,5 +1,6 @@
// Happy Hour // Happy Hour
var happy_hour = true // set to true or false, to enable/disable the happy hours function var happy_hour = true // set to true or false, to enable/disable the happy hours function
var random_hour = true
var randHappy = false // only works if happy_hour = true var randHappy = false // only works if happy_hour = true
var scheduleHappy = false // only works if happy_hour = true var scheduleHappy = false // only works if happy_hour = true
@@ -13,6 +14,7 @@ var bulk_enabled = false
//Shortcuts //Shortcuts
var pauseShort = "ctrl+alt+p" var pauseShort = "ctrl+alt+p"
var happyHourShort = "ctrl+alt+h" var happyHourShort = "ctrl+alt+h"
var randomHourShort = "ctrl+alt+r"
// Login Data // Login Data
var twitch_channel_name = "" var twitch_channel_name = ""
+3 -3
View File
@@ -44,9 +44,9 @@ body {
visibility: hidden; visibility: hidden;
} }
#HappyHourText { #SpecialHourText {
opacity: 0; opacity: 0;
font-size: 2.8rem; font-size: 2.5rem;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
@@ -71,7 +71,7 @@ body {
height: 100%; height: 100%;
} */ } */
#HappyHourHTML { #SpecialHourHTML {
top:-200px; top:-200px;
position: relative; position: relative;
} }
+4 -4
View File
@@ -23,10 +23,10 @@
<div id="textDiv"> <div id="textDiv">
<p id="timeText">00:00:00</p> <p id="timeText">00:00:00</p>
</div> </div>
<div id="HappyHourHTML"> <div id="SpecialHourHTML">
<p id="HappyHourText">Happy Hour Activated!</p> <p id="SpecialHourText">Happy Hour Activated!</p>
<!-- <p id="HappyHourDeactive">Happy Hour Deactivated :(</p> <!-- <p id="SpecialHourDeactive">Happy Hour Deactivated :(</p>
<p id="HappyHourError">Happy Hour not available D:</p> --> <p id="SpecialHourError">Happy Hour not available D:</p> -->
</div> </div>
<canvas id="canvas"></canvas> <canvas id="canvas"></canvas>
</div> </div>
+48 -43
View File
@@ -5,6 +5,7 @@ var initialMinutes;
var initialSeconds; var initialSeconds;
var paused = false; var paused = false;
var happy_hour_active = false; var happy_hour_active = false;
var random_hour_active = false;
var initialHoursLocal = window.localStorage.getItem('initialHours') var initialHoursLocal = window.localStorage.getItem('initialHours')
if(initialHoursLocal !== null) { if(initialHoursLocal !== null) {
@@ -96,52 +97,56 @@ Mousetrap.bind(pauseShort, function(e) {
}); });
Mousetrap.bind(happyHourShort, async function(e){ Mousetrap.bind(happyHourShort, async function(e){
if(happy_hour){ specialHourHandler('Happy');
happyHourFunc()
}
else {
logMessage("Core", "Happy Hour is not available")
document.getElementById("HappyHourText").innerHTML = "Happy Hour error";
document.getElementById("HappyHourText").animate({opacity: [ 0, 1 ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("HappyHourText").style.opacity = "1";
document.getElementById("HappyHourHTML").animate({top: [ "-200px", "-250px" ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("HappyHourHTML").style.top = "-250px";
await sleep(5000)
document.getElementById("HappyHourText").animate({opacity: [ 1, 0 ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("HappyHourText").style.opacity = "0";
}
}); });
async function happyHourFunc(){ Mousetrap.bind(randomHourShort, async function(e){
if(!happy_hour_active){ specialHourHandler('Random');
logMessage("Core","Happy Hour activated"); });
happy_hour_active = true;
document.getElementById("HappyHourText").innerHTML = "Happy Hour Activated!"; async function specialHourHandler(type){
document.getElementById("HappyHourText").animate({opacity: [ 0, 1 ], easing: [ 'ease-in', 'ease-out' ],}, 500); if((type === 'Happy' && happy_hour) || (type === 'Random' && random_hour)){
document.getElementById("HappyHourText").style.opacity = "1"; specialHourFunc(type)
document.getElementById("HappyHourHTML").animate({top: [ "-200px", "-250px" ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("HappyHourHTML").style.top = "-250px";
document.getElementById("container").style.backgroundImage = "-webkit-linear-gradient(-45deg, transparent 33%, rgba(0, 0, 0, .1) 33%, rgba(0,0, 0, .1) 66%, transparent 66%), -webkit-linear-gradient(top, rgba(255, 255, 255, .25), rgba(0, 0, 0, .25)), url(https://drive.google.com/uc?id=1oduFlPg84O1DliM5FsLvJJsnwZ4m1Vpm), -webkit-linear-gradient(left, #0074cc, #a700cc)";
await sleep(10000)
document.getElementById("HappyHourText").animate({opacity: [ 1, 0 ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("HappyHourText").style.opacity = "0";
} }
else if(happy_hour_active){ else {
logMessage("Core", "Happy Hour deactivated") logMessage("Core", `${type} Hour is not available`)
clearTimeout(happyHourFunc) document.getElementById("SpecialHourText").innerHTML = `${type} Hour error`;
happy_hour_active = false; document.getElementById("SpecialHourText").animate({opacity: [ 0, 1 ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("HappyHourText").innerHTML = "Happy Hour Deactivated"; document.getElementById("SpecialHourText").style.opacity = "1";
document.getElementById("HappyHourText").animate({opacity: [ 0, 1 ], easing: [ 'ease-in', 'ease-out' ],}, 500); document.getElementById("SpecialHourHTML").animate({top: [ "-200px", "-250px" ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("HappyHourText").style.opacity = "1"; document.getElementById("SpecialHourHTML").style.top = "-250px";
document.getElementById("HappyHourHTML").animate({top: [ "-200px", "-250px" ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("HappyHourHTML").style.top = "-250px";
document.getElementById("container").style.backgroundImage = "-webkit-linear-gradient(-45deg, transparent 33%, rgba(0, 0, 0, .1) 33%, rgba(0,0, 0, .1) 66%, transparent 66%), -webkit-linear-gradient(top, rgba(255, 255, 255, .25), rgba(0, 0, 0, .25)), -webkit-linear-gradient(left, #0074cc, #a700cc)";
await sleep(5000) await sleep(5000)
document.getElementById("HappyHourText").animate({opacity: [ 1, 0 ], easing: [ 'ease-in', 'ease-out' ],}, 500); document.getElementById("SpecialHourText").animate({opacity: [ 1, 0 ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("HappyHourText").style.opacity = "0"; document.getElementById("SpecialHourText").style.opacity = "0";
} }
} }
async function specialHourFunc(type){
let activate = ((type === 'Happy' && !happy_hour_active) || (type === 'Random' && !random_hour_active));
let toggleText = activate ? 'Activated' : 'Deactivated';
logMessage("Core", `${type} Hour ${toggleText}`);
if (type === 'Happy') happy_hour_active = activate;
if (type === 'Random') random_hour_active = activate;
let animation = (happy_hour_active || random_hour_active) ? ', url(https://drive.google.com/uc?id=1oduFlPg84O1DliM5FsLvJJsnwZ4m1Vpm)' : '';
document.getElementById("SpecialHourText").innerHTML = `${type} Hour ${toggleText}!`;
document.getElementById("SpecialHourText").animate({opacity: [ 0, 1 ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("SpecialHourText").style.opacity = "1";
document.getElementById("SpecialHourHTML").animate({top: [ "-200px", "-250px" ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("SpecialHourHTML").style.top = "-250px";
document.getElementById("container").style.backgroundImage = `-webkit-linear-gradient(-45deg, transparent 33%, rgba(0, 0, 0, .1) 33%, rgba(0,0, 0, .1) 66%, transparent 66%), -webkit-linear-gradient(top, rgba(255, 255, 255, .25), rgba(0, 0, 0, .25))${animation}, -webkit-linear-gradient(left, #0074cc, #a700cc)`;
await sleep(activate ? 5000 : 10000);
document.getElementById("SpecialHourText").animate({opacity: [ 1, 0 ], easing: [ 'ease-in', 'ease-out' ],}, 500);
document.getElementById("SpecialHourText").style.opacity = "0";
}
let countdownEnded = false; let countdownEnded = false;
let users = []; let users = [];
@@ -198,8 +203,8 @@ 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!")
happyHourFunc() specialHourFunc()
setTimeout(happyHourFunc, 3600000) setTimeout(specialHourFunc, 3600000)
} }
setTimeout(randomHappy,1000) setTimeout(randomHappy,1000)
} }
@@ -211,8 +216,8 @@ function scheduleHappyFunc(){
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!")
happyHourFunc() specialHourFunc()
setTimeout(happyHourFunc, 3600000) setTimeout(specialHourFunc, 3600000)
setTimeout(scheduleHappyFunc, 36000000) setTimeout(scheduleHappyFunc, 36000000)
} }
} }