diff --git a/README.md b/README.md index 3e773db..84a0747 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -

Twitch Subathon Countdown

-

This is a countdown specifically made for the Twitch streamer "SugusSusana"

+

Twitch Subathon Countdown Template

+

This is the template I created for my Twitch Subathon Countdowns


Description

@@ -14,17 +14,21 @@

After cloning this repository you'll have to edit the "config.js" file with any plain text editor, then change the value of the variables acording to what you want:

Streamlabs Token

-

To get the token you'll have to go to the api settings tab of your streamlabs dashboard then click on tokens API, copy your socket API token and finally paste the code on the "streamlabsToken" variable in the "config.js" file.

+

To get the token you'll have to go to the api settings tab of your Streamlabs dashboard then click on API Tokens, copy your socket API token and finally paste the code on the "streamlabs_token" variable in the "config.js" file.

+

StreamElements Token

+

To get the token you'll have to go to your StreamElements channels dashboard, then click on show secrets, copy the Overlay token and paste the code on the "streamelements_token" variable in the "config.js" file.

+ +

Streamloots Token

-

To get the token you'll have to go to your streamloots creator dashboard, then to alerts & widgets, then go to alerts, then copy the last part of the alerts url and finally paste the code on the "streamlootsToken" variable in the "config.js" file.

+

To get the token you'll have to go to your Streamloots creator dashboard, then to alerts & widgets, then go to alerts, then copy the last part of the alerts url and finally paste the code on the "streamloots_token" variable in the "config.js" file.

Initial Time

-

You can set the initial time of the timer by setting the hours, minutes and seconds to be added when the timer is added.

+

You can set the initial time of the timer by setting the hours, minutes and seconds to be added when the timer is created.

-

Other Value

+

Other Values

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

Add To OBS

diff --git a/assets/background.svg b/assets/background.svg deleted file mode 100644 index 89823bb..0000000 --- a/assets/background.svg +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - diff --git a/auth_streamelements.png b/auth_streamelements.png new file mode 100644 index 0000000..2a53a16 Binary files /dev/null and b/auth_streamelements.png differ diff --git a/auth_streamlabs.png b/auth_streamlabs.png index 1b41405..1241813 100644 Binary files a/auth_streamlabs.png and b/auth_streamlabs.png differ diff --git a/auth_streamloots.png b/auth_streamloots.png index 10f7796..22e2d56 100644 Binary files a/auth_streamloots.png and b/auth_streamloots.png differ diff --git a/config.js b/config.js index a481f05..4028975 100644 --- a/config.js +++ b/config.js @@ -1,17 +1,36 @@ -var streamlabsToken = "" -var streamlootsToken = "" +// Login Data +var twitch_channel_name = "" +var streamlabs_token = "" +var streamelements_token = "" +var streamloots_token = "" -var initialHours = 3 -var initialMinutes = 30 -var initialSeconds = 40 +// Initial Counter Config +var initialHours = 5 +var initialMinutes = 0 +var initialSeconds = 0 -var secondsPerSub = 300 +// General Twitch, Streamlabs And StreamElements Config +var seconds_added_per_sub_prime = 30 +var seconds_added_per_sub_tier1 = 30 +var seconds_added_per_sub_tier2 = 60 +var seconds_added_per_sub_tier3 = 120 -var secondsPerDono = 300 -var quantityDono = 5 +var seconds_added_per_resub_prime = 30 +var seconds_added_per_resub_tier1 = 30 +var seconds_added_per_resub_tier2 = 60 +var seconds_added_per_resub_tier3 = 120 -var secondsPerChest = 300 -var quantityChest = 10 +var seconds_added_per_giftsub_tier1 = 30 +var seconds_added_per_giftsub_tier2 = 60 +var seconds_added_per_giftsub_tier3 = 120 -var secondsPerBits = 300 -var quantityBits = 500 \ No newline at end of file +var min_amount_of_bits = 500 +var seconds_added_per_bits = 30 + +// Streamlabs And StreamElements Config +var min_donation_amount = 5 +var seconds_added_per_donation = 30 + +// Streamloots Config +var min_amount_of_chests = 5 +var seconds_added_per_chests = 30 \ No newline at end of file diff --git a/css/style.css b/css/style.css index 6cb0d74..62683c7 100644 --- a/css/style.css +++ b/css/style.css @@ -1,6 +1,7 @@ body, body * { padding: 0; margin: 0; + font-family: 'Manrope', sans-serif; } body { @@ -10,28 +11,36 @@ body { +:root { + --background-color: #f7fff7; + --shadow-color: #00000020; + --text-color: #292f36; +} + + + #container { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); + background-color: var(--background-color); + box-shadow: 0 0 1.25rem 0.5rem var(--shadow-color); + width: 500px; + height: 180px; + border-radius: 30px; } #textDiv { - background-color: #bea0af; - width: 420px; - height: 150px; - border-radius: 20px; display: flex; justify-content: center; align-items: center; - + height: 100%; } p { - color: #3c3341; - font-size: 4rem; - font-family: 'Manrope', sans-serif; + color: var(--text-color); + font-size: 5rem; z-index: 1; } @@ -42,11 +51,28 @@ img { } canvas { - width: 420px; - height: 150px; + width: 500px; + height: 180px; border-radius: 20px; position: absolute; top: 0; bottom: 0; z-index: 2; +} + + + +.addedTime { + 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); + text-shadow: 0 0 1.5rem var(--text-color); + transition: top 1s ease-out, opacity .5s ease-out; } \ No newline at end of file diff --git a/index.html b/index.html index 3880276..2c43dd8 100644 --- a/index.html +++ b/index.html @@ -10,17 +10,25 @@ Subathon Timer - +

