Formatting fixes

This commit is contained in:
Ajay Ramachandran
2020-01-09 12:12:49 -05:00
parent 52f60d70e2
commit f42c23cd9a
2 changed files with 36 additions and 36 deletions

42
SB.js
View File

@@ -4,27 +4,6 @@ Map.prototype.toJSON = function() {
return Array.from(this.entries()); 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 { class mapIO extends Map {
constructor(id) { constructor(id) {
super(); 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() { function configProxy() {
chrome.storage.onChanged.addListener((changes, namespace) => { chrome.storage.onChanged.addListener((changes, namespace) => {
for (key in changes) { for (key in changes) {

View File

@@ -4,21 +4,21 @@ async function runThePopup() {
//is it in the popup or content script //is it in the popup or content script
var inPopup = true; var inPopup = true;
if (chrome.tabs == undefined) { if (chrome.tabs == undefined) {
//this is on the content script, use direct communication //this is on the content script, use direct communication
chrome.tabs = {}; chrome.tabs = {};
chrome.tabs.sendMessage = function(id, request, callback) { chrome.tabs.sendMessage = function(id, request, callback) {
messageListener(request, null, callback); messageListener(request, null, callback);
} }
//add a dummy query method //add a dummy query method
chrome.tabs.query = function(config, callback) { chrome.tabs.query = function(config, callback) {
callback([{ callback([{
url: document.URL, url: document.URL,
id: -1 id: -1
}]); }]);
} }
inPopup = false; inPopup = false;
} }
await wait(() => SB.config !== undefined); await wait(() => SB.config !== undefined);