Clock/update.js

33 lines
863 B
JavaScript
Raw Normal View History

2022-09-13 15:57:56 +00:00
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");
setTimeout(() => {
window.location.href = window.location.href;
2022-09-13 16:05:50 +00:00
}, 30000);
2022-09-13 15:57:56 +00:00
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();