mirror of
https://codeberg.org/nobody/LocalCDN.git
synced 2025-02-02 20:37:04 +01:00
Create regular expressions as constants
This commit is contained in:
parent
93cefdd8c0
commit
f60b1c8f2e
@ -273,6 +273,11 @@ const Regex = {
|
||||
'BOOTSTRAP_FONTS_ONLY': /\/bootstrap\/(?:\d{1,2}\.){1,3}\d{1,2}\/fonts\//,
|
||||
'ROCKET_LOADER': /ajax\.cloudflare\.com\/cdn-cgi\/scripts\/[a-zA-Z0-9]{8}\/cloudflare-static\/rocket-loader\.min\.js/,
|
||||
'TWITTER_BOOTSTRAP_ALPHA_BETA': /-(alpha|beta).?\d?/,
|
||||
'INTERNAL_STATISTICS_DATA': /((2\d)\d{2})-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])/,
|
||||
'DOMAIN': /[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,24}/,
|
||||
'INTERNAL_RESOURCES': /resources\/[0-9a-z.-]+\/((?:\d{1,2}\.){1,3}\d{1,2})?.*\.(css|jsm)/,
|
||||
'ISO_DATE': /((2\d)\d{2})-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])/,
|
||||
'HEX_COLOR': /#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/,
|
||||
};
|
||||
|
||||
const MaterialIcons = {
|
||||
|
@ -213,7 +213,7 @@ storageManager._validateDomainsAndStatistics = function (type, obj) {
|
||||
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) {
|
||||
if (((Regex.DOMAIN).test(key) || key === '') && value === true) {
|
||||
valid[key] = value;
|
||||
} else {
|
||||
alert(`${chrome.i18n.getMessage('dialogImportFailed')}: ${key}`);
|
||||
@ -222,12 +222,12 @@ storageManager._validateDomainsAndStatistics = function (type, obj) {
|
||||
}
|
||||
} else if (type === 'internalStatisticsData') {
|
||||
for (const [date, values] of Object.entries(obj)) {
|
||||
if ((/((2\d)\d{2})-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])/).test(date)) {
|
||||
if ((Regex.INTERNAL_STATISTICS_DATA).test(date)) {
|
||||
for (const [types, category] of Object.entries(values)) {
|
||||
if (types === 'frameworks') {
|
||||
for (const [name, counter] of Object.entries(category)) {
|
||||
// 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)) {
|
||||
if (!(Regex.INTERNAL_RESOURCES).test(name) && !storageManager._validateNumbers(counter)) {
|
||||
alert(`${chrome.i18n.getMessage('dialogImportFailed')}: ${name}`);
|
||||
throw InvalidFile;
|
||||
}
|
||||
@ -235,7 +235,7 @@ storageManager._validateDomainsAndStatistics = function (type, obj) {
|
||||
} else if (types === 'cdns') {
|
||||
for (const [name, counter] of Object.entries(category)) {
|
||||
// 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)) {
|
||||
if (!(Regex.DOMAIN).test(name) && !storageManager._validateNumbers(counter)) {
|
||||
alert(`${chrome.i18n.getMessage('dialogImportFailed')}: ${name}`);
|
||||
throw InvalidFile;
|
||||
}
|
||||
@ -259,9 +259,9 @@ storageManager._validateDomainsAndStatistics = function (type, obj) {
|
||||
};
|
||||
|
||||
storageManager._validateStrings = function (value) {
|
||||
if ((/((2\d)\d{2})-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])/).test(value)) {
|
||||
if ((Regex.ISO_DATE).test(value)) {
|
||||
return value;
|
||||
} else if ((/#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/).test(value)) {
|
||||
} else if ((Regex.HEX_COLOR).test(value)) {
|
||||
return value;
|
||||
} else if (value === 'Default' || value === 'Light' || value === 'Grey') {
|
||||
return value;
|
||||
|
Loading…
x
Reference in New Issue
Block a user