diff --git a/SB.js b/SB.js index 0eb8cfb0..b38c9642 100644 --- a/SB.js +++ b/SB.js @@ -4,27 +4,6 @@ Map.prototype.toJSON = function() { return Array.from(this.entries()); }; -function storeEncode(data) { - if(!(data instanceof Map)) return data; - return JSON.stringify(data); -} - -function mapDecode(data, key) { - if(typeof data !== "string") return data; - try { - let str = JSON.parse(data); - if(!Array.isArray(str)) return data; - return new Map(str); - } catch(e) { - return data - } -} - -function mapProxy(data, key) { - if(!(data instanceof Map)) return data; - return new mapIO(key); -} - class mapIO extends Map { constructor(id) { super(); @@ -73,6 +52,27 @@ class mapIO extends Map { } } +function storeEncode(data) { + if(!(data instanceof Map)) return data; + return JSON.stringify(data); +} + +function mapDecode(data, key) { + if(typeof data !== "string") return data; + try { + let str = JSON.parse(data); + if(!Array.isArray(str)) return data; + return new Map(str); + } catch(e) { + return data + } +} + +function mapProxy(data, key) { + if(!(data instanceof Map)) return data; + return new mapIO(key); +} + function configProxy() { chrome.storage.onChanged.addListener((changes, namespace) => { for (key in changes) { diff --git a/popup.js b/popup.js index 19408027..15b489f8 100644 --- a/popup.js +++ b/popup.js @@ -4,21 +4,21 @@ async function runThePopup() { //is it in the popup or content script var inPopup = true; if (chrome.tabs == undefined) { - //this is on the content script, use direct communication - chrome.tabs = {}; - chrome.tabs.sendMessage = function(id, request, callback) { - messageListener(request, null, callback); - } - - //add a dummy query method - chrome.tabs.query = function(config, callback) { - callback([{ - url: document.URL, - id: -1 - }]); - } - - inPopup = false; + //this is on the content script, use direct communication + chrome.tabs = {}; + chrome.tabs.sendMessage = function(id, request, callback) { + messageListener(request, null, callback); + } + + //add a dummy query method + chrome.tabs.query = function(config, callback) { + callback([{ + url: document.URL, + id: -1 + }]); + } + + inPopup = false; } await wait(() => SB.config !== undefined);