From a7fc0b0cd59d245473eb94e0a009fc279084ca4b Mon Sep 17 00:00:00 2001 From: MeowcaTheoRange Date: Tue, 13 Sep 2022 10:57:56 -0500 Subject: [PATCH] Added update detector --- index.html | 11 +++++++++++ styles/dialog.css | 10 +++++----- update.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 update.js diff --git a/index.html b/index.html index 2f67e2a..426bb3e 100644 --- a/index.html +++ b/index.html @@ -196,6 +196,16 @@ +
+
+

There's an update!

+

You should restart - there's a new update of FunnyClock².

+
+
+ +
+
+
+ \ No newline at end of file diff --git a/styles/dialog.css b/styles/dialog.css index 3ed514a..4a1492a 100644 --- a/styles/dialog.css +++ b/styles/dialog.css @@ -40,13 +40,13 @@ margin: 8px 0; } -.dialog form div { +.dialog div { text-align: right; margin-top: 8px; box-sizing: border-box; } -.dialog form div input[type=submit] { +.dialog div input[type=submit], .dialog div button { margin: 0; padding: 8px; height: 32px; @@ -59,15 +59,15 @@ transition: background-color 0.125s, color 0.125s; } -.dialog form div input:focus { +.dialog div input:focus { background-color: #00000020; } -.dialog form div input:hover { +.dialog div input:hover { background-color: #00000040; } -.dialog form div input:active { +.dialog div input:active { background-color: #00000080; } diff --git a/update.js b/update.js new file mode 100644 index 0000000..351f19a --- /dev/null +++ b/update.js @@ -0,0 +1,30 @@ +var prevSha = localStorage.getItem("commitsha") ?? "ThisShouldntBeASHA"; + +setInterval(reqData, 30000); + +function reqData() { + const XHR = new XMLHttpRequest(); + + XHR.addEventListener("load", (event) => { + var resp = JSON.parse(event.target.response); + + if (resp.sha != prevSha) { + if (prevSha == "ThisShouldntBeASHA") { + localStorage.setItem("commitsha", resp.sha); + } else { + document.querySelector(".scr-update--").classList.add("open"); + localStorage.setItem("commitsha", resp.sha); + } + } + }); + + XHR.addEventListener("error", (event) => { + console.log('Oops! Something went wrong.'); + }); + + XHR.open("GET", "https://api.github.com/repos/meowcatheorange/clock/commits/master"); + + XHR.send(); +} + +reqData(); \ No newline at end of file