diff options
author | lolcat <will@lolcat.ca> | 2023-11-27 01:01:56 -0500 |
---|---|---|
committer | lolcat <will@lolcat.ca> | 2023-11-27 01:01:56 -0500 |
commit | 2519666e1c831f85836f9ce6d975d3ceb975c09d (patch) | |
tree | 86c68604aff9c7a0a430e70ef082195a4c3a717f /static/serverping.js | |
parent | 9fd993b47b8c1b6e3c9d9f0e8d43a85860230f59 (diff) |
google web, videos and news, various other fixes
Diffstat (limited to 'static/serverping.js')
-rw-r--r-- | static/serverping.js | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/static/serverping.js b/static/serverping.js index 5fe285d..a94fe50 100644 --- a/static/serverping.js +++ b/static/serverping.js @@ -160,6 +160,16 @@ function number_format(int){ return new Intl.NumberFormat().format(int); } +window.fetch = (function(fetch) { + return function(fn, t){ + const begin = Date.now(); + return fetch.apply(this, arguments).then(function(response) { + response.ping = Date.now() - begin; + return response; + }); + }; +})(window.fetch); + // parse initial server list fetch_server(window.location.origin); @@ -187,25 +197,24 @@ async function fetch_server(server){ list.push(server); var data = null; - var ping = new Date().getTime(); try{ - data = await fetch( + var payload = await fetch( server + "/ami4get" ); - if(data.status !== 200){ + if(payload.status !== 200){ // endpoint is not available errors++; div_failedreqs.textContent = number_format(errors); - console.warn(server + ": Invalid HTTP code " + data.status); + console.warn(server + ": Invalid HTTP code " + payload.status); return; } - data = await data.json(); - data.server.ping = new Date().getTime() - ping; + data = await payload.json(); + data.server.ping = payload.ping; }catch(error){ |