use viaaas prefix for localstorage check navigate mode

This commit is contained in:
creeper123123321 2021-07-01 13:52:43 -03:00
parent aadfba6bd0
commit 1b232ae693
4 changed files with 18 additions and 19 deletions

View File

@ -1,22 +1,22 @@
// Account storage // Account storage
function storeMcAccount(accessToken, clientToken, name, id, msUser = null) { 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}; let account = {accessToken: accessToken, clientToken: clientToken, name: name, id: id, msUser: msUser};
accounts.push(account); accounts.push(account);
localStorage.setItem("mc_accounts", JSON.stringify(accounts)); localStorage.setItem("viaaas_mc_accounts", JSON.stringify(accounts));
refreshAccountList(); refreshAccountList();
return account; return account;
} }
function removeMcAccount(id) { function removeMcAccount(id) {
let accounts = JSON.parse(localStorage.getItem("mc_accounts")) || []; let accounts = getMcAccounts();
accounts = accounts.filter(it => it.id != id); accounts = accounts.filter(it => it.id != id);
localStorage.setItem("mc_accounts", JSON.stringify(accounts)); localStorage.setItem("viaaas_mc_accounts", JSON.stringify(accounts));
refreshAccountList(); refreshAccountList();
} }
function getMcAccounts() { function getMcAccounts() {
return JSON.parse(localStorage.getItem("mc_accounts")) || []; return JSON.parse(localStorage.getItem("viaaas_mc_accounts")) || [];
} }
function findAccountByMcName(name) { function findAccountByMcName(name) {

View File

@ -2,9 +2,9 @@ function defaultCors() {
return "https://crp123-cors.herokuapp.com/"; return "https://crp123-cors.herokuapp.com/";
} }
function getCorsProxy() { function getCorsProxy() {
return localStorage.getItem("cors-proxy") || defaultCors(); return localStorage.getItem("viaaas_cors_proxy") || defaultCors();
} }
function setCorsProxy(url) { function setCorsProxy(url) {
localStorage.setItem("cors-proxy", url); localStorage.setItem("viaaas_cors_proxy", url);
refreshCorsStatus(); refreshCorsStatus();
} }

View File

@ -9,34 +9,32 @@ function defaultWs() {
} }
function getWsUrl() { function getWsUrl() {
let url = localStorage.getItem("ws-url") || defaultWs(); return localStorage.getItem("viaaas_ws_url") || defaultWs();
localStorage.setItem("ws-url", url);
return url;
} }
function setWsUrl(url) { function setWsUrl(url) {
localStorage.setItem("ws-url", url); localStorage.setItem("viaaas_ws_url", url);
location.reload(); location.reload();
} }
// Tokens // Tokens
function saveToken(token) { function saveToken(token) {
let hTokens = JSON.parse(localStorage.getItem("tokens")) || {}; let hTokens = JSON.parse(localStorage.getItem("viaaas_tokens")) || {};
let tokens = hTokens[wsUrl] || []; let tokens = getTokens();
tokens.push(token); tokens.push(token);
hTokens[wsUrl] = tokens; hTokens[wsUrl] = tokens;
localStorage.setItem("tokens", JSON.stringify(hTokens)); localStorage.setItem("viaaas_tokens", JSON.stringify(hTokens));
} }
function removeToken(token) { function removeToken(token) {
let hTokens = JSON.parse(localStorage.getItem("tokens")) || {}; let hTokens = JSON.parse(localStorage.getItem("viaaas_tokens")) || {};
let tokens = hTokens[wsUrl] || []; let tokens = getTokens();
tokens = tokens.filter(it => it != token); tokens = tokens.filter(it => it != token);
hTokens[wsUrl] = tokens; hTokens[wsUrl] = tokens;
localStorage.setItem("tokens", JSON.stringify(hTokens)); localStorage.setItem("viaaas_tokens", JSON.stringify(hTokens));
} }
function getTokens() { function getTokens() {
return (JSON.parse(localStorage.getItem("tokens")) || {})[wsUrl] || []; return (JSON.parse(localStorage.getItem("viaaas_tokens")) || {})[wsUrl] || [];
} }
// Websocket // Websocket

View File

@ -15,6 +15,7 @@ self.addEventListener("install", evt => {
}); });
self.addEventListener("fetch", evt => { self.addEventListener("fetch", evt => {
if (event.request.mode != "navigate") return;
evt.respondWith( evt.respondWith(
fromNetwork(evt.request) fromNetwork(evt.request)
.catch(() => fromCache(evt.request)) .catch(() => fromCache(evt.request))