initial commit and all the project done because I'm dumb
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
const start = () => {
|
||||
screenWidth = window.innerWidth;
|
||||
screenHeight = window.innerHeight;
|
||||
|
||||
endingTime = new Date(Date.now());
|
||||
endingTime = timeFunc.addHours(endingTime, initialHours);
|
||||
endingTime = timeFunc.addMinutes(endingTime, initialMinutes);
|
||||
endingTime = timeFunc.addSeconds(endingTime, initialSeconds);
|
||||
|
||||
timeText = document.getElementById("timeText");
|
||||
|
||||
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 inter = setInterval(() => {
|
||||
getNextTime();
|
||||
}, 100);
|
||||
|
||||
|
||||
|
||||
socket = io(`https://sockets.streamlabs.com?token=${streamlabsToken}`, {transports: ['websocket']})
|
||||
|
||||
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);
|
||||
}
|
||||
else if (event.type == "donation") {
|
||||
if (parseInt(event.message[0].amount) >= quantityDono) {
|
||||
endingTime = timeFunc.addSeconds(endingTime, secondsPerDono);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
timeFunc = {
|
||||
addHours(time, h) {
|
||||
time.setTime(time.getTime() + (h * 60 * 60 * 1000));
|
||||
return time;
|
||||
},
|
||||
|
||||
addMinutes(time, m) {
|
||||
time.setTime(time.getTime() + (m * 60 * 1000));
|
||||
return time;
|
||||
},
|
||||
|
||||
addSeconds (time, s) {
|
||||
time.setTime(time.getTime() + (s * 1000));
|
||||
return time;
|
||||
},
|
||||
|
||||
getHours(time) {
|
||||
let hours;
|
||||
if (typeof time !== 'number') {
|
||||
hours = time.getHours().toString();
|
||||
}
|
||||
else {
|
||||
hours = Math.floor(time / (1000 * 60 * 60)).toString();
|
||||
}
|
||||
hours = (hours.length < 2) ? `0${hours}` : hours;
|
||||
return hours;
|
||||
},
|
||||
|
||||
getMinutes(time) {
|
||||
let minutes;
|
||||
if (typeof time !== 'number') {
|
||||
minutes = time.getMinutes().toString();
|
||||
}
|
||||
else {
|
||||
minutes = Math.floor((time % (1000 * 60 * 60)) / (1000 * 60)).toString();
|
||||
}
|
||||
minutes = (minutes.length < 2) ? `0${minutes}` : minutes;
|
||||
return minutes;
|
||||
},
|
||||
|
||||
getSeconds(time) {
|
||||
let seconds;
|
||||
if (typeof time !== 'number') {
|
||||
seconds = time.getSeconds().toString();
|
||||
}
|
||||
else {
|
||||
seconds = Math.floor((time % (1000 * 60)) / 1000).toString();
|
||||
}
|
||||
seconds = (seconds.length < 2) ? `0${seconds}` : seconds;
|
||||
return seconds;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user