Skip to content

Commit

Permalink
change time server, fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ChlodAlejandro committed Jan 23, 2025
1 parent 18c39a3 commit a1c4ee5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
// Using an XHR here, *just in case* the TV does not support the
// Fetch API. `fetch` would be much better.
var request = new XMLHttpRequest();
request.open("GET", "https://worldtimeapi.org/api/timezone/Asia/Manila", true);
request.open("GET", "https://random.chlod.net/time.php", true);

// Account for response time delay
var loadStartTime;
Expand All @@ -216,6 +216,10 @@
loadStartTime = Date.now();
}
};
request.onerror = function() {
console.log("Failed to get time offset from API.");
rej();
}
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
var data = JSON.parse(this.response);
Expand Down Expand Up @@ -302,7 +306,7 @@

/**
* Adjust the clock to use actual time instead of system time.
*
*
* @param {start} [string] Whether this is the start of execution.
* If not, this function will not run if it is within 15 minutes
* of endTimestamp.
Expand Down Expand Up @@ -386,12 +390,12 @@
}, 1000);
} catch (e) {
alert("Failed to start: " + e + "\n" + e.stack);
document.getElementsByTagName("main")[0].innerText =
document.getElementsByTagName("main")[0].innerText =
"Failed to load: " + e;
const pre = document.createElement("pre");
pre.innerText = e.stack;
document.getElementsByTagName("main")[0].appendChild(pre);
}
</script>
</body>
</html>
</html>

0 comments on commit a1c4ee5

Please sign in to comment.