From 386fee2a840e8ab611d96f2dab10052271d64018 Mon Sep 17 00:00:00 2001 From: Lea Date: Wed, 1 Mar 2023 12:25:05 +0100 Subject: [PATCH] ReUp of correct files, made a mistake merged with an older version (I think), so here the correct files again --- README.md | 8 +- config.js | 71 +++++++---- js/api/streamelements.js | 90 ++++++++++++- js/api/streamlabs.js | 266 ++++++++++++++++++++++++++------------- js/api/streamloots.js | 63 +++++++--- js/api/twitch.js | 104 +++++---------- js/script.js | 147 +++++++++++++++------- 7 files changed, 499 insertions(+), 250 deletions(-) diff --git a/README.md b/README.md index 9712c5f..5b8b6d4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

Twitch Subathon Countdown Template

+

Improved Twitch Subathon Countdown

This is a Twitch Subathon Countdown originally by JayexDesigns.

The CSS Code is updated by Johnnycyan. The JS Files are updated by leabdd to add functionalities.


@@ -12,6 +12,7 @@

Shortcuts

To pause the Timer: CTRL+ALT+P

To enable/disable Happy Hour: CTRL+ALT+H

+

Shortcuts can be changed in config.js


Preview

@@ -42,11 +43,16 @@

Happy Hour

If this is true, you can turn enable Happy Hour with the Shortcut. If it is false, the feature is disabled and cant be enabled.

You have to set the Happy Hour time values manually.

+

If enabled it can randomly activate the Happy Hour. It will last for one hour, but can be turned off manually with the Shortkey.

+

In the Config you can set a specific Date and Time. At that a Happy Hour will happen.

Bulk

This enables that multiple Subs get added to the timer at once.

For Example when a user gifts 10 Subs.

+

Full control on what to use

+

You can enable and disable if you want to add time for Subscriptions, Bits, Donations or Chests.

+

Other Values

Change the other values to set the amount of seconds that will be added for the subscriptions, donations... And the minimum donation amounts to trigger the countdown increase.