00:00:00

-
+ + + + + - + + + + + \ No newline at end of file diff --git a/js/api/streamelements.js b/js/api/streamelements.js new file mode 100644 index 0000000..a2a1b09 --- /dev/null +++ b/js/api/streamelements.js @@ -0,0 +1,122 @@ +if (streamelements_token !== "") { + var streamElementsSocket; + const streamElementsConnect = () => { + streamElementsSocket = undefined; + streamElementsSocket = io('https://realtime.streamelements.com', { + transports: ['websocket'] + }); + + streamElementsSocket.on('connect', onConnect); + streamElementsSocket.on('disconnect', onDisconnect); + streamElementsSocket.on('authenticated', onAuthenticated); + streamElementsSocket.on('unauthorized', console.error); + streamElementsSocket.on('event:test', onEvent); + streamElementsSocket.on('event', onEvent); + streamElementsSocket.on('event:update', onEvent); + streamElementsSocket.on('event:reset', onEvent); + + function onConnect() { + logMessage("StreamElements", "Socket Connected"); + streamElementsSocket.emit('authenticate', {method: 'apikey', token: streamelements_token}); + } + + function onDisconnect() { + logMessage("StreamElements", "Socket Disconnected"); + streamElementsConnect(); + } + + function onAuthenticated(data) { + const { + channelId + } = data; + logMessage("StreamElements", `Channel ${channelId} Connected`); + } + + function onEvent(data) { + logObject("StreamElements", data); + if (!countdownEnded) { + if (data['listener'] === "subscriber-latest") { + 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 * amount); + logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier1 * amount} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 1 Subs`); + } + else if (data['event']['tier'] == "2000") { + addTime(endingTime, seconds_added_per_giftsub_tier2 * amount); + logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier2 * amount} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 2 Subs`); + } + else if (data['event']['tier'] == "3000") { + addTime(endingTime, seconds_added_per_giftsub_tier3 * amount); + logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier3 * 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); + logMessage("StreamElements", `Added ${seconds_added_per_resub_prime} Seconds Because ${data['event']['name']} ReSubscribed With Prime`); + } + else if (data['event']['tier'] == "1000") { + addTime(endingTime, seconds_added_per_resub_tier1); + logMessage("StreamElements", `Added ${seconds_added_per_resub_tier1} Seconds Because ${data['event']['name']} ReSubscribed With Tier 1`); + } + else if (data['event']['tier'] == "2000") { + addTime(endingTime, seconds_added_per_resub_tier2); + logMessage("StreamElements", `Added ${seconds_added_per_resub_tier2} Seconds Because ${data['event']['name']} ReSubscribed With Tier 2`); + } + else if (data['event']['tier'] == "3000") { + addTime(endingTime, seconds_added_per_resub_tier3); + logMessage("StreamElements", `Added ${seconds_added_per_resub_tier3} Seconds Because ${data['event']['name']} ReSubscribed With Tier 3`); + } + } + else { + if (data['event']['tier'] == "prime") { + addTime(endingTime, seconds_added_per_sub_prime); + logMessage("StreamElements", `Added ${seconds_added_per_sub_prime} Seconds Because ${data['event']['name']} Subscribed With Prime`); + } + else if (data['event']['tier'] == "1000") { + addTime(endingTime, seconds_added_per_sub_tier1); + logMessage("StreamElements", `Added ${seconds_added_per_sub_tier1} Seconds Because ${data['event']['name']} Subscribed With Tier 1`); + } + else if (data['event']['tier'] == "2000") { + addTime(endingTime, seconds_added_per_sub_tier2); + logMessage("StreamElements", `Added ${seconds_added_per_sub_tier2} Seconds Because ${data['event']['name']} Subscribed With Tier 2`); + } + else if (data['event']['tier'] == "3000") { + addTime(endingTime, seconds_added_per_sub_tier3); + logMessage("StreamElements", `Added ${seconds_added_per_sub_tier3} 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") { + 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); + logMessage("StreamElements", `Added ${seconds_added_per_bits * 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") { + if (data['event']['amount'] >= min_donation_amount) { + let times = Math.floor(data['event']['amount']/min_donation_amount); + addTime(endingTime, seconds_added_per_donation * times); + logMessage("StreamElements", `Added ${seconds_added_per_donation * times} Seconds Because ${data['event']['name']} Donated ${data['event']['amount']}$`); + if (!users.includes(data['event']['name'])) { + users.push(data['event']['name']); + } + } + } + } + } + } + streamElementsConnect(); +} \ No newline at end of file diff --git a/js/api/streamlabs.js b/js/api/streamlabs.js new file mode 100644 index 0000000..63f74f6 --- /dev/null +++ b/js/api/streamlabs.js @@ -0,0 +1,116 @@ +if (streamlabs_token !== "") { + socket = io(`https://sockets.streamlabs.com?token=${streamlabs_token}`, {transports: ['websocket']}); + + socket.on("connect", () => { + logMessage("Streamlabs", "Socket Connected"); + }); + + 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`); + } + 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}`); + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); + } + } + } + } + + 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`); + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); + } + } + } + } + }); + + socket.on("disconnect", () => { + logMessage("Streamlabs", "Socket Disconnected"); + socket.connect(); + }); +} \ No newline at end of file diff --git a/js/api/streamloots.js b/js/api/streamloots.js new file mode 100644 index 0000000..55cdaed --- /dev/null +++ b/js/api/streamloots.js @@ -0,0 +1,36 @@ +if (streamloots_token !== "") { + evtSourceStreamLoots = new EventSource(`https://widgets.streamloots.com/alerts/${streamloots_token}/media-stream`); + logMessage("Streamloots", "Event Source Created"); + + evtSourceStreamLoots.onmessage = async (event) => { + 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); + } + } + } + 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); + } + } + } + } + } + } +} \ No newline at end of file diff --git a/js/api/twitch.js b/js/api/twitch.js new file mode 100644 index 0000000..976f7df --- /dev/null +++ b/js/api/twitch.js @@ -0,0 +1,99 @@ +if (twitch_channel_name !== "") { + const client = new tmi.client({ + channels: [twitch_channel_name], + }); + + client.connect(); + logMessage("Twitch", `Client Connected`); + + client.on('subscription', (channel, username, methods, message, userstate) => { + if (!countdownEnded) { + 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); + } + } + }); + + client.on('resub', (channel, username, months, message, userstate, methods) => { + if (!countdownEnded) { + 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); + } + } + }); + + client.on('subgift', (channel, username, months, recipient, methods, userstate) => { + if (!countdownEnded) { + switch (methods['plan']) { + case "Prime": + addTime(endingTime, seconds_added_per_giftsub_tier1); + logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier1} Seconds Because ${username} Gifted A Tier 1 Sub`); + break; + case "1000": + addTime(endingTime, seconds_added_per_giftsub_tier1); + logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier1} Seconds Because ${username} Gifted A Tier 1 Sub`); + break; + case "2000": + addTime(endingTime, seconds_added_per_giftsub_tier2); + logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier2} Seconds Because ${username} Gifted A Tier 2 Sub`); + break; + case "3000": + addTime(endingTime, seconds_added_per_giftsub_tier3); + logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier3} Seconds Because ${username} Gifted A Tier 3 Sub`); + break; + } + if (!users.includes(username)) { + users.push(username); + } + } + }); + + 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']); + } + } + } + }); +} \ No newline at end of file diff --git a/js/lib/generalFunc.js b/js/lib/generalFunc.js new file mode 100644 index 0000000..86a4a06 --- /dev/null +++ b/js/lib/generalFunc.js @@ -0,0 +1,15 @@ +const sleep = (ms) => { + return new Promise(resolve => setTimeout(resolve, ms)); +}; + +const randomInRange = (min, max) => { + return Math.floor(Math.random() * (max - min)) + min; +}; + +const logMessage = (module, message) => { + console.log(`[${module}]: ${message}`); +}; + +const logObject = (module, object) => { + console.log(`[${module}]: `, object); +}; \ No newline at end of file diff --git a/js/timeFunc.js b/js/lib/timeFunc.js similarity index 100% rename from js/timeFunc.js rename to js/lib/timeFunc.js diff --git a/js/lib/tmi.min.js b/js/lib/tmi.min.js new file mode 100644 index 0000000..8f5833e --- /dev/null +++ b/js/lib/tmi.min.js @@ -0,0 +1 @@ +!function s(o,i,r){function a(t,e){if(!i[t]){if(!o[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(c)return c(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=i[t]={exports:{}},o[t][0].call(n.exports,function(e){return a(o[t][1][e]||e)},n,n.exports,s,o,i,r)}return i[t].exports}for(var c="function"==typeof require&&require,e=0;e: ").concat(m)),t.tags.hasOwnProperty("username")||(t.tags.username=M),t.tags["message-type"]="whisper";var J=H.channel(t.tags.username);this.emits(["whisper","message"],[[J,t.tags,m,!1]]);break;case"PRIVMSG":t.tags.username=t.prefix.split("!")[0],"jtv"===t.tags.username?(a=H.username(m.split(" ")[0]),c=m.includes("auto"),m.includes("hosting you for")?(J=H.extractNumber(m),this.emit("hosted",l,a,J,c)):m.includes("hosting you")&&this.emit("hosted",l,a,0,c)):(a=H.get(this.opts.options.messagesLogLevel,"info"),c=H.actionMessage(m),t.tags["message-type"]=c?"action":"chat",m=c?c[1]:m,t.tags.hasOwnProperty("bits")?this.emit("cheer",l,t.tags,m):(t.tags.hasOwnProperty("msg-id")?"highlighted-message"!==t.tags["msg-id"]&&"skip-subs-mode-message"!==t.tags["msg-id"]||(u=t.tags["msg-id"],this.emit("redeem",l,t.tags.username,u,t.tags,m)):t.tags.hasOwnProperty("custom-reward-id")&&(u=t.tags["custom-reward-id"],this.emit("redeem",l,t.tags.username,u,t.tags,m)),c?(this.log[a]("[".concat(l,"] *<").concat(t.tags.username,">: ").concat(m)),this.emits(["action","message"],[[l,t.tags,m,!1]])):(this.log[a]("[".concat(l,"] <").concat(t.tags.username,">: ").concat(m)),this.emits(["chat","message"],[[l,t.tags,m,!1]]))));break;default:this.log.warn("Could not parse message:\n".concat(JSON.stringify(t,null,4)))}}},n.prototype.connect=function(){var s=this;return new Promise(function(t,n){s.server=H.get(s.opts.connection.server,"irc-ws.chat.twitch.tv"),s.port=H.get(s.opts.connection.port,80),s.secure&&(s.port=443),443===s.port&&(s.secure=!0),s.reconnectTimer=s.reconnectTimer*s.reconnectDecay,s.reconnectTimer>=s.maxReconnectInterval&&(s.reconnectTimer=s.maxReconnectInterval),s._openConnection(),s.once("_promiseConnect",function(e){e?n(e):t([s.server,~~s.port])})})},n.prototype._openConnection=function(){this.ws=new r("".concat(this.secure?"wss":"ws","://").concat(this.server,":").concat(this.port,"/"),"irc"),this.ws.onmessage=this._onMessage.bind(this),this.ws.onerror=this._onError.bind(this),this.ws.onclose=this._onClose.bind(this),this.ws.onopen=this._onOpen.bind(this)},n.prototype._onOpen=function(){var t=this;H.isNull(this.ws)||1!==this.ws.readyState||(this.log.info("Connecting to ".concat(this.server," on port ").concat(this.port,"..")),this.emit("connecting",this.server,~~this.port),this.username=H.get(this.opts.identity.username,H.justinfan()),this._getToken().then(function(e){e=H.password(e);t.log.info("Sending authentication to server.."),t.emit("logon"),t.ws.send("CAP REQ :twitch.tv/tags twitch.tv/commands twitch.tv/membership"),e?t.ws.send("PASS ".concat(e)):H.isJustinfan(t.username)&&t.ws.send("PASS SCHMOOPIIE"),t.ws.send("NICK ".concat(t.username))}).catch(function(e){t.emits(["_promiseConnect","disconnected"],[[e],["Could not get a token."]])}))},n.prototype._getToken=function(){var e,t=this.opts.identity.password;return"function"==typeof t?(e=t())instanceof Promise?e:Promise.resolve(e):Promise.resolve(t)},n.prototype._onMessage=function(e){var t=this;e.data.split("\r\n").forEach(function(e){H.isNull(e)||t.handleMessage(q.msg(e))})},n.prototype._onError=function(){var t=this;this.moderators={},this.userstate={},this.globaluserstate={},clearInterval(this.pingLoop),clearTimeout(this.pingTimeout),this.reason=H.isNull(this.ws)?"Connection closed.":"Unable to connect.",this.emits(["_promiseConnect","disconnected"],[[this.reason]]),this.reconnect&&this.reconnections===this.maxReconnectAttempts&&(this.emit("maxreconnect"),this.log.error("Maximum reconnection attempts reached.")),this.reconnect&&!this.reconnecting&&this.reconnections<=this.maxReconnectAttempts-1&&(this.reconnecting=!0,this.reconnections=this.reconnections+1,this.log.error("Reconnecting in ".concat(Math.round(this.reconnectTimer/1e3)," seconds..")),this.emit("reconnect"),setTimeout(function(){t.reconnecting=!1,t.connect().catch(function(e){return t.log.error(e)})},this.reconnectTimer)),this.ws=null},n.prototype._onClose=function(){var t=this;this.moderators={},this.userstate={},this.globaluserstate={},clearInterval(this.pingLoop),clearTimeout(this.pingTimeout),this.wasCloseCalled?(this.wasCloseCalled=!1,this.reason="Connection closed.",this.log.info(this.reason),this.emits(["_promiseConnect","_promiseDisconnect","disconnected"],[[this.reason],[null],[this.reason]])):(this.emits(["_promiseConnect","disconnected"],[[this.reason]]),this.reconnect&&this.reconnections===this.maxReconnectAttempts&&(this.emit("maxreconnect"),this.log.error("Maximum reconnection attempts reached.")),this.reconnect&&!this.reconnecting&&this.reconnections<=this.maxReconnectAttempts-1&&(this.reconnecting=!0,this.reconnections=this.reconnections+1,this.log.error("Could not connect to server. Reconnecting in ".concat(Math.round(this.reconnectTimer/1e3)," seconds..")),this.emit("reconnect"),setTimeout(function(){t.reconnecting=!1,t.connect().catch(function(e){return t.log.error(e)})},this.reconnectTimer))),this.ws=null},n.prototype._getPromiseDelay=function(){return this.currentLatency<=600?600:this.currentLatency+100},n.prototype._sendCommand=function(s,o,i,r){var a=this;return new Promise(function(e,t){if(H.isNull(a.ws)||1!==a.ws.readyState)return t("Not connected to server.");var n;"number"==typeof s&&H.promiseDelay(s).then(function(){return t("No response from Twitch.")}),H.isNull(o)?(a.log.info("Executing command: ".concat(i)),a.ws.send(i)):(n=H.channel(o),a.log.info("[".concat(n,"] Executing command: ").concat(i)),a.ws.send("PRIVMSG ".concat(n," :").concat(i))),"function"==typeof r?r(e,t):e()})},n.prototype._sendMessage=function(c,u,l,m){var h=this;return new Promise(function(e,t){if(H.isNull(h.ws)||1!==h.ws.readyState)return t("Not connected to server.");if(H.isJustinfan(h.getUsername()))return t("Cannot send anonymous messages.");var n,s=H.channel(u);h.userstate[s]||(h.userstate[s]={}),500<=l.length&&(n=H.splitLine(l,500),l=n[0],setTimeout(function(){h._sendMessage(c,u,n[1],function(){})},350)),h.ws.send("PRIVMSG ".concat(s," :").concat(l));var o={};Object.keys(h.emotesets).forEach(function(e){return h.emotesets[e].forEach(function(e){return(H.isRegex(e.code)?q.emoteRegex:q.emoteString)(l,e.code,e.id,o)})});var i=H.merge(h.userstate[s],q.emotes({emotes:q.transformEmotes(o)||null})),r=H.get(h.opts.options.messagesLogLevel,"info"),a=H.actionMessage(l);a?(i["message-type"]="action",h.log[r]("[".concat(s,"] *<").concat(h.getUsername(),">: ").concat(a[1])),h.emits(["action","message"],[[s,i,a[1],!0]])):(i["message-type"]="chat",h.log[r]("[".concat(s,"] <").concat(h.getUsername(),">: ").concat(l)),h.emits(["chat","message"],[[s,i,l,!0]])),"function"==typeof m?m(e,t):e()})},n.prototype._updateEmoteset=function(s){var o=this;this.emotes=s,this._getToken().then(function(e){return o.api({url:"/chat/emoticon_images?emotesets=".concat(s),headers:{Authorization:"OAuth ".concat(H.token(e)),"Client-ID":o.clientId}},function(e,t,n){return e?void setTimeout(function(){return o._updateEmoteset(s)},6e4):(o.emotesets=n.emoticon_sets||{},o.emit("emotesets",s,o.emotesets))})}).catch(function(){return setTimeout(function(){return o._updateEmoteset(s)},6e4)})},n.prototype.getUsername=function(){return this.username},n.prototype.getOptions=function(){return this.opts},n.prototype.getChannels=function(){return this.channels},n.prototype.isMod=function(e,t){e=H.channel(e);return this.moderators[e]||(this.moderators[e]=[]),this.moderators[e].includes(H.username(t))},n.prototype.readyState=function(){return H.isNull(this.ws)?"CLOSED":["CONNECTING","OPEN","CLOSING","CLOSED"][this.ws.readyState]},n.prototype._isConnected=function(){return null!==this.ws&&1===this.ws.readyState},n.prototype.disconnect=function(){var n=this;return new Promise(function(e,t){H.isNull(n.ws)||3===n.ws.readyState?(n.log.error("Cannot disconnect from server. Socket is not opened or connection is already closing."),t("Cannot disconnect from server. Socket is not opened or connection is already closing.")):(n.wasCloseCalled=!0,n.log.info("Disconnecting from server.."),n.ws.close(),n.once("_promiseDisconnect",function(){return e([n.server,~~n.port])}))})},void 0!==u&&u.exports&&(u.exports=n),"undefined"!=typeof window&&(window.tmi={},window.tmi.client=n,window.tmi.Client=n)}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./api":2,"./commands":4,"./events":5,"./logger":6,"./parser":7,"./timer":8,"./utils":9,ws:10}],4:[function(e,t,n){"use strict";var u=e("./utils");function s(s,o){var e=this;return s=u.channel(s),o=u.get(o,30),this._sendCommand(this._getPromiseDelay(),s,"/followers ".concat(o),function(t,n){e.once("_promiseFollowers",function(e){e?n(e):t([s,~~o])})})}function o(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/followersoff",function(t,n){e.once("_promiseFollowersoff",function(e){e?n(e):t([s])})})}function i(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),null,"PART ".concat(s),function(t,n){e.once("_promisePart",function(e){e?n(e):t([s])})})}function r(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/r9kbeta",function(t,n){e.once("_promiseR9kbeta",function(e){e?n(e):t([s])})})}function a(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/r9kbetaoff",function(t,n){e.once("_promiseR9kbetaoff",function(e){e?n(e):t([s])})})}function c(s,o){var e=this;return s=u.channel(s),o=u.get(o,300),this._sendCommand(this._getPromiseDelay(),s,"/slow ".concat(o),function(t,n){e.once("_promiseSlow",function(e){e?n(e):t([s,~~o])})})}function l(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/slowoff",function(t,n){e.once("_promiseSlowoff",function(e){e?n(e):t([s])})})}t.exports={action:function(n,s){return n=u.channel(n),s="ACTION ".concat(s,""),this._sendMessage(this._getPromiseDelay(),n,s,function(e,t){e([n,s])})},ban:function(s,o,i){var e=this;return s=u.channel(s),o=u.username(o),i=u.get(i,""),this._sendCommand(this._getPromiseDelay(),s,"/ban ".concat(o," ").concat(i),function(t,n){e.once("_promiseBan",function(e){e?n(e):t([s,o,i])})})},clear:function(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/clear",function(t,n){e.once("_promiseClear",function(e){e?n(e):t([s])})})},color:function(e,s){var o=this;return s=u.get(s,e),this._sendCommand(this._getPromiseDelay(),"#tmijs","/color ".concat(s),function(t,n){o.once("_promiseColor",function(e){e?n(e):t([s])})})},commercial:function(s,o){var e=this;return s=u.channel(s),o=u.get(o,30),this._sendCommand(this._getPromiseDelay(),s,"/commercial ".concat(o),function(t,n){e.once("_promiseCommercial",function(e){e?n(e):t([s,~~o])})})},deletemessage:function(s,e){var o=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/delete ".concat(e),function(t,n){o.once("_promiseDeletemessage",function(e){e?n(e):t([s])})})},emoteonly:function(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/emoteonly",function(t,n){e.once("_promiseEmoteonly",function(e){e?n(e):t([s])})})},emoteonlyoff:function(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/emoteonlyoff",function(t,n){e.once("_promiseEmoteonlyoff",function(e){e?n(e):t([s])})})},followersonly:s,followersmode:s,followersonlyoff:o,followersmodeoff:o,host:function(o,i){var e=this;return o=u.channel(o),i=u.username(i),this._sendCommand(2e3,o,"/host ".concat(i),function(n,s){e.once("_promiseHost",function(e,t){e?s(e):n([o,i,~~t])})})},join:function(a){var c=this;return a=u.channel(a),this._sendCommand(null,null,"JOIN ".concat(a),function(s,o){var i="_promiseJoin",r=!1,e=function e(t,n){a===u.channel(n)&&(c.removeListener(i,e),r=!0,t?o(t):s([a]))};c.on(i,e);e=c._getPromiseDelay();u.promiseDelay(e).then(function(){r||c.emit(i,"No response from Twitch.",a)})})},mod:function(s,o){var e=this;return s=u.channel(s),o=u.username(o),this._sendCommand(this._getPromiseDelay(),s,"/mod ".concat(o),function(t,n){e.once("_promiseMod",function(e){e?n(e):t([s,o])})})},mods:function(o){var i=this;return o=u.channel(o),this._sendCommand(this._getPromiseDelay(),o,"/mods",function(n,s){i.once("_promiseMods",function(e,t){e?s(e):(t.forEach(function(e){i.moderators[o]||(i.moderators[o]=[]),i.moderators[o].includes(e)||i.moderators[o].push(e)}),n(t))})})},part:i,leave:i,ping:function(){var n=this;return this._sendCommand(this._getPromiseDelay(),null,"PING",function(t,e){n.latency=new Date,n.pingTimeout=setTimeout(function(){null!==n.ws&&(n.wasCloseCalled=!1,n.log.error("Ping timeout."),n.ws.close(),clearInterval(n.pingLoop),clearTimeout(n.pingTimeout))},u.get(n.opts.connection.timeout,9999)),n.once("_promisePing",function(e){return t([parseFloat(e)])})})},r9kbeta:r,r9kmode:r,r9kbetaoff:a,r9kmodeoff:a,raw:function(n){return this._sendCommand(this._getPromiseDelay(),null,n,function(e,t){e([n])})},say:function(n,s){return n=u.channel(n),s.startsWith(".")&&!s.startsWith("..")||s.startsWith("/")||s.startsWith("\\")?"me "===s.substr(1,3)?this.action(n,s.substr(4)):this._sendCommand(this._getPromiseDelay(),n,s,function(e,t){e([n,s])}):this._sendMessage(this._getPromiseDelay(),n,s,function(e,t){e([n,s])})},slow:c,slowmode:c,slowoff:l,slowmodeoff:l,subscribers:function(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/subscribers",function(t,n){e.once("_promiseSubscribers",function(e){e?n(e):t([s])})})},subscribersoff:function(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/subscribersoff",function(t,n){e.once("_promiseSubscribersoff",function(e){e?n(e):t([s])})})},timeout:function(s,o,i,r){var e=this;return s=u.channel(s),o=u.username(o),u.isNull(i)||u.isInteger(i)||(r=i,i=300),i=u.get(i,300),r=u.get(r,""),this._sendCommand(this._getPromiseDelay(),s,"/timeout ".concat(o," ").concat(i," ").concat(r),function(t,n){e.once("_promiseTimeout",function(e){e?n(e):t([s,o,~~i,r])})})},unban:function(s,o){var e=this;return s=u.channel(s),o=u.username(o),this._sendCommand(this._getPromiseDelay(),s,"/unban ".concat(o),function(t,n){e.once("_promiseUnban",function(e){e?n(e):t([s,o])})})},unhost:function(s){var e=this;return s=u.channel(s),this._sendCommand(2e3,s,"/unhost",function(t,n){e.once("_promiseUnhost",function(e){e?n(e):t([s])})})},unmod:function(s,o){var e=this;return s=u.channel(s),o=u.username(o),this._sendCommand(this._getPromiseDelay(),s,"/unmod ".concat(o),function(t,n){e.once("_promiseUnmod",function(e){e?n(e):t([s,o])})})},unvip:function(s,o){var e=this;return s=u.channel(s),o=u.username(o),this._sendCommand(this._getPromiseDelay(),s,"/unvip ".concat(o),function(t,n){e.once("_promiseUnvip",function(e){e?n(e):t([s,o])})})},vip:function(s,o){var e=this;return s=u.channel(s),o=u.username(o),this._sendCommand(this._getPromiseDelay(),s,"/vip ".concat(o),function(t,n){e.once("_promiseVip",function(e){e?n(e):t([s,o])})})},vips:function(e){var t=this;return e=u.channel(e),this._sendCommand(this._getPromiseDelay(),e,"/vips",function(n,s){t.once("_promiseVips",function(e,t){e?s(e):n(t)})})},whisper:function(n,s){var o=this;return(n=u.username(n))===this.getUsername()?Promise.reject("Cannot send a whisper to the same account."):this._sendCommand(this._getPromiseDelay(),"#tmijs","/w ".concat(n," ").concat(s),function(e,t){o.once("_promiseWhisper",function(e){e&&t(e)})}).catch(function(e){if(e&&"string"==typeof e&&0!==e.indexOf("No response from Twitch."))throw e;var t=u.channel(n),e=u.merge({"message-type":"whisper","message-id":null,"thread-id":null,username:o.getUsername()},o.globaluserstate);return o.emits(["whisper","message"],[[t,e,s,!0],[t,e,s,!0]]),[n,s]})}}},{"./utils":9}],5:[function(e,t,n){"use strict";function s(e){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function c(e){return"function"==typeof e}function u(e){return"object"===s(e)&&null!==e}function a(e){return void 0===e}((t.exports=o).EventEmitter=o).prototype._events=void 0,o.prototype._maxListeners=void 0,o.defaultMaxListeners=10,o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},o.prototype.emit=function(e){var t,n,s,o,i,r;if(this._events||(this._events={}),"error"===e&&(!this._events.error||u(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(a(n=this._events[e]))return!1;if(c(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1),n.apply(this,o)}else if(u(n))for(o=Array.prototype.slice.call(arguments,1),s=(r=n.slice()).length,i=0;in&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},o.prototype.once=function(e,t){if(!c(t))throw TypeError("listener must be a function");var n=!1;if(this._events.hasOwnProperty(e)&&"_"===e.charAt(0)){var s,o=1,i=e;for(s in this._events)this._events.hasOwnProperty(s)&&s.startsWith(i)&&o++;e+=o}function r(){"_"!==e.charAt(0)||isNaN(e.substr(e.length-1))||(e=e.substring(0,e.length-1)),this.removeListener(e,r),n||(n=!0,t.apply(this,arguments))}return r.listener=t,this.on(e,r),this},o.prototype.removeListener=function(e,t){var n,s,o,i;if(!c(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(o=(n=this._events[e]).length,s=-1,n===t||c(n.listener)&&n.listener===t){if(delete this._events[e],this._events.hasOwnProperty(e+"2")&&"_"===e.charAt(0)){var r,a=e;for(r in this._events)this._events.hasOwnProperty(r)&&r.startsWith(a)&&(isNaN(parseInt(r.substr(r.length-1)))||(this._events[e+parseInt(r.substr(r.length-1)-1)]=this._events[r],delete this._events[r]));this._events[e]=this._events[e+"1"],delete this._events[e+"1"]}this._events.removeListener&&this.emit("removeListener",e,t)}else if(u(n)){for(i=o;0n?(t.command=e.slice(n),t):null;for(t.command=e.slice(n,s),n=s+1;32===e.charCodeAt(n);)n++;for(;ne.length)&&(t=e.length);for(var n=0,s=new Array(t);n").replace(/\\"\\;/g,'"').replace(/\\'\\;/g,"'")},unescapeIRC:function(e){return e&&e.includes("\\")?e.replace(a,function(e,t){return t in u?u[t]:t}):e},escapeIRC:function(e){return e&&e.replace(c,function(e,t){return t in l?"\\".concat(l[t]):t})},actionMessage:function(e){return e.match(i)},addWord:function(e,t){return e.length?e+" "+t:e+t},channel:function(e){var t=(e||"").toLowerCase();return"#"===t[0]?t:"#"+t},extractNumber:function(e){for(var t=e.split(" "),n=0;n { - screenWidth = window.innerWidth; - screenHeight = window.innerHeight; +const timeText = document.getElementById("timeText"); - endingTime = new Date(Date.now()); - endingTime = timeFunc.addHours(endingTime, initialHours); - endingTime = timeFunc.addMinutes(endingTime, initialMinutes); - endingTime = timeFunc.addSeconds(endingTime, initialSeconds); +let endingTime = new Date(Date.now()); +endingTime = timeFunc.addHours(endingTime, initialHours); +endingTime = timeFunc.addMinutes(endingTime, initialMinutes); +endingTime = timeFunc.addSeconds(endingTime, initialSeconds); - timeText = document.getElementById("timeText"); +let countdownEnded = false; +let users = []; +let time; - const getNextTime = () => { - let currentTime = new Date(Date.now()); - let differenceTime = endingTime - currentTime; - let time = `${timeFunc.getHours(differenceTime)}:${timeFunc.getMinutes(differenceTime)}:${timeFunc.getSeconds(differenceTime)}`; - if (time === "00:00:00") { - clearInterval(inter); - time = "¡FIN!"; - console.log(time); - } - timeText.innerText = time; +const getNextTime = () => { + let currentTime = new Date(Date.now()); + let differenceTime = endingTime - currentTime; + time = `${timeFunc.getHours(differenceTime)}:${timeFunc.getMinutes(differenceTime)}:${timeFunc.getSeconds(differenceTime)}`; + if (differenceTime <= 0) { + clearInterval(countdownUpdater); + countdownEnded = true; + time = "00:00:00"; } + timeText.innerText = time; +}; - const inter = setInterval(() => { - getNextTime(); - }, 100); +let countdownUpdater = setInterval(() => { + getNextTime(); +}, 100); - socket = io(`https://sockets.streamlabs.com?token=${streamlabsToken}`, {transports: ['websocket']}) +const addTime = async (time, s) => { + endingTime = timeFunc.addSeconds(time, s); + let addedTime = document.createElement("p"); + addedTime.classList = "addedTime"; + addedTime.innerText = `+${s}s`; + document.body.appendChild(addedTime); + addedTime.style.display = "block"; + await sleep(50); + addedTime.style.left = `${randomInRange(35, 65)}%`; + addedTime.style.top = `${randomInRange(25, 45)}%`; + addedTime.style.opacity = "1"; + await sleep(2500); + addedTime.style.opacity = "0"; + await sleep(500); + addedTime.remove(); +}; - socket.on("connect", () => { - console.log("Socket Connected"); - }); - socket.on("event", (event) => { - console.log(event); - if (event.type == "subscription" || event.type == "resub") { - endingTime = timeFunc.addSeconds(endingTime, secondsPerSub); + +const testAddTime = (times, delay) => { + let addTimeInterval = setInterval(async () => { + if (times > 0) { + await sleep(randomInRange(50, delay-50)); + addTime(endingTime, 30); + --times; } - else if (event.type == "donation") { - if (parseInt(event.message[0].amount) >= quantityDono) { - endingTime = timeFunc.addSeconds(endingTime, secondsPerDono); - } + else { + clearInterval(addTimeInterval); } - else if (event.type == "bits") { - if (parseInt(event.message[0].amount) >= quantityBits) { - endingTime = timeFunc.addSeconds(endingTime, secondsPerBits); - } - } - }); - - socket.on("disconnect", () => { - console.log("Socket Disconnected"); - }); - - - - evtSourceStreamLoots = new EventSource(`https://widgets.streamloots.com/alerts/${streamlootsToken}/media-stream`); - - evtSourceStreamLoots.onmessage = async (event) => { - data = await JSON.parse(event.data); - if (data.data.type == "purchase") { - if (typeof(data.data.fields[0].value) == "number") { - if (data.data.fields[0].value >= quantityChest) { - endingTime = timeFunc.addSeconds(endingTime, secondsPerChest); - } - } - else { - if (data.data.fields[1].value >= quantityChest) { - endingTime = timeFunc.addSeconds(endingTime, secondsPerChest); - } - } - } - } -} \ No newline at end of file + }, delay); +}; \ No newline at end of file diff --git a/preview.gif b/preview.gif deleted file mode 100644 index 26102d6..0000000 Binary files a/preview.gif and /dev/null differ