From 5a89ede16b2d4285f2679b9706729e3342c1faae Mon Sep 17 00:00:00 2001 From: Danilo Titato Date: Wed, 1 Mar 2023 16:33:46 -0300 Subject: [PATCH] Add random hour visual toggle --- config.js | 2 ++ css/style.css | 6 ++-- index.html | 8 ++--- js/script.js | 91 +++++++++++++++++++++++++++------------------------ 4 files changed, 57 insertions(+), 50 deletions(-) diff --git a/config.js b/config.js index 4737c33..9c76a70 100644 --- a/config.js +++ b/config.js @@ -1,5 +1,6 @@ // Happy Hour 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 scheduleHappy = false // only works if happy_hour = true @@ -13,6 +14,7 @@ var bulk_enabled = false //Shortcuts var pauseShort = "ctrl+alt+p" var happyHourShort = "ctrl+alt+h" +var randomHourShort = "ctrl+alt+r" // Login Data var twitch_channel_name = "" diff --git a/css/style.css b/css/style.css index cf4dae4..144cb1d 100644 --- a/css/style.css +++ b/css/style.css @@ -44,9 +44,9 @@ body { visibility: hidden; } -#HappyHourText { +#SpecialHourText { opacity: 0; - font-size: 2.8rem; + font-size: 2.5rem; display: flex; justify-content: center; align-items: center; @@ -71,7 +71,7 @@ body { height: 100%; } */ -#HappyHourHTML { +#SpecialHourHTML { top:-200px; position: relative; } diff --git a/index.html b/index.html index 53c274f..2b092e7 100644 --- a/index.html +++ b/index.html @@ -23,10 +23,10 @@

00:00:00

-
-

Happy Hour Activated!

- +
+

Happy Hour Activated!

+
diff --git a/js/script.js b/js/script.js index 5f6532b..bd866f1 100644 --- a/js/script.js +++ b/js/script.js @@ -5,6 +5,7 @@ var initialMinutes; var initialSeconds; var paused = false; var happy_hour_active = false; +var random_hour_active = false; var initialHoursLocal = window.localStorage.getItem('initialHours') if(initialHoursLocal !== null) { @@ -96,52 +97,56 @@ Mousetrap.bind(pauseShort, function(e) { }); Mousetrap.bind(happyHourShort, async function(e){ - if(happy_hour){ - 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"; - } + specialHourHandler('Happy'); }); -async function happyHourFunc(){ - if(!happy_hour_active){ - logMessage("Core","Happy Hour activated"); - happy_hour_active = true; - document.getElementById("HappyHourText").innerHTML = "Happy Hour Activated!"; - 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"; - 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"; +Mousetrap.bind(randomHourShort, async function(e){ + specialHourHandler('Random'); +}); + +async function specialHourHandler(type){ + if((type === 'Happy' && happy_hour) || (type === 'Random' && random_hour)){ + specialHourFunc(type) } - else if(happy_hour_active){ - logMessage("Core", "Happy Hour deactivated") - clearTimeout(happyHourFunc) - happy_hour_active = false; - document.getElementById("HappyHourText").innerHTML = "Happy Hour Deactivated"; - 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"; - 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)"; + else { + logMessage("Core", `${type} Hour is not available`) + document.getElementById("SpecialHourText").innerHTML = `${type} Hour error`; + 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"; await sleep(5000) - document.getElementById("HappyHourText").animate({opacity: [ 1, 0 ], easing: [ 'ease-in', 'ease-out' ],}, 500); - document.getElementById("HappyHourText").style.opacity = "0"; + document.getElementById("SpecialHourText").animate({opacity: [ 1, 0 ], easing: [ 'ease-in', 'ease-out' ],}, 500); + 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 users = []; @@ -198,8 +203,8 @@ function randomHappy(){ if(!happy_hour_active){ if((getRandomInt(0,10000) == 127)){ logMessage("RandomHappy","It's not rigged!") - happyHourFunc() - setTimeout(happyHourFunc, 3600000) + specialHourFunc() + setTimeout(specialHourFunc, 3600000) } setTimeout(randomHappy,1000) } @@ -211,8 +216,8 @@ function scheduleHappyFunc(){ if(now.getUTCHours() == scheduleHappyHour){ if(now.getUTCMinutes() == 00){ logMessage("Schedule","It's time!") - happyHourFunc() - setTimeout(happyHourFunc, 3600000) + specialHourFunc() + setTimeout(specialHourFunc, 3600000) setTimeout(scheduleHappyFunc, 36000000) } }