diff --git a/config.js b/config.js index a7a4449..4737c33 100644 --- a/config.js +++ b/config.js @@ -1,8 +1,18 @@ // 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 randHappy = false // only works if happy_hour = true +var scheduleHappy = false // only works if happy_hour = true + +// needs scheduleHappy to be true +var scheduleHappyDay = 5 // Weekdays from 0 to 6 from Sunday to Saturday | Default 5 is Friday +var scheduleHappyHour = 18 // Hours in 24 format UTC Time | Default 18 is 20:00 CEST // Bulk (if you want multiple subs to add to a big sum or each alone) -var bulk_enabled = true; +var bulk_enabled = false + +//Shortcuts +var pauseShort = "ctrl+alt+p" +var happyHourShort = "ctrl+alt+h" // Login Data var twitch_channel_name = "" @@ -15,6 +25,12 @@ var initialHoursConfig = 2 var initialMinutesConfig = 0 var initialSecondsConfig = 0 +// Enable/Disable Subs, Bits, Donations, Chests +var subEnable = true +var bitEnable = false +var donationEnable = false +var chestEnable = false + // General Twitch, Streamlabs And StreamElements Config var seconds_added_per_sub_prime = 60 var seconds_added_per_sub_tier1 = 60 @@ -30,28 +46,37 @@ var seconds_added_per_giftsub_tier1 = 60 var seconds_added_per_giftsub_tier2 = 180 var seconds_added_per_giftsub_tier3 = 480 -// General Twitch, Streamlabs And StreamElements Config for Happy Hour -var seconds_added_per_sub_prime_happy = 120 -var seconds_added_per_sub_tier1_happy = 120 -var seconds_added_per_sub_tier2_happy = 360 -var seconds_added_per_sub_tier3_happy = 960 - -var seconds_added_per_resub_prime_happy = 120 -var seconds_added_per_resub_tier1_happy = 120 -var seconds_added_per_resub_tier2_happy = 360 -var seconds_added_per_resub_tier3_happy = 960 - -var seconds_added_per_giftsub_tier1_happy = 120 -var seconds_added_per_giftsub_tier2_happy = 360 -var seconds_added_per_giftsub_tier3_happy = 960 - -// var min_amount_of_bits = 500 -// var seconds_added_per_bits = 30 +var min_amount_of_bits = 50 +var seconds_added_per_bits = 30 // Streamlabs And StreamElements Config -// var min_donation_amount = 5 -// var seconds_added_per_donation = 30 +var min_donation_amount = 1 +var seconds_added_per_donation = 30 // Streamloots Config -// var min_amount_of_chests = 5 -// var seconds_added_per_chests = 30 +var min_amount_of_chests = 1 +var seconds_added_per_chests = 30 + + +// General Twitch, Streamlabs And StreamElements Config for Happy Hour +var seconds_added_per_sub_prime_happy = 85 +var seconds_added_per_sub_tier1_happy = 85 +var seconds_added_per_sub_tier2_happy = 300 +var seconds_added_per_sub_tier3_happy = 960 + +var seconds_added_per_resub_prime_happy = 85 +var seconds_added_per_resub_tier1_happy = 85 +var seconds_added_per_resub_tier2_happy = 300 +var seconds_added_per_resub_tier3_happy = 960 + +var seconds_added_per_giftsub_tier1_happy = 85 +var seconds_added_per_giftsub_tier2_happy = 300 +var seconds_added_per_giftsub_tier3_happy = 960 + +var seconds_added_per_bits_happy = 60 + +// Streamlabs And StreamElements Config +var seconds_added_per_donation_happy = 60 + +// Streamloots Config +var seconds_added_per_chests_happy = 60 diff --git a/js/api/streamelements.js b/js/api/streamelements.js index a2a1b09..fe35118 100644 --- a/js/api/streamelements.js +++ b/js/api/streamelements.js @@ -34,8 +34,8 @@ if (streamelements_token !== "") { function onEvent(data) { logObject("StreamElements", data); - if (!countdownEnded) { - if (data['listener'] === "subscriber-latest") { + if (!countdownEnded && !happy_hour_active) { + if ((data['listener'] === "subscriber-latest") && subEnable) { if (data['event']['gifted'] || data['event']['bulkGifted']) { let amount; if (data['event']['gifted']) amount = 1; @@ -94,7 +94,7 @@ if (streamelements_token !== "") { } } - else if (data['listener'] === "cheer-latest") { + else if ((data['listener'] === "cheer-latest") && bitEnable) { if (data['event']['amount'] >= min_amount_of_bits) { let times = Math.floor(data['event']['amount']/min_amount_of_bits); addTime(endingTime, seconds_added_per_bits * times); @@ -105,7 +105,7 @@ if (streamelements_token !== "") { } } - else if (data['listener'] === "tip-latest") { + else if ((data['listener'] === "tip-latest") && donationEnable) { if (data['event']['amount'] >= min_donation_amount) { let times = Math.floor(data['event']['amount']/min_donation_amount); addTime(endingTime, seconds_added_per_donation * times); @@ -116,6 +116,88 @@ if (streamelements_token !== "") { } } } + else if (!countdownEnded && happy_hour_active) { + if ((data['listener'] === "subscriber-latest") && subEnable) { + if (data['event']['gifted'] || data['event']['bulkGifted']) { + let amount; + if (data['event']['gifted']) amount = 1; + else amount = data['event']['amount']; + if (data['event']['tier'] == "prime" || data['event']['tier'] == "1000") { + addTime(endingTime, seconds_added_per_giftsub_tier1_happy * amount); + logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier1_happy * amount} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 1 Subs`); + } + else if (data['event']['tier'] == "2000") { + addTime(endingTime, seconds_added_per_giftsub_tier2_happy * amount); + logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier2_happy * amount} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 2 Subs`); + } + else if (data['event']['tier'] == "3000") { + addTime(endingTime, seconds_added_per_giftsub_tier3_happy * amount); + logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier3_happy * amount} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 3 Subs`); + } + } + else if (data['event']['amount'] != "1") { + if (data['event']['tier'] == "prime") { + addTime(endingTime, seconds_added_per_resub_prime_happy); + logMessage("StreamElements", `Added ${seconds_added_per_resub_prime_happy} Seconds Because ${data['event']['name']} ReSubscribed With Prime`); + } + else if (data['event']['tier'] == "1000") { + addTime(endingTime, seconds_added_per_resub_tier1_happy); + logMessage("StreamElements", `Added ${seconds_added_per_resub_tier1_happy} Seconds Because ${data['event']['name']} ReSubscribed With Tier 1`); + } + else if (data['event']['tier'] == "2000") { + addTime(endingTime, seconds_added_per_resub_tier2_happy); + logMessage("StreamElements", `Added ${seconds_added_per_resub_tier2_happy} Seconds Because ${data['event']['name']} ReSubscribed With Tier 2`); + } + else if (data['event']['tier'] == "3000") { + addTime(endingTime, seconds_added_per_resub_tier3_happy); + logMessage("StreamElements", `Added ${seconds_added_per_resub_tier3_happy} Seconds Because ${data['event']['name']} ReSubscribed With Tier 3`); + } + } + else { + if (data['event']['tier'] == "prime") { + addTime(endingTime, seconds_added_per_sub_prime_happy); + logMessage("StreamElements", `Added ${seconds_added_per_sub_prime_happy} Seconds Because ${data['event']['name']} Subscribed With Prime`); + } + else if (data['event']['tier'] == "1000") { + addTime(endingTime, seconds_added_per_sub_tier1_happy); + logMessage("StreamElements", `Added ${seconds_added_per_sub_tier1_happy} Seconds Because ${data['event']['name']} Subscribed With Tier 1`); + } + else if (data['event']['tier'] == "2000") { + addTime(endingTime, seconds_added_per_sub_tier2_happy); + logMessage("StreamElements", `Added ${seconds_added_per_sub_tier2_happy} Seconds Because ${data['event']['name']} Subscribed With Tier 2`); + } + else if (data['event']['tier'] == "3000") { + addTime(endingTime, seconds_added_per_sub_tier3_happy); + logMessage("StreamElements", `Added ${seconds_added_per_sub_tier3_happy} Seconds Because ${data['event']['name']} Subscribed With Tier 3`); + } + } + if (!users.includes(data['event']['name'])) { + users.push(data['event']['name']); + } + } + + else if ((data['listener'] === "cheer-latest") && bitEnable) { + if (data['event']['amount'] >= min_amount_of_bits) { + let times = Math.floor(data['event']['amount']/min_amount_of_bits); + addTime(endingTime, seconds_added_per_bits_happy * times); + logMessage("StreamElements", `Added ${seconds_added_per_bits_happy * times} Seconds Because ${data['event']['name']} Donated ${data['event']['amount']} Bits`); + if (!users.includes(data['event']['name'])) { + users.push(data['event']['name']); + } + } + } + + else if ((data['listener'] === "tip-latest") && donationEnable) { + if (data['event']['amount'] >= min_donation_amount) { + let times = Math.floor(data['event']['amount']/min_donation_amount); + addTime(endingTime, seconds_added_per_donation_happy * times); + logMessage("StreamElements", `Added ${seconds_added_per_donation_happy * times} Seconds Because ${data['event']['name']} Donated ${data['event']['amount']}$`); + if (!users.includes(data['event']['name'])) { + users.push(data['event']['name']); + } + } + } + } } } streamElementsConnect(); diff --git a/js/api/streamlabs.js b/js/api/streamlabs.js index 63f74f6..466000d 100644 --- a/js/api/streamlabs.js +++ b/js/api/streamlabs.js @@ -8,85 +8,45 @@ if (streamlabs_token !== "") { socket.on("event", (event) => { logObject("Streamlabs", event); if (event.type == "subscription" && !event.message[0].gifter) { - if (!countdownEnded) { - if (event.message[0].sub_plan == "1000") { - addTime(endingTime, seconds_added_per_sub_tier1); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier1} Seconds Because ${event.message[0].name} Subscribed With Tier 1`); + if (!countdownEnded && subEnable) { + if(!happy_hour_active){ + if (event.message[0].sub_plan == "1000") { + addTime(endingTime, seconds_added_per_sub_tier1); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier1} Seconds Because ${event.message[0].name} Subscribed With Tier 1`); + } + else if (event.message[0].sub_plan == "2000") { + addTime(endingTime, seconds_added_per_sub_tier2); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier2} Seconds Because ${event.message[0].name} Subscribed With Tier 2`); + } + else if (event.message[0].sub_plan == "3000") { + addTime(endingTime, seconds_added_per_sub_tier3); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier3} Seconds Because ${event.message[0].name} Subscribed With Tier 3`); + } + else { + addTime(endingTime, seconds_added_per_sub_prime); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_prime} Seconds Because ${event.message[0].name} Subscribed With Prime`); + } + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); + } } - else if (event.message[0].sub_plan == "2000") { - addTime(endingTime, seconds_added_per_sub_tier2); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier2} Seconds Because ${event.message[0].name} Subscribed With Tier 2`); - } - else if (event.message[0].sub_plan == "3000") { - addTime(endingTime, seconds_added_per_sub_tier3); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier3} Seconds Because ${event.message[0].name} Subscribed With Tier 3`); - } - else { - addTime(endingTime, seconds_added_per_sub_prime); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_prime} Seconds Because ${event.message[0].name} Subscribed With Prime`); - } - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } - } - } - - else if (event.type == "resub" && !event.message[0].gifter) { - if (!countdownEnded) { - if (event.message[0].sub_plan == "1000") { - addTime(endingTime, seconds_added_per_resub_tier1); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier1} Seconds Because ${event.message[0].name} ReSubscribed With Tier 1`); - } - else if (event.message[0].sub_plan == "2000") { - addTime(endingTime, seconds_added_per_resub_tier2); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier2} Seconds Because ${event.message[0].name} ReSubscribed With Tier 2`); - } - else if (event.message[0].sub_plan == "3000") { - addTime(endingTime, seconds_added_per_resub_tier3); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier3} Seconds Because ${event.message[0].name} ReSubscribed With Tier 3`); - } - else { - addTime(endingTime, seconds_added_per_resub_prime); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_prime} Seconds Because ${event.message[0].name} ReSubscribed With Prime`); - } - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } - } - } - - else if (event.message[0].gifter) { - if (!countdownEnded) { - if (event.message[0].sub_plan == "1000") { - addTime(endingTime, seconds_added_per_giftsub_tier1); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier1} Seconds Because ${event.message[0].gifter} Gifted A Tier 1 Sub`); - } - else if (event.message[0].sub_plan == "2000") { - addTime(endingTime, seconds_added_per_giftsub_tier2); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier2} Seconds Because ${event.message[0].gifter} Gifted A Tier 2 Sub`); - } - else if (event.message[0].sub_plan == "3000") { - addTime(endingTime, seconds_added_per_giftsub_tier3); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier3} Seconds Because ${event.message[0].gifter} Gifted A Tier 3 Sub`); - } - else { - addTime(endingTime, seconds_added_per_giftsub_tier1); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier1} Seconds Because ${event.message[0].gifter} Gifted A Tier 1 Sub`); - } - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } - } - } - - else if (event.type == "donation") { - if (!countdownEnded) { - let dono = parseInt(event.message[0].amount); - let currency = event.message[0].currency; - if (dono >= min_donation_amount) { - let times = Math.floor(dono/min_donation_amount); - addTime(endingTime, seconds_added_per_donation * times); - logMessage("Streamlabs", `Added ${seconds_added_per_donation * times} Seconds Because ${event.message[0].name} Donated ${dono} ${currency}`); + else if(!happy_hour_active){ + if (event.message[0].sub_plan == "1000") { + addTime(endingTime, seconds_added_per_sub_tier1_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier1_happy} Seconds Because ${event.message[0].name} Subscribed With Tier 1`); + } + else if (event.message[0].sub_plan == "2000") { + addTime(endingTime, seconds_added_per_sub_tier2_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier2_happy} Seconds Because ${event.message[0].name} Subscribed With Tier 2`); + } + else if (event.message[0].sub_plan == "3000") { + addTime(endingTime, seconds_added_per_sub_tier3_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier3_happy} Seconds Because ${event.message[0].name} Subscribed With Tier 3`); + } + else { + addTime(endingTime, seconds_added_per_sub_prime_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_prime_happy} Seconds Because ${event.message[0].name} Subscribed With Prime`); + } if (!users.includes(event.message[0].name)) { users.push(event.message[0].name); } @@ -94,17 +54,153 @@ if (streamlabs_token !== "") { } } - else if (event.type == "bits") { - if (!countdownEnded) { - let bits = parseInt(event.message[0].amount); - if (bits >= min_amount_of_bits) { - let times = Math.floor(bits/min_amount_of_bits); - addTime(endingTime, seconds_added_per_bits * times); - logMessage("Streamlabs", `Added ${seconds_added_per_bits * times} Seconds Because ${event.message[0].name} Donated ${bits} Bits`); + else if (event.type == "resub" && !event.message[0].gifter) { + if (!countdownEnded && subEnable) { + if(!happy_hour_active){ + if (event.message[0].sub_plan == "1000") { + addTime(endingTime, seconds_added_per_resub_tier1); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier1} Seconds Because ${event.message[0].name} ReSubscribed With Tier 1`); + } + else if (event.message[0].sub_plan == "2000") { + addTime(endingTime, seconds_added_per_resub_tier2); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier2} Seconds Because ${event.message[0].name} ReSubscribed With Tier 2`); + } + else if (event.message[0].sub_plan == "3000") { + addTime(endingTime, seconds_added_per_resub_tier3); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier3} Seconds Because ${event.message[0].name} ReSubscribed With Tier 3`); + } + else { + addTime(endingTime, seconds_added_per_resub_prime); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_prime} Seconds Because ${event.message[0].name} ReSubscribed With Prime`); + } if (!users.includes(event.message[0].name)) { users.push(event.message[0].name); } } + else if(!happy_hour_active){ + if (event.message[0].sub_plan == "1000") { + addTime(endingTime, seconds_added_per_resub_tier1_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier1_happy} Seconds Because ${event.message[0].name} ReSubscribed With Tier 1`); + } + else if (event.message[0].sub_plan == "2000") { + addTime(endingTime, seconds_added_per_resub_tier2_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier2_happy} Seconds Because ${event.message[0].name} ReSubscribed With Tier 2`); + } + else if (event.message[0].sub_plan == "3000") { + addTime(endingTime, seconds_added_per_resub_tier3_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier3_happy} Seconds Because ${event.message[0].name} ReSubscribed With Tier 3`); + } + else { + addTime(endingTime, seconds_added_per_resub_prime_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_prime_happy} Seconds Because ${event.message[0].name} ReSubscribed With Prime`); + } + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); + } + } + } + } + + else if (event.message[0].gifter) { + if (!countdownEnded && subEnable) { + if(!happy_hour_active){ + if (event.message[0].sub_plan == "1000") { + addTime(endingTime, seconds_added_per_giftsub_tier1); + logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier1} Seconds Because ${event.message[0].gifter} Gifted A Tier 1 Sub`); + } + else if (event.message[0].sub_plan == "2000") { + addTime(endingTime, seconds_added_per_giftsub_tier2); + logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier2} Seconds Because ${event.message[0].gifter} Gifted A Tier 2 Sub`); + } + else if (event.message[0].sub_plan == "3000") { + addTime(endingTime, seconds_added_per_giftsub_tier3); + logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier3} Seconds Because ${event.message[0].gifter} Gifted A Tier 3 Sub`); + } + else { + addTime(endingTime, seconds_added_per_giftsub_tier1); + logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier1} Seconds Because ${event.message[0].gifter} Gifted A Tier 1 Sub`); + } + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); + } + } + else if(happy_hour_active){ + if (event.message[0].sub_plan == "1000") { + addTime(endingTime, seconds_added_per_giftsub_tier1_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier1_happy} Seconds Because ${event.message[0].gifter} Gifted A Tier 1 Sub`); + } + else if (event.message[0].sub_plan == "2000") { + addTime(endingTime, seconds_added_per_giftsub_tier2_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier2_happy} Seconds Because ${event.message[0].gifter} Gifted A Tier 2 Sub`); + } + else if (event.message[0].sub_plan == "3000") { + addTime(endingTime, seconds_added_per_giftsub_tier3_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier3_happy} Seconds Because ${event.message[0].gifter} Gifted A Tier 3 Sub`); + } + else { + addTime(endingTime, seconds_added_per_giftsub_tier1_happy); + logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier1_happy} Seconds Because ${event.message[0].gifter} Gifted A Tier 1 Sub`); + } + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); + } + } + } + } + + else if (event.type == "donation") { + if (!countdownEnded && donationEnable) { + if(!happy_hour_active){ + let dono = parseInt(event.message[0].amount); + let currency = event.message[0].currency; + if (dono >= min_donation_amount) { + let times = Math.floor(dono/min_donation_amount); + addTime(endingTime, seconds_added_per_donation * times); + logMessage("Streamlabs", `Added ${seconds_added_per_donation * times} Seconds Because ${event.message[0].name} Donated ${dono} ${currency}`); + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); + } + } + } + else if(happy_hour_active){ + let dono = parseInt(event.message[0].amount); + let currency = event.message[0].currency; + if (dono >= min_donation_amount) { + let times = Math.floor(dono/min_donation_amount); + addTime(endingTime, seconds_added_per_donation_happy * times); + logMessage("Streamlabs", `Added ${seconds_added_per_donation_happy * times} Seconds Because ${event.message[0].name} Donated ${dono} ${currency}`); + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); + } + } + } + } + } + + else if (event.type == "bits") { + if (!countdownEnded && donationEnable) { + if(!happy_hour_active){ + let bits = parseInt(event.message[0].amount); + if (bits >= min_amount_of_bits) { + let times = Math.floor(bits/min_amount_of_bits); + addTime(endingTime, seconds_added_per_bits * times); + logMessage("Streamlabs", `Added ${seconds_added_per_bits * times} Seconds Because ${event.message[0].name} Donated ${bits} Bits`); + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); + } + } + } + else if(happy_hour_active){ + let bits = parseInt(event.message[0].amount); + if (bits >= min_amount_of_bits) { + let times = Math.floor(bits/min_amount_of_bits); + addTime(endingTime, seconds_added_per_bits_happy * times); + logMessage("Streamlabs", `Added ${seconds_added_per_bits_happy * times} Seconds Because ${event.message[0].name} Donated ${bits} Bits`); + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); + } + } + } } } }); diff --git a/js/api/streamloots.js b/js/api/streamloots.js index 55cdaed..3d412bd 100644 --- a/js/api/streamloots.js +++ b/js/api/streamloots.js @@ -6,27 +6,54 @@ if (streamloots_token !== "") { data = await JSON.parse(event.data); logObject("Streamloots", data); if (data.data.type == "purchase") { - if (!countdownEnded) { - let chests; - if (typeof(data.data.fields[0].value) == "number") { - chests = data.data.fields[0].value; - if (chests >= min_amount_of_chests) { - let times = Math.floor(chests/min_amount_of_chests); - addTime(endingTime, seconds_added_per_chests * times); - logMessage("Streamloots", `Added ${seconds_added_per_chests * times} Seconds Because ${data.data.fields[1].value} Bought ${chests} Chests`); - if (!users.includes(data.data.fields[1].value)) { - users.push(data.data.fields[1].value); + if (!countdownEnded && chestEnable) { + if(!happy_hour_active){ + let chests; + if (typeof(data.data.fields[0].value) == "number") { + chests = data.data.fields[0].value; + if (chests >= min_amount_of_chests) { + let times = Math.floor(chests/min_amount_of_chests); + addTime(endingTime, seconds_added_per_chests * times); + logMessage("Streamloots", `Added ${seconds_added_per_chests * times} Seconds Because ${data.data.fields[1].value} Bought ${chests} Chests`); + if (!users.includes(data.data.fields[1].value)) { + users.push(data.data.fields[1].value); + } + } + } + else { + chests = data.data.fields[1].value; + if (chests >= min_amount_of_chests) { + let times = Math.floor(chests/min_amount_of_chests); + addTime(endingTime, seconds_added_per_chests * times); + logMessage("Streamloots", `Added ${seconds_added_per_chests * times} Seconds Because ${data.data.fields[0].value} Gifted ${chests} Chests`); + if (!users.includes(data.data.fields[0].value)) { + users.push(data.data.fields[0].value); + } } } } - else { - chests = data.data.fields[1].value; - if (chests >= min_amount_of_chests) { - let times = Math.floor(chests/min_amount_of_chests); - addTime(endingTime, seconds_added_per_chests * times); - logMessage("Streamloots", `Added ${seconds_added_per_chests * times} Seconds Because ${data.data.fields[0].value} Gifted ${chests} Chests`); - if (!users.includes(data.data.fields[0].value)) { - users.push(data.data.fields[0].value); + if(happy_hour_active){ + let chests; + if (typeof(data.data.fields[0].value) == "number") { + chests = data.data.fields[0].value; + if (chests >= min_amount_of_chests) { + let times = Math.floor(chests/min_amount_of_chests); + addTime(endingTime, seconds_added_per_chests_happy * times); + logMessage("Streamloots", `Added ${seconds_added_per_chests_happy * times} Seconds Because ${data.data.fields[1].value} Bought ${chests} Chests`); + if (!users.includes(data.data.fields[1].value)) { + users.push(data.data.fields[1].value); + } + } + } + else { + chests = data.data.fields[1].value; + if (chests >= min_amount_of_chests) { + let times = Math.floor(chests/min_amount_of_chests); + addTime(endingTime, seconds_added_per_chests_happy * times); + logMessage("Streamloots", `Added ${seconds_added_per_chests_happy * times} Seconds Because ${data.data.fields[0].value} Gifted ${chests} Chests`); + if (!users.includes(data.data.fields[0].value)) { + users.push(data.data.fields[0].value); + } } } } diff --git a/js/api/twitch.js b/js/api/twitch.js index 474c629..9e0182e 100644 --- a/js/api/twitch.js +++ b/js/api/twitch.js @@ -11,8 +11,8 @@ if (twitch_channel_name !== "") { logMessage("Twitch", `Client Connected`); client.on('subscription', (channel, username, methods, message, userstate) => { - if (!countdownEnded) { - if(happy_hour == true && happy_hour_active == false){ + if (!countdownEnded && subEnable) { + if(!happy_hour_active){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_sub_prime); @@ -32,7 +32,7 @@ if (twitch_channel_name !== "") { break; } } - else if(happy_hour == true && happy_hour_active == true){ + else if(happy_hour_active){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_sub_prime_happy); @@ -52,26 +52,6 @@ if (twitch_channel_name !== "") { break; } } - else if(happy_hour == false){ - switch (methods['plan']) { - case "Prime": - addTime(endingTime, seconds_added_per_sub_prime); - logMessage("Twitch", `Added ${seconds_added_per_sub_prime} Seconds Because ${username} Subscribed With Prime`); - break; - case "1000": - addTime(endingTime, seconds_added_per_sub_tier1); - logMessage("Twitch", `Added ${seconds_added_per_sub_tier1} Seconds Because ${username} Subscribed With Tier 1`); - break; - case "2000": - addTime(endingTime, seconds_added_per_sub_tier2); - logMessage("Twitch", `Added ${seconds_added_per_sub_tier2} Seconds Because ${username} Subscribed With Tier 2`); - break; - case "3000": - addTime(endingTime, seconds_added_per_sub_tier3); - logMessage("Twitch", `Added ${seconds_added_per_sub_tier3} Seconds Because ${username} Subscribed With Tier 3`); - break; - } - } if (!users.includes(username)) { users.push(username); } @@ -79,8 +59,8 @@ if (twitch_channel_name !== "") { }); client.on('resub', (channel, username, months, message, userstate, methods) => { - if (!countdownEnded) { - if(happy_hour == true && happy_hour_active == false){ + if (!countdownEnded && subEnable) { + if(!happy_hour_active){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_resub_prime); @@ -100,7 +80,7 @@ if (twitch_channel_name !== "") { break; } } - else if(happy_hour == true && happy_hour_active == true){ + else if(happy_hour_active){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_resub_prime_happy); @@ -120,26 +100,6 @@ if (twitch_channel_name !== "") { break; } } - else if(happy_hour == false){ - switch (methods['plan']) { - case "Prime": - addTime(endingTime, seconds_added_per_resub_prime); - logMessage("Twitch", `Added ${seconds_added_per_resub_prime} Seconds Because ${username} ReSubscribed With Prime`); - break; - case "1000": - addTime(endingTime, seconds_added_per_resub_tier1); - logMessage("Twitch", `Added ${seconds_added_per_resub_tier1} Seconds Because ${username} ReSubscribed With Tier 1`); - break; - case "2000": - addTime(endingTime, seconds_added_per_resub_tier2); - logMessage("Twitch", `Added ${seconds_added_per_resub_tier2} Seconds Because ${username} ReSubscribed With Tier 2`); - break; - case "3000": - addTime(endingTime, seconds_added_per_resub_tier3); - logMessage("Twitch", `Added ${seconds_added_per_resub_tier3} Seconds Because ${username} ReSubscribed With Tier 3`); - break; - } - } if (!users.includes(username)) { users.push(username); } @@ -147,8 +107,8 @@ if (twitch_channel_name !== "") { }); client.on('subgift', (channel, username, months, recipient, methods, userstate) => { - if (!countdownEnded) { - if(happy_hour == true && happy_hour_active == false){ + if (!countdownEnded && subEnable) { + if(!happy_hour_active){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_giftsub_prime); @@ -168,7 +128,7 @@ if (twitch_channel_name !== "") { break; } } - else if(happy_hour == true && happy_hour_active == true){ + else if(happy_hour_active){ switch (methods['plan']) { case "Prime": addTime(endingTime, seconds_added_per_giftsub_prime_happy); @@ -188,26 +148,6 @@ if (twitch_channel_name !== "") { break; } } - else if(happy_hour == false){ - switch (methods['plan']) { - case "Prime": - addTime(endingTime, seconds_added_per_giftsub_tier1); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier1} Seconds Because ${username} gifted Sub With Prime`); - break; - case "1000": - addTime(endingTime, seconds_added_per_giftsub_tier1); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier1} Seconds Because ${username} gifted Sub With Tier 1`); - break; - case "2000": - addTime(endingTime, seconds_added_per_giftsub_tier2); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier2} Seconds Because ${username} gifted Sub With Tier 2`); - break; - case "3000": - addTime(endingTime, seconds_added_per_giftsub_tier3); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier3} Seconds Because ${username} gifted Sub With Tier 3`); - break; - } - } if (!users.includes(username)) { users.push(username); } @@ -215,13 +155,25 @@ if (twitch_channel_name !== "") { }); client.on('cheer', (channel, userstate, message) => { - if (!countdownEnded) { - if (userstate.bits >= min_amount_of_bits) { - let times = Math.floor(userstate.bits/min_amount_of_bits); - addTime(endingTime, seconds_added_per_bits * times); - logMessage("Twitch", `Added ${seconds_added_per_bits * times} Seconds Because ${userstate['display-name']} Donated ${userstate.bits} Bits`); - if (!users.includes(userstate['display-name'])) { - users.push(userstate['display-name']); + if (!countdownEnded && bitEnable) { + if(!happy_hour_active){ + if (userstate.bits >= min_amount_of_bits) { + let times = Math.floor(userstate.bits/min_amount_of_bits); + addTime(endingTime, seconds_added_per_bits * times); + logMessage("Twitch", `Added ${seconds_added_per_bits * times} Seconds Because ${userstate['display-name']} Donated ${userstate.bits} Bits`); + if (!users.includes(userstate['display-name'])) { + users.push(userstate['display-name']); + } + } + } + if(happy_hour_active){ + if (userstate.bits >= min_amount_of_bits) { + let times = Math.floor(userstate.bits/min_amount_of_bits); + addTime(endingTime, seconds_added_per_bits_happy * times); + logMessage("Twitch", `Added ${seconds_added_per_bits_happy * times} Seconds Because ${userstate['display-name']} Donated ${userstate.bits} Bits`); + if (!users.includes(userstate['display-name'])) { + users.push(userstate['display-name']); + } } } } diff --git a/js/script.js b/js/script.js index 188b146..5f6532b 100644 --- a/js/script.js +++ b/js/script.js @@ -39,21 +39,39 @@ resetBtn.addEventListener("click", function(){ endingTime = timeFunc.addHours(timeNow, initialHours); endingTime = timeFunc.addMinutes(timeNow, initialMinutes); endingTime = timeFunc.addSeconds(timeNow, initialSeconds); - + window.localStorage.removeItem('initialHours'); window.localStorage.removeItem('initialMinutes'); window.localStorage.removeItem('initialSeconds'); - + logMessage("Core", "Timer Reset."); }); startBtn.addEventListener("click", function(){ - if(paused == true){ - initialHours = window.localStorage.getItem('initialHours') - initialMinutes = window.localStorage.getItem('initialMinutes') - initialSeconds = window.localStorage.getItem('initialSeconds') + if(paused){ + var initialHoursLocal = window.localStorage.getItem('initialHours') + if(initialHoursLocal !== null) { + initialHours = initialHoursLocal; + logMessage("Core", "Found initialHours in localStorage.") + } else { + initialHours = initialHoursConfig; + } + var initialMinutesLocal = window.localStorage.getItem('initialMinutes') + if(initialMinutesLocal !== null) { + initialMinutes = initialMinutesLocal; + logMessage("Core", "Found initialMinutes in localStorage.") + } else { + initialMinutes = initialMinutesConfig; + } + var initialSecondsLocal = window.localStorage.getItem('initialSeconds') + if(initialSecondsLocal !== null) { + initialSeconds = initialSecondsLocal; + logMessage("Core", "Found initialSeconds in localStorage.") + } else { + initialSeconds = initialSecondsConfig; + } } let timeNow = new Date(Date.now()); @@ -70,41 +88,18 @@ startBtn.addEventListener("click", function(){ }); -Mousetrap.bind('ctrl+alt+p', function(e) { +Mousetrap.bind(pauseShort, function(e) { paused = true; logMessage("Core", "Timer was paused"); document.getElementById("startPage").style.visibility = "visible"; document.getElementById("container").style.visibility = "hidden"; }); -Mousetrap.bind('ctrl+alt+h', async function(e){ - if(happy_hour == true && happy_hour_active == false){ - 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(happyHourShort, async function(e){ + if(happy_hour){ + happyHourFunc() } - 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"; - 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)"; - await sleep(5000) - document.getElementById("HappyHourText").animate({opacity: [ 1, 0 ], easing: [ 'ease-in', 'ease-out' ],}, 500); - document.getElementById("HappyHourText").style.opacity = "0"; - } - else if(happy_hour == false){ + 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); @@ -117,6 +112,36 @@ Mousetrap.bind('ctrl+alt+h', async function(e){ } }); +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"; + } + 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)"; + await sleep(5000) + document.getElementById("HappyHourText").animate({opacity: [ 1, 0 ], easing: [ 'ease-in', 'ease-out' ],}, 500); + document.getElementById("HappyHourText").style.opacity = "0"; + } +} + let countdownEnded = false; let users = []; @@ -128,6 +153,15 @@ endingTime = timeFunc.addHours(endingTime, initialHours); endingTime = timeFunc.addMinutes(endingTime, initialMinutes); endingTime = timeFunc.addSeconds(endingTime, initialSeconds); +function getRandomInt(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min)) + min; +} + +var randomHappyBool = false +var scheduleHappyBool = false + const getNextTime = () => { let currentTime = new Date(Date.now()); @@ -138,10 +172,19 @@ const getNextTime = () => { countdownEnded = true; time = "00:00:00"; } - if(paused == false){ + if(!paused){ window.localStorage.setItem('initialHours', timeFunc.getHours(differenceTime)); window.localStorage.setItem('initialMinutes', timeFunc.getMinutes(differenceTime)); window.localStorage.setItem('initialSeconds', timeFunc.getSeconds(differenceTime)); + + if(randHappy && happy_hour && !randomHappyBool){ + randomHappyBool = true + setTimeout(randomHappy,1000) + } + if(scheduleHappy && happy_hour && !scheduleHappyBool){ + scheduleHappyBool = true + scheduleHappyFunc() + } } timeText.innerText = time; @@ -151,6 +194,30 @@ let countdownUpdater = setInterval(() => { getNextTime(); }, 1); +function randomHappy(){ + if(!happy_hour_active){ + if((getRandomInt(0,10000) == 127)){ + logMessage("RandomHappy","It's not rigged!") + happyHourFunc() + setTimeout(happyHourFunc, 3600000) + } + setTimeout(randomHappy,1000) + } +} + +function scheduleHappyFunc(){ + let now = new Date() + if(now.getDay() == scheduleHappyDay){ + if(now.getUTCHours() == scheduleHappyHour){ + if(now.getUTCMinutes() == 00){ + logMessage("Schedule","It's time!") + happyHourFunc() + setTimeout(happyHourFunc, 3600000) + setTimeout(scheduleHappyFunc, 36000000) + } + } + } +} var firstSub = true; var endingTimeBeforeCounter; @@ -182,16 +249,10 @@ const addTimeInternal = async () => { firstSub = true; let addedTime = document.createElement("p"); - if(happy_hour == true && happy_hour_active == true) { + if(happy_hour_active) { 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) { + else { addedTime.classList = "addedTime"; } addedTime.innerText = `+${s}s`;