mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-15 16:07:06 +03:00
Formatting fixes
This commit is contained in:
42
SB.js
42
SB.js
@@ -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) {
|
||||||
|
|||||||
30
popup.js
30
popup.js
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user