mirror of
https://codeberg.org/nobody/LocalCDN.git
synced 2025-06-05 21:49:31 +02:00
Just code style (JS)
This commit is contained in:
@@ -14,12 +14,21 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
|
||||
const InvalidFile = 'Invalid file!';
|
||||
|
||||
|
||||
/**
|
||||
* Storage Manager
|
||||
*/
|
||||
|
||||
var storageManager = {};
|
||||
|
||||
|
||||
/**
|
||||
* Public Methods
|
||||
*/
|
||||
@@ -78,12 +87,12 @@ storageManager.migrateData = function (target) {
|
||||
|
||||
storageManager.export = function () {
|
||||
let filename = new Date().toISOString();
|
||||
filename = filename.substring(0, 10) + '_localcdn_backup.txt';
|
||||
filename = `${filename.substring(0, 10)}_localcdn_backup.txt`;
|
||||
|
||||
storageManager.type.get(null, function (items) {
|
||||
delete items['whitelistedDomains'];
|
||||
let element = document.createElement('a');
|
||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(items, null, ' ')));
|
||||
element.setAttribute('href', `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(items, null, ' '))}`);
|
||||
element.setAttribute('download', filename);
|
||||
element.style.display = 'none';
|
||||
document.body.appendChild(element);
|
||||
@@ -169,13 +178,13 @@ storageManager._validation = function (content) {
|
||||
// Set default if not existing in file
|
||||
imported[key] = value;
|
||||
} else {
|
||||
alert(chrome.i18n.getMessage('dialogImportFailed') + '\n\n' + key + ': ' + content[key]);
|
||||
throw 'Invalid file!';
|
||||
alert(`${chrome.i18n.getMessage('dialogImportFailed')}\n\n${key}: ${content[key]}`);
|
||||
throw InvalidFile;
|
||||
}
|
||||
}
|
||||
|
||||
// set values directly
|
||||
wrappers.setIcon({ path: imported['selectedIcon'] }, 'Enabled');
|
||||
wrappers.setIcon({'path': imported['selectedIcon']}, 'Enabled');
|
||||
storageManager.amountInjected = imported['amountInjected'];
|
||||
storageManager.statistics = imported['internalStatisticsData'];
|
||||
|
||||
@@ -187,13 +196,15 @@ storageManager._validation = function (content) {
|
||||
|
||||
storageManager._validateDomainsAndStatistics = function (type, obj) {
|
||||
let valid = {};
|
||||
|
||||
if (type === 'allowedDomainsGoogleFonts' || type === 'domainsManipulateDOM' || type === 'allowlistedDomains') {
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
if ((/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,24}/.test(key) || key === '') && value === true) {
|
||||
valid[key] = value;
|
||||
} else {
|
||||
alert(chrome.i18n.getMessage('dialogImportFailed') + ': ' + key);
|
||||
throw 'Invalid file!';
|
||||
alert(`${chrome.i18n.getMessage('dialogImportFailed')}: ${key}`);
|
||||
throw InvalidFile;
|
||||
}
|
||||
}
|
||||
} else if (type === 'internalStatisticsData') {
|
||||
@@ -202,32 +213,34 @@ storageManager._validateDomainsAndStatistics = function (type, obj) {
|
||||
for (const [types, category] of Object.entries(values)) {
|
||||
if (types === 'frameworks') {
|
||||
for (const [name, counter] of Object.entries(category)) {
|
||||
if (!/resources\/[0-9a-z.-]+\/((?:\d{1,2}\.){1,3}\d{1,2})?.*\.(css|jsm)/.test(name) && !storageManager._validateNumbers(counter)) {
|
||||
alert(chrome.i18n.getMessage('dialogImportFailed') + ': ' + name);
|
||||
throw 'Invalid file!';
|
||||
// eslint-disable-next-line max-len
|
||||
if (!(/resources\/[0-9a-z.-]+\/((?:\d{1,2}\.){1,3}\d{1,2})?.*\.(css|jsm)/).test(name) && !storageManager._validateNumbers(counter)) {
|
||||
alert(`${chrome.i18n.getMessage('dialogImportFailed')}: ${name}`);
|
||||
throw InvalidFile;
|
||||
}
|
||||
}
|
||||
} else if (types === 'cdns') {
|
||||
for (const [name, counter] of Object.entries(category)) {
|
||||
if (!/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,24}/.test(name) && !storageManager._validateNumbers(counter)) {
|
||||
alert(chrome.i18n.getMessage('dialogImportFailed') + ': ' + name);
|
||||
throw 'Invalid file!';
|
||||
// eslint-disable-next-line no-useless-escape, max-len
|
||||
if (!(/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,24}/).test(name) && !storageManager._validateNumbers(counter)) {
|
||||
alert(`${chrome.i18n.getMessage('dialogImportFailed')}: ${name}`);
|
||||
throw InvalidFile;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert(chrome.i18n.getMessage('dialogImportFailed') + ': ' + type);
|
||||
throw 'Invalid file!';
|
||||
alert(`${chrome.i18n.getMessage('dialogImportFailed')}: ${type}`);
|
||||
throw InvalidFile;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert(chrome.i18n.getMessage('dialogImportFailed') + ': ' + date);
|
||||
throw 'Invalid file!';
|
||||
alert(`${chrome.i18n.getMessage('dialogImportFailed')}: ${date}`);
|
||||
throw InvalidFile;
|
||||
}
|
||||
}
|
||||
valid = obj;
|
||||
} else {
|
||||
alert(chrome.i18n.getMessage('dialogImportFailed') + ': ' + type);
|
||||
throw 'Invalid file!';
|
||||
alert(`${chrome.i18n.getMessage('dialogImportFailed')}: ${type}`);
|
||||
throw InvalidFile;
|
||||
}
|
||||
return valid;
|
||||
};
|
||||
@@ -252,6 +265,11 @@ storageManager._validateNumbers = function (value) {
|
||||
return isNaN(value) ? 0 : value;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Initializations
|
||||
*/
|
||||
|
||||
storageManager.data = {};
|
||||
storageManager.type = chrome.storage.local;
|
||||
storageManager.amountInjected = 0;
|
||||
|
Reference in New Issue
Block a user