commit 996639cf6f36740ce57012ec15910a67812da4a3
Author: Joaquin Touron <43842304+JayexDesigns@users.noreply.github.com>
Date: Sun Jun 27 19:25:55 2021 +0200
initial commit and all the project done because I'm dumb
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6186f82
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.mp4
+LEEME.txt
\ No newline at end of file
diff --git a/assets/background.svg b/assets/background.svg
new file mode 100644
index 0000000..89823bb
--- /dev/null
+++ b/assets/background.svg
@@ -0,0 +1,132 @@
+
+
diff --git a/config.js b/config.js
new file mode 100644
index 0000000..a481f05
--- /dev/null
+++ b/config.js
@@ -0,0 +1,17 @@
+var streamlabsToken = ""
+var streamlootsToken = ""
+
+var initialHours = 3
+var initialMinutes = 30
+var initialSeconds = 40
+
+var secondsPerSub = 300
+
+var secondsPerDono = 300
+var quantityDono = 5
+
+var secondsPerChest = 300
+var quantityChest = 10
+
+var secondsPerBits = 300
+var quantityBits = 500
\ No newline at end of file
diff --git a/css/style.css b/css/style.css
new file mode 100644
index 0000000..6cb0d74
--- /dev/null
+++ b/css/style.css
@@ -0,0 +1,52 @@
+body, body * {
+ padding: 0;
+ margin: 0;
+}
+
+body {
+ width: 100vw;
+ height: 100vh;
+}
+
+
+
+#container {
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+}
+
+#textDiv {
+ background-color: #bea0af;
+ width: 420px;
+ height: 150px;
+ border-radius: 20px;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+
+}
+
+p {
+ color: #3c3341;
+ font-size: 4rem;
+ font-family: 'Manrope', sans-serif;
+ z-index: 1;
+}
+
+img {
+ position: absolute;
+ top: 0;
+ bottom: 0;
+}
+
+canvas {
+ width: 420px;
+ height: 150px;
+ border-radius: 20px;
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ z-index: 2;
+}
\ No newline at end of file
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..3880276
--- /dev/null
+++ b/index.html
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+ Subathon Timer
+
+
+
+
+

+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/js/script.js b/js/script.js
new file mode 100644
index 0000000..329760d
--- /dev/null
+++ b/js/script.js
@@ -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);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/js/timeFunc.js b/js/timeFunc.js
new file mode 100644
index 0000000..45a83cd
--- /dev/null
+++ b/js/timeFunc.js
@@ -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;
+ }
+};
\ No newline at end of file