From 1b232ae693093d9ea3e13e05a38ce172fd68397a Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Thu, 1 Jul 2021 13:52:43 -0300 Subject: [PATCH] use viaaas prefix for localstorage check navigate mode --- src/main/resources/web/js/account_manager.js | 10 +++++----- src/main/resources/web/js/cors_proxy.js | 6 +++--- src/main/resources/web/js/websocket.js | 20 +++++++++----------- src/main/resources/web/sw.js | 1 + 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main/resources/web/js/account_manager.js b/src/main/resources/web/js/account_manager.js index 010e8f9..1e7a524 100644 --- a/src/main/resources/web/js/account_manager.js +++ b/src/main/resources/web/js/account_manager.js @@ -1,22 +1,22 @@ // Account storage function storeMcAccount(accessToken, clientToken, name, id, msUser = null) { - let accounts = JSON.parse(localStorage.getItem("mc_accounts")) || []; + let accounts = JSON.parse(localStorage.getItem("viaaas_mc_accounts")) || []; let account = {accessToken: accessToken, clientToken: clientToken, name: name, id: id, msUser: msUser}; accounts.push(account); - localStorage.setItem("mc_accounts", JSON.stringify(accounts)); + localStorage.setItem("viaaas_mc_accounts", JSON.stringify(accounts)); refreshAccountList(); return account; } function removeMcAccount(id) { - let accounts = JSON.parse(localStorage.getItem("mc_accounts")) || []; + let accounts = getMcAccounts(); accounts = accounts.filter(it => it.id != id); - localStorage.setItem("mc_accounts", JSON.stringify(accounts)); + localStorage.setItem("viaaas_mc_accounts", JSON.stringify(accounts)); refreshAccountList(); } function getMcAccounts() { - return JSON.parse(localStorage.getItem("mc_accounts")) || []; + return JSON.parse(localStorage.getItem("viaaas_mc_accounts")) || []; } function findAccountByMcName(name) { diff --git a/src/main/resources/web/js/cors_proxy.js b/src/main/resources/web/js/cors_proxy.js index 5a7de02..80610b6 100644 --- a/src/main/resources/web/js/cors_proxy.js +++ b/src/main/resources/web/js/cors_proxy.js @@ -2,9 +2,9 @@ function defaultCors() { return "https://crp123-cors.herokuapp.com/"; } function getCorsProxy() { - return localStorage.getItem("cors-proxy") || defaultCors(); + return localStorage.getItem("viaaas_cors_proxy") || defaultCors(); } function setCorsProxy(url) { - localStorage.setItem("cors-proxy", url); + localStorage.setItem("viaaas_cors_proxy", url); refreshCorsStatus(); -} \ No newline at end of file +} diff --git a/src/main/resources/web/js/websocket.js b/src/main/resources/web/js/websocket.js index 6586556..fd1cd32 100644 --- a/src/main/resources/web/js/websocket.js +++ b/src/main/resources/web/js/websocket.js @@ -9,34 +9,32 @@ function defaultWs() { } function getWsUrl() { - let url = localStorage.getItem("ws-url") || defaultWs(); - localStorage.setItem("ws-url", url); - return url; + return localStorage.getItem("viaaas_ws_url") || defaultWs(); } function setWsUrl(url) { - localStorage.setItem("ws-url", url); + localStorage.setItem("viaaas_ws_url", url); location.reload(); } // Tokens function saveToken(token) { - let hTokens = JSON.parse(localStorage.getItem("tokens")) || {}; - let tokens = hTokens[wsUrl] || []; + let hTokens = JSON.parse(localStorage.getItem("viaaas_tokens")) || {}; + let tokens = getTokens(); tokens.push(token); hTokens[wsUrl] = tokens; - localStorage.setItem("tokens", JSON.stringify(hTokens)); + localStorage.setItem("viaaas_tokens", JSON.stringify(hTokens)); } function removeToken(token) { - let hTokens = JSON.parse(localStorage.getItem("tokens")) || {}; - let tokens = hTokens[wsUrl] || []; + let hTokens = JSON.parse(localStorage.getItem("viaaas_tokens")) || {}; + let tokens = getTokens(); tokens = tokens.filter(it => it != token); hTokens[wsUrl] = tokens; - localStorage.setItem("tokens", JSON.stringify(hTokens)); + localStorage.setItem("viaaas_tokens", JSON.stringify(hTokens)); } function getTokens() { - return (JSON.parse(localStorage.getItem("tokens")) || {})[wsUrl] || []; + return (JSON.parse(localStorage.getItem("viaaas_tokens")) || {})[wsUrl] || []; } // Websocket diff --git a/src/main/resources/web/sw.js b/src/main/resources/web/sw.js index 95d4993..4ecda08 100644 --- a/src/main/resources/web/sw.js +++ b/src/main/resources/web/sw.js @@ -15,6 +15,7 @@ self.addEventListener("install", evt => { }); self.addEventListener("fetch", evt => { + if (event.request.mode != "navigate") return; evt.respondWith( fromNetwork(evt.request) .catch(() => fromCache(evt.request))