2021-01-01 14:27:58 +00:00
|
|
|
/* global tryJSONparse */// toolbox.js
|
2018-01-01 17:02:49 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-11-11 11:53:40 +00:00
|
|
|
(() => {
|
2021-01-01 14:27:58 +00:00
|
|
|
let LZString;
|
|
|
|
|
2020-11-11 11:53:40 +00:00
|
|
|
/** @namespace StorageExtras */
|
|
|
|
const StorageExtras = {
|
|
|
|
async getValue(key) {
|
|
|
|
return (await this.get(key))[key];
|
|
|
|
},
|
|
|
|
async setValue(key, value) {
|
|
|
|
await this.set({[key]: value});
|
|
|
|
},
|
|
|
|
async getLZValue(key) {
|
|
|
|
return (await this.getLZValues([key]))[key];
|
|
|
|
},
|
|
|
|
async getLZValues(keys = Object.values(this.LZ_KEY)) {
|
2021-01-01 14:27:58 +00:00
|
|
|
const [data] = await Promise.all([
|
2020-11-11 11:53:40 +00:00
|
|
|
this.get(keys),
|
2021-01-01 14:27:58 +00:00
|
|
|
LZString || loadLZString(),
|
2020-11-11 11:53:40 +00:00
|
|
|
]);
|
|
|
|
for (const key of keys) {
|
|
|
|
const value = data[key];
|
|
|
|
data[key] = value && tryJSONparse(LZString.decompressFromUTF16(value));
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
async setLZValue(key, value) {
|
2021-01-01 14:27:58 +00:00
|
|
|
if (!LZString) await loadLZString();
|
2020-11-11 11:53:40 +00:00
|
|
|
return this.setValue(key, LZString.compressToUTF16(JSON.stringify(value)));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
/** @namespace StorageExtrasSync */
|
|
|
|
const StorageExtrasSync = {
|
|
|
|
LZ_KEY: {
|
|
|
|
csslint: 'editorCSSLintConfig',
|
|
|
|
stylelint: 'editorStylelintConfig',
|
|
|
|
usercssTemplate: 'usercssTemplate',
|
|
|
|
},
|
|
|
|
};
|
2021-01-01 14:27:58 +00:00
|
|
|
|
|
|
|
async function loadLZString() {
|
|
|
|
await require(['/vendor/lz-string-unsafe/lz-string-unsafe.min']);
|
|
|
|
LZString = window.LZString || window.LZStringUnsafe;
|
|
|
|
}
|
|
|
|
|
2020-11-11 11:53:40 +00:00
|
|
|
/** @type {chrome.storage.StorageArea|StorageExtras} */
|
|
|
|
window.chromeLocal = Object.assign(browser.storage.local, StorageExtras);
|
|
|
|
/** @type {chrome.storage.StorageArea|StorageExtras|StorageExtrasSync} */
|
|
|
|
window.chromeSync = Object.assign(browser.storage.sync, StorageExtras, StorageExtrasSync);
|
2018-01-04 14:04:23 +00:00
|
|
|
})();
|