From a1c4ee545038c2ba14974fc5b57fa86acafd05bb Mon Sep 17 00:00:00 2001 From: Chlod Alejandro Date: Thu, 23 Jan 2025 13:16:51 +0800 Subject: [PATCH] change time server, fix error handling --- public/index.html | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index 0c68c5d..640afd7 100644 --- a/public/index.html +++ b/public/index.html @@ -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; @@ -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); @@ -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. @@ -386,7 +390,7 @@ }, 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; @@ -394,4 +398,4 @@ } - \ No newline at end of file +