|
@@ -18,7 +18,7 @@ function cacheOrFetch(handle) {
|
|
|
let promise = requests[url];
|
|
|
if (!promise) {
|
|
|
promise = handle.call(this, url, ...args)
|
|
|
- .catch(err => {
|
|
|
+ .catch((err) => {
|
|
|
console.error(`Error fetching: ${url}`, err);
|
|
|
})
|
|
|
.then(() => {
|
|
@@ -51,9 +51,9 @@ const storage = {
|
|
|
},
|
|
|
getMulti(ids, def) {
|
|
|
return browser.storage.local.get(ids.map(id => this.getKey(id)))
|
|
|
- .then(data => {
|
|
|
+ .then((data) => {
|
|
|
const result = {};
|
|
|
- ids.forEach(id => { result[id] = data[this.getKey(id)] || def; });
|
|
|
+ ids.forEach((id) => { result[id] = data[this.getKey(id)] || def; });
|
|
|
return result;
|
|
|
});
|
|
|
},
|
|
@@ -76,7 +76,7 @@ storage.script = Object.assign({}, storage.base, {
|
|
|
prefix: 'scr:',
|
|
|
dump: ensureListArgs(function dump(items) {
|
|
|
const updates = {};
|
|
|
- items.forEach(item => {
|
|
|
+ items.forEach((item) => {
|
|
|
updates[this.getKey(item.props.id)] = item;
|
|
|
store.scriptMap[item.props.id] = item;
|
|
|
});
|
|
@@ -92,7 +92,7 @@ storage.value = Object.assign({}, storage.base, {
|
|
|
dump(dict) {
|
|
|
const updates = {};
|
|
|
Object.keys(dict)
|
|
|
- .forEach(id => {
|
|
|
+ .forEach((id) => {
|
|
|
const value = dict[id];
|
|
|
updates[this.getKey(id)] = value;
|
|
|
});
|
|
@@ -136,13 +136,13 @@ function initialize() {
|
|
|
});
|
|
|
})
|
|
|
.then(() => browser.storage.local.get())
|
|
|
- .then(data => {
|
|
|
+ .then((data) => {
|
|
|
const scripts = [];
|
|
|
const storeInfo = {
|
|
|
id: 0,
|
|
|
position: 0,
|
|
|
};
|
|
|
- Object.keys(data).forEach(key => {
|
|
|
+ Object.keys(data).forEach((key) => {
|
|
|
const value = data[key];
|
|
|
if (key.startsWith('scr:')) {
|
|
|
// {
|
|
@@ -156,7 +156,7 @@ function initialize() {
|
|
|
storeInfo.position = Math.max(storeInfo.position, getInt(objectGet(value, 'props.position')));
|
|
|
}
|
|
|
});
|
|
|
- scripts.forEach(script => {
|
|
|
+ scripts.forEach((script) => {
|
|
|
script.custom = {
|
|
|
...getDefaultCustom(),
|
|
|
...script.custom,
|
|
@@ -211,7 +211,7 @@ export function sortScripts() {
|
|
|
return pos1 - pos2;
|
|
|
});
|
|
|
return normalizePosition()
|
|
|
- .then(changed => {
|
|
|
+ .then((changed) => {
|
|
|
sendMessageOrIgnore({ cmd: 'ScriptsUpdated' });
|
|
|
return changed;
|
|
|
});
|
|
@@ -266,7 +266,7 @@ export function dumpValueStore(where, valueStore) {
|
|
|
return (where.id
|
|
|
? Promise.resolve(where.id)
|
|
|
: getScript(where).then(script => objectGet(script, 'props.id')))
|
|
|
- .then(id => {
|
|
|
+ .then((id) => {
|
|
|
if (id) return dumpValueStores({ [id]: valueStore });
|
|
|
});
|
|
|
}
|
|
@@ -280,14 +280,14 @@ export function getScriptsByURL(url) {
|
|
|
: store.scripts.filter(script => !script.config.removed && testScript(url, script));
|
|
|
const reqKeys = {};
|
|
|
const cacheKeys = {};
|
|
|
- scripts.forEach(script => {
|
|
|
+ scripts.forEach((script) => {
|
|
|
if (script.config.enabled) {
|
|
|
if (!script.custom.pathMap) buildPathMap(script);
|
|
|
const { pathMap } = script.custom;
|
|
|
- script.meta.require.forEach(key => {
|
|
|
+ script.meta.require.forEach((key) => {
|
|
|
reqKeys[pathMap[key] || key] = 1;
|
|
|
});
|
|
|
- Object.values(script.meta.resources).forEach(key => {
|
|
|
+ Object.values(script.meta.resources).forEach((key) => {
|
|
|
cacheKeys[pathMap[key] || key] = 1;
|
|
|
});
|
|
|
}
|
|
@@ -301,7 +301,7 @@ export function getScriptsByURL(url) {
|
|
|
GM_deleteValue: 1,
|
|
|
};
|
|
|
const scriptsWithValue = enabledScripts
|
|
|
- .filter(script => {
|
|
|
+ .filter((script) => {
|
|
|
const grant = objectGet(script, 'meta.grant');
|
|
|
return grant && grant.some(gm => gmValues[gm]);
|
|
|
});
|
|
@@ -326,7 +326,7 @@ export function getScriptsByURL(url) {
|
|
|
export function getData() {
|
|
|
const cacheKeys = {};
|
|
|
const { scripts } = store;
|
|
|
- scripts.forEach(script => {
|
|
|
+ scripts.forEach((script) => {
|
|
|
const icon = objectGet(script, 'meta.icon');
|
|
|
if (isRemote(icon)) {
|
|
|
const pathMap = objectGet(script, 'custom.pathMap') || {};
|
|
@@ -406,7 +406,7 @@ function saveScript(script, code) {
|
|
|
props.uri = getNameURI(script);
|
|
|
props.uuid = props.uuid || getUUID(props.id);
|
|
|
// Do not allow script with same name and namespace
|
|
|
- if (store.scripts.some(item => {
|
|
|
+ if (store.scripts.some((item) => {
|
|
|
const itemProps = item.props || {};
|
|
|
return props.id !== itemProps.id && props.uri === itemProps.uri;
|
|
|
})) {
|
|
@@ -445,15 +445,15 @@ export function updateScriptInfo(id, data) {
|
|
|
|
|
|
export function getExportData(withValues) {
|
|
|
return getScripts()
|
|
|
- .then(scripts => {
|
|
|
+ .then((scripts) => {
|
|
|
const ids = scripts.map(({ props: { id } }) => id);
|
|
|
return storage.code.getMulti(ids)
|
|
|
- .then(codeMap => {
|
|
|
+ .then((codeMap) => {
|
|
|
const data = {};
|
|
|
data.items = scripts.map(script => ({ script, code: codeMap[script.props.id] }));
|
|
|
if (withValues) {
|
|
|
return storage.value.getMulti(ids)
|
|
|
- .then(values => {
|
|
|
+ .then((values) => {
|
|
|
data.values = values;
|
|
|
return data;
|
|
|
});
|
|
@@ -480,7 +480,7 @@ export function parseScript(data) {
|
|
|
},
|
|
|
};
|
|
|
return getScript({ id, meta })
|
|
|
- .then(oldScript => {
|
|
|
+ .then((oldScript) => {
|
|
|
let script;
|
|
|
if (oldScript) {
|
|
|
if (isNew) throw i18n('msgNamespaceConflict');
|
|
@@ -509,7 +509,7 @@ export function parseScript(data) {
|
|
|
buildPathMap(script, data.url);
|
|
|
return saveScript(script, code).then(() => script);
|
|
|
})
|
|
|
- .then(script => {
|
|
|
+ .then((script) => {
|
|
|
fetchScriptResources(script, data);
|
|
|
Object.assign(result.data.update, script, update);
|
|
|
result.data.where = { id: script.props.id };
|
|
@@ -540,7 +540,7 @@ function buildPathMap(script, base) {
|
|
|
function fetchScriptResources(script, cache) {
|
|
|
const { meta, custom: { pathMap } } = script;
|
|
|
// @require
|
|
|
- meta.require.forEach(key => {
|
|
|
+ meta.require.forEach((key) => {
|
|
|
const fullUrl = pathMap[key] || key;
|
|
|
const cached = objectGet(cache, ['require', fullUrl]);
|
|
|
if (cached) {
|
|
@@ -550,7 +550,7 @@ function fetchScriptResources(script, cache) {
|
|
|
}
|
|
|
});
|
|
|
// @resource
|
|
|
- Object.values(meta.resources).forEach(url => {
|
|
|
+ Object.values(meta.resources).forEach((url) => {
|
|
|
const fullUrl = pathMap[url] || url;
|
|
|
const cached = objectGet(cache, ['resources', fullUrl]);
|
|
|
if (cached) {
|
|
@@ -592,8 +592,8 @@ export function vacuum() {
|
|
|
[storage.code, codeKeys],
|
|
|
];
|
|
|
return browser.storage.local.get()
|
|
|
- .then(data => {
|
|
|
- Object.keys(data).forEach(key => {
|
|
|
+ .then((data) => {
|
|
|
+ Object.keys(data).forEach((key) => {
|
|
|
mappings.some(([substore, map]) => {
|
|
|
const { prefix } = substore;
|
|
|
if (key.startsWith(prefix)) {
|
|
@@ -608,16 +608,16 @@ export function vacuum() {
|
|
|
if (obj[key] < 0) obj[key] = 1;
|
|
|
else if (!obj[key]) obj[key] = 2;
|
|
|
};
|
|
|
- store.scripts.forEach(script => {
|
|
|
+ store.scripts.forEach((script) => {
|
|
|
const { id } = script.props;
|
|
|
touch(codeKeys, id);
|
|
|
touch(valueKeys, id);
|
|
|
if (!script.custom.pathMap) buildPathMap(script);
|
|
|
const { pathMap } = script.custom;
|
|
|
- script.meta.require.forEach(url => {
|
|
|
+ script.meta.require.forEach((url) => {
|
|
|
touch(requireKeys, pathMap[url] || url);
|
|
|
});
|
|
|
- Object.values(script.meta.resources).forEach(url => {
|
|
|
+ Object.values(script.meta.resources).forEach((url) => {
|
|
|
touch(cacheKeys, pathMap[url] || url);
|
|
|
});
|
|
|
const { icon } = script.meta;
|
|
@@ -627,7 +627,7 @@ export function vacuum() {
|
|
|
}
|
|
|
});
|
|
|
mappings.forEach(([substore, map]) => {
|
|
|
- Object.keys(map).forEach(key => {
|
|
|
+ Object.keys(map).forEach((key) => {
|
|
|
const value = map[key];
|
|
|
if (value < 0) {
|
|
|
// redundant value
|