diff options
| author | stonedDiscord <Tukz@gmx.de> | 2022-03-12 01:42:32 +0100 |
|---|---|---|
| committer | stonedDiscord <Tukz@gmx.de> | 2022-03-12 01:42:32 +0100 |
| commit | 0c3e277dadde35a812202d1dbc64a9712c061be0 (patch) | |
| tree | 74c08d425d0bd75f0bc61bb610167f290357ccbb /webAO/master.js | |
| parent | d338c0ede98703aaf05d380077a76ab66b763f65 (diff) | |
i think this is how caching can work
Diffstat (limited to 'webAO/master.js')
| -rw-r--r-- | webAO/master.js | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/webAO/master.js b/webAO/master.js index 2d1e69a..58b18e5 100644 --- a/webAO/master.js +++ b/webAO/master.js @@ -28,10 +28,11 @@ fpPromise hdid = result.visitorId; check_https(); - + fetch("https://servers.aceattorneyonline.com/servers") - .then(response => response.json()) - .then(data => processServerlist(data)); + .then(cachedServerlist) + .then(response => loadServerlist(response)) + .catch(cachedServerlist); fetch("https://servers.aceattorneyonline.com/version") .then(response => response.text()) @@ -111,10 +112,22 @@ function checkOnline(serverID, coIP) { }; } +function loadServerlist(thelist) { + localStorage.setItem('masterlist', thelist); + processServerlist(thelist) +} + +function cachedServerlist(response) { + if (!response.ok) { + document.getElementById('ms_error').style.display = 'block'; + return localStorage.getItem('masterlist'); + } + return response.json(); +} + function processServerlist(thelist) { for (let i = 0; i < thelist.length - 1; i++) { const serverEntry = thelist[i]; - console.debug(serverEntry) servers[i] = serverEntry; |
