Clock/update.js

33 lines
No EOL
863 B
JavaScript

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;
}, 10000);
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();