From d9130a4bcb10387db5251255a2442c79a3ceb1ed Mon Sep 17 00:00:00 2001 From: John Date: Wed, 11 May 2022 15:31:05 -0400 Subject: [PATCH] Adding styling dings for happy hour --- config.js | 5 ++++- css/style.css | 19 +++++++++++++++++ js/api/twitch.js | 18 ++++++++-------- js/script.js | 54 +++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 78 insertions(+), 18 deletions(-) diff --git a/config.js b/config.js index e648880..a7a4449 100644 --- a/config.js +++ b/config.js @@ -1,5 +1,8 @@ // Happy Hour -var happpy_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 + +// Bulk (if you want multiple subs to add to a big sum or each alone) +var bulk_enabled = true; // Login Data var twitch_channel_name = "" diff --git a/css/style.css b/css/style.css index ca65d86..cf4dae4 100644 --- a/css/style.css +++ b/css/style.css @@ -208,3 +208,22 @@ canvas { color:white; transition: top 1s ease-out, opacity .5s ease-out; } + +.gold { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + opacity: 0; + display: none; + z-index: 5; + font-weight: 400; + font-size: 3.25rem; + /*color: var(--background-color);*/ + color:gold; + background: linear-gradient(to right, #BF953F, #FCF6BA, #B38728, #FBF5B7, #AA771C); + -webkit-background-clip: text; + -webkit-text-fill-color: transparent; + transition: top 1s ease-out, opacity .5s ease-out; + text-shadow:none !important; +} diff --git a/js/api/twitch.js b/js/api/twitch.js index 1884d02..474c629 100644 --- a/js/api/twitch.js +++ b/js/api/twitch.js @@ -12,7 +12,7 @@ if (twitch_channel_name !== "") { client.on('subscription', (channel, username, methods, message, userstate) => { if (!countdownEnded) { - if(happpy_hour == true && happy_hour_active == false){ + if(happy_hour == true && happy_hour_active == false){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_sub_prime); @@ -32,7 +32,7 @@ if (twitch_channel_name !== "") { break; } } - else if(happpy_hour == true && happy_hour_active == true){ + else if(happy_hour == true && happy_hour_active == true){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_sub_prime_happy); @@ -52,7 +52,7 @@ if (twitch_channel_name !== "") { break; } } - else if(happpy_hour == false){ + else if(happy_hour == false){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_sub_prime); @@ -80,7 +80,7 @@ if (twitch_channel_name !== "") { client.on('resub', (channel, username, months, message, userstate, methods) => { if (!countdownEnded) { - if(happpy_hour == true && happy_hour_active == false){ + if(happy_hour == true && happy_hour_active == false){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_resub_prime); @@ -100,7 +100,7 @@ if (twitch_channel_name !== "") { break; } } - else if(happpy_hour == true && happy_hour_active == true){ + else if(happy_hour == true && happy_hour_active == true){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_resub_prime_happy); @@ -120,7 +120,7 @@ if (twitch_channel_name !== "") { break; } } - else if(happpy_hour == false){ + else if(happy_hour == false){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_resub_prime); @@ -148,7 +148,7 @@ if (twitch_channel_name !== "") { client.on('subgift', (channel, username, months, recipient, methods, userstate) => { if (!countdownEnded) { - if(happpy_hour == true && happy_hour_active == false){ + if(happy_hour == true && happy_hour_active == false){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_giftsub_prime); @@ -168,7 +168,7 @@ if (twitch_channel_name !== "") { break; } } - else if(happpy_hour == true && happy_hour_active == true){ + else if(happy_hour == true && happy_hour_active == true){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_giftsub_prime_happy); @@ -188,7 +188,7 @@ if (twitch_channel_name !== "") { break; } } - else if(happpy_hour == false){ + else if(happy_hour == false){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_giftsub_tier1); diff --git a/js/script.js b/js/script.js index 1dc4f02..188b146 100644 --- a/js/script.js +++ b/js/script.js @@ -78,7 +78,7 @@ Mousetrap.bind('ctrl+alt+p', function(e) { }); Mousetrap.bind('ctrl+alt+h', async function(e){ - if(happpy_hour == true && happy_hour_active == false){ + if(happy_hour == true && happy_hour_active == false){ logMessage("Core","Happy Hour activated"); happy_hour_active = true; document.getElementById("HappyHourText").innerHTML = "Happy Hour Activated!"; @@ -86,13 +86,12 @@ Mousetrap.bind('ctrl+alt+h', async function(e){ 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("HappyHourText").style.visibility = "visible"; 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(happpy_hour == true && happy_hour_active == true){ + else if(happy_hour == true && happy_hour_active == true){ logMessage("Core", "Happy Hour deactivated") happy_hour_active = false; document.getElementById("HappyHourText").innerHTML = "Happy Hour Deactivated"; @@ -105,7 +104,7 @@ Mousetrap.bind('ctrl+alt+h', async function(e){ document.getElementById("HappyHourText").animate({opacity: [ 1, 0 ], easing: [ 'ease-in', 'ease-out' ],}, 500); document.getElementById("HappyHourText").style.opacity = "0"; } - else if(happpy_hour == false){ + else if(happy_hour == false){ 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); @@ -153,9 +152,48 @@ let countdownUpdater = setInterval(() => { }, 1); +var firstSub = true; +var endingTimeBeforeCounter; +var addedTimeCounter; +var timeoutID; + const addTime = async (time, s) => { + if(!bulk_enabled) { + endingTimeBeforeCounter = time; + addedTimeCounter = s; + addTimeInternal(); + return; + } + if(firstSub) { + firstSub = false; + endingTimeBeforeCounter = time; + addedTimeCounter = s; + } else { + addedTimeCounter += s; + window.clearTimeout(timeoutID); + } + timeoutID = window.setTimeout(addTimeInternal, 1000); +}; + +const addTimeInternal = async () => { + let time = endingTimeBeforeCounter; + let s = addedTimeCounter; + addedTimeCounter = 0; + firstSub = true; + let addedTime = document.createElement("p"); - addedTime.classList = "addedTime"; + if(happy_hour == true && happy_hour_active == true) { + addedTime.classList = "gold"; + } + else if(happy_hour == true && happy_hour_active == false) { + addedTime.classList = "addedTime"; + } + else if(happy_hour == false && happy_hour_active == true) { + addedTime.classList = "addedTime"; + } + else if(happy_hour == false && happy_hour_active == false) { + addedTime.classList = "addedTime"; + } addedTime.innerText = `+${s}s`; document.body.appendChild(addedTime); addedTime.style.display = "block"; @@ -163,17 +201,17 @@ const addTime = async (time, s) => { addedTime.style.left = `${randomInRange(35, 65)}%`; addedTime.style.top = `${randomInRange(15, 40)}%`; addedTime.style.opacity = "1"; - while(s > 0){ + while(s > 0){ timeStep = s > 60 ? s/30 : 2 endingTime = timeFunc.addSeconds(time, timeStep) await sleep(50); s -= timeStep - } + } await sleep(200); addedTime.style.opacity = "0"; await sleep(200); addedTime.remove(); -}; +} const testAddTime = (times, delay, s) => { let addTimeInterval = setInterval(async () => {