mirror of
https://codeberg.org/nobody/LocalCDN.git
synced 2025-02-23 15:17:49 +01:00
Only formatting
This commit is contained in:
parent
3591496f9a
commit
ed66f98580
@ -29,7 +29,6 @@ var helpers = {};
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
helpers.insertI18nContentIntoDocument = function (document) {
|
helpers.insertI18nContentIntoDocument = function (document) {
|
||||||
|
|
||||||
let scriptDirection, i18nElements, translationComplete;
|
let scriptDirection, i18nElements, translationComplete;
|
||||||
|
|
||||||
translationComplete = true;
|
translationComplete = true;
|
||||||
@ -37,11 +36,10 @@ helpers.insertI18nContentIntoDocument = function (document) {
|
|||||||
i18nElements = document.querySelectorAll('[data-i18n-content]');
|
i18nElements = document.querySelectorAll('[data-i18n-content]');
|
||||||
|
|
||||||
i18nElements.forEach(function (i18nElement) {
|
i18nElements.forEach(function (i18nElement) {
|
||||||
|
|
||||||
let i18nMessageName = i18nElement.getAttribute('data-i18n-content');
|
let i18nMessageName = i18nElement.getAttribute('data-i18n-content');
|
||||||
|
|
||||||
if(chrome.i18n.getMessage(i18nMessageName) !== '') {
|
if (chrome.i18n.getMessage(i18nMessageName) !== '') {
|
||||||
if (i18nElement.type === "button") {
|
if (i18nElement.type === 'button') {
|
||||||
i18nElement.value = chrome.i18n.getMessage(i18nMessageName);
|
i18nElement.value = chrome.i18n.getMessage(i18nMessageName);
|
||||||
} else {
|
} else {
|
||||||
i18nElement.innerText = chrome.i18n.getMessage(i18nMessageName);
|
i18nElement.innerText = chrome.i18n.getMessage(i18nMessageName);
|
||||||
@ -53,18 +51,15 @@ helpers.insertI18nContentIntoDocument = function (document) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return translationComplete;
|
return translationComplete;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers.insertI18nTitlesIntoDocument = function (document) {
|
helpers.insertI18nTitlesIntoDocument = function (document) {
|
||||||
|
|
||||||
let scriptDirection, i18nElements;
|
let scriptDirection, i18nElements;
|
||||||
|
|
||||||
scriptDirection = helpers.determineScriptDirection(navigator.language);
|
scriptDirection = helpers.determineScriptDirection(navigator.language);
|
||||||
i18nElements = document.querySelectorAll('[data-i18n-title]');
|
i18nElements = document.querySelectorAll('[data-i18n-title]');
|
||||||
|
|
||||||
i18nElements.forEach(function (i18nElement) {
|
i18nElements.forEach(function (i18nElement) {
|
||||||
|
|
||||||
let i18nMessageName = i18nElement.getAttribute('data-i18n-title');
|
let i18nMessageName = i18nElement.getAttribute('data-i18n-title');
|
||||||
|
|
||||||
i18nElement.setAttribute('title', chrome.i18n.getMessage(i18nMessageName));
|
i18nElement.setAttribute('title', chrome.i18n.getMessage(i18nMessageName));
|
||||||
@ -73,19 +68,42 @@ helpers.insertI18nTitlesIntoDocument = function (document) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
helpers.languageIsFullySupported = function (language) {
|
helpers.languageIsFullySupported = function (language) {
|
||||||
|
|
||||||
let languageSupported, supportedLanguages;
|
let languageSupported, supportedLanguages;
|
||||||
|
|
||||||
languageSupported = false;
|
languageSupported = false;
|
||||||
|
|
||||||
supportedLanguages = [
|
supportedLanguages = [
|
||||||
'ar', 'bg', 'zh', 'cs', 'da', 'nl', 'en', 'eo', 'et', 'fi',
|
'ar',
|
||||||
'fr', 'de', 'el', 'he', 'hu', 'is', 'id', 'it', 'ja', 'ko',
|
'bg',
|
||||||
'nb', 'pl', 'pt', 'ro', 'ru', 'es', 'sv', 'tr'
|
'zh',
|
||||||
|
'cs',
|
||||||
|
'da',
|
||||||
|
'nl',
|
||||||
|
'en',
|
||||||
|
'eo',
|
||||||
|
'et',
|
||||||
|
'fi',
|
||||||
|
'fr',
|
||||||
|
'de',
|
||||||
|
'el',
|
||||||
|
'he',
|
||||||
|
'hu',
|
||||||
|
'is',
|
||||||
|
'id',
|
||||||
|
'it',
|
||||||
|
'ja',
|
||||||
|
'ko',
|
||||||
|
'nb',
|
||||||
|
'pl',
|
||||||
|
'pt',
|
||||||
|
'ro',
|
||||||
|
'ru',
|
||||||
|
'es',
|
||||||
|
'sv',
|
||||||
|
'tr',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let supportedLanguage of supportedLanguages) {
|
for (let supportedLanguage of supportedLanguages) {
|
||||||
|
|
||||||
if (language.search(supportedLanguage) !== -1) {
|
if (language.search(supportedLanguage) !== -1) {
|
||||||
languageSupported = true;
|
languageSupported = true;
|
||||||
}
|
}
|
||||||
@ -95,7 +113,6 @@ helpers.languageIsFullySupported = function (language) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
helpers.normalizeDomain = function (domain) {
|
helpers.normalizeDomain = function (domain) {
|
||||||
|
|
||||||
domain = domain.toLowerCase().trim();
|
domain = domain.toLowerCase().trim();
|
||||||
|
|
||||||
if (domain.startsWith(Address.WWW_PREFIX)) {
|
if (domain.startsWith(Address.WWW_PREFIX)) {
|
||||||
@ -106,7 +123,6 @@ helpers.normalizeDomain = function (domain) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
helpers.extractDomainFromUrl = function (url, normalize) {
|
helpers.extractDomainFromUrl = function (url, normalize) {
|
||||||
|
|
||||||
if (/^(?!(http[s]?|file):\/\/).*/.test(url)) {
|
if (/^(?!(http[s]?|file):\/\/).*/.test(url)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -135,7 +151,6 @@ helpers.extractDomainFromUrl = function (url, normalize) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
helpers.extractFilenameFromPath = function (path) {
|
helpers.extractFilenameFromPath = function (path) {
|
||||||
|
|
||||||
let pathSegments, filename;
|
let pathSegments, filename;
|
||||||
|
|
||||||
pathSegments = path.split('/');
|
pathSegments = path.split('/');
|
||||||
@ -145,16 +160,14 @@ helpers.extractFilenameFromPath = function (path) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
helpers.generateRandomHexString = function (length) {
|
helpers.generateRandomHexString = function (length) {
|
||||||
|
|
||||||
let randomValues, randomHexString;
|
let randomValues, randomHexString;
|
||||||
|
|
||||||
randomValues = crypto.getRandomValues(new Uint8Array(length));
|
randomValues = crypto.getRandomValues(new Uint8Array(length));
|
||||||
randomHexString = '';
|
randomHexString = '';
|
||||||
|
|
||||||
for (let value of randomValues) {
|
for (let value of randomValues) {
|
||||||
|
|
||||||
// eslint-disable-next-line no-bitwise
|
// eslint-disable-next-line no-bitwise
|
||||||
let hexValue = (0 ^ value & 15 >> 0 / 4).toString(16);
|
let hexValue = (0 ^ (value & (15 >> (0 / 4)))).toString(16);
|
||||||
randomHexString += hexValue;
|
randomHexString += hexValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,9 +175,7 @@ helpers.generateRandomHexString = function (length) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
helpers.determineCdnName = function (domainName) {
|
helpers.determineCdnName = function (domainName) {
|
||||||
|
|
||||||
switch (domainName) {
|
switch (domainName) {
|
||||||
|
|
||||||
case 'ajax.googleapis.com':
|
case 'ajax.googleapis.com':
|
||||||
return 'Google Hosted Libraries';
|
return 'Google Hosted Libraries';
|
||||||
case 'ajax.aspnetcdn.com':
|
case 'ajax.aspnetcdn.com':
|
||||||
@ -219,12 +230,10 @@ helpers.determineCdnName = function (domainName) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
helpers.determineResourceName = function (filename) {
|
helpers.determineResourceName = function (filename) {
|
||||||
|
if (filename in ListOfFiles) {
|
||||||
if(filename in ListOfFiles) {
|
|
||||||
return ListOfFiles[filename];
|
return ListOfFiles[filename];
|
||||||
}
|
}
|
||||||
return 'Unknown';
|
return 'Unknown';
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers.determineBundle = function (path = '') {
|
helpers.determineBundle = function (path = '') {
|
||||||
@ -238,7 +247,6 @@ helpers.determineBundle = function (path = '') {
|
|||||||
};
|
};
|
||||||
|
|
||||||
helpers.determineScriptDirection = function (language) {
|
helpers.determineScriptDirection = function (language) {
|
||||||
|
|
||||||
let rightToLeftLanguages, scriptDirection;
|
let rightToLeftLanguages, scriptDirection;
|
||||||
|
|
||||||
rightToLeftLanguages = ['ar', 'he'];
|
rightToLeftLanguages = ['ar', 'he'];
|
||||||
@ -253,14 +261,12 @@ helpers.determineScriptDirection = function (language) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
helpers.formatNumber = function (number) {
|
helpers.formatNumber = function (number) {
|
||||||
|
|
||||||
if (typeof number === 'number') {
|
if (typeof number === 'number') {
|
||||||
return number.toLocaleString();
|
return number.toLocaleString();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers.formatVersion = function (version) {
|
helpers.formatVersion = function (version) {
|
||||||
|
|
||||||
if (version.indexOf('beta') === -1) {
|
if (version.indexOf('beta') === -1) {
|
||||||
return version;
|
return version;
|
||||||
} else {
|
} else {
|
||||||
@ -276,7 +282,7 @@ helpers.setLastVersion = function (type, version) {
|
|||||||
* If-Else-If: 0-5ms (Average <1ms)
|
* If-Else-If: 0-5ms (Average <1ms)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(version !== null && version !== undefined) {
|
if (version !== null && version !== undefined) {
|
||||||
version = version.toString();
|
version = version.toString();
|
||||||
}
|
}
|
||||||
if (type.includes('/algoliasearch/3.')) {
|
if (type.includes('/algoliasearch/3.')) {
|
||||||
@ -534,7 +540,6 @@ helpers.setLastVersion = function (type, version) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
helpers.compareVersion = function (v1, v2) {
|
helpers.compareVersion = function (v1, v2) {
|
||||||
/**
|
/**
|
||||||
* compareVersion( '1.5.7' , '1.5.8' ) is TRUE
|
* compareVersion( '1.5.7' , '1.5.8' ) is TRUE
|
||||||
@ -544,13 +549,13 @@ helpers.compareVersion = function (v1, v2) {
|
|||||||
v1 = v1.split('.');
|
v1 = v1.split('.');
|
||||||
v2 = v2.split('.');
|
v2 = v2.split('.');
|
||||||
const k = Math.min(v1.length, v2.length);
|
const k = Math.min(v1.length, v2.length);
|
||||||
for (let i = 0; i < k; ++ i) {
|
for (let i = 0; i < k; ++i) {
|
||||||
v1[i] = parseInt(v1[i], 10);
|
v1[i] = parseInt(v1[i], 10);
|
||||||
v2[i] = parseInt(v2[i], 10);
|
v2[i] = parseInt(v2[i], 10);
|
||||||
if (v1[i] > v2[i]) return true;
|
if (v1[i] > v2[i]) return true;
|
||||||
if (v1[i] < v2[i]) return false;
|
if (v1[i] < v2[i]) return false;
|
||||||
}
|
}
|
||||||
return v1.length == v2.length ? true: (v1.length < v2.length ? false : true);
|
return v1.length == v2.length ? true : v1.length < v2.length ? false : true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ListOfFiles = {
|
const ListOfFiles = {
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stats
|
* Stats
|
||||||
@ -29,17 +29,15 @@ stats.setStats = function (injection) {
|
|||||||
framework = injection.path;
|
framework = injection.path;
|
||||||
|
|
||||||
if (today in data) {
|
if (today in data) {
|
||||||
if (cdn in data[today]["cdns"]) {
|
if (cdn in data[today]['cdns']) {
|
||||||
data[today]["cdns"][cdn] = ++data[today]["cdns"][cdn];
|
data[today]['cdns'][cdn] = ++data[today]['cdns'][cdn];
|
||||||
} else {
|
} else {
|
||||||
Object.assign(data[today]["cdns"], { [cdn]: 1 });
|
Object.assign(data[today]['cdns'], { [cdn]: 1 });
|
||||||
}
|
}
|
||||||
if (framework in data[today]["frameworks"]) {
|
if (framework in data[today]['frameworks']) {
|
||||||
data[today]["frameworks"][framework] = ++data[today]["frameworks"][
|
data[today]['frameworks'][framework] = ++data[today]['frameworks'][framework];
|
||||||
framework
|
|
||||||
];
|
|
||||||
} else {
|
} else {
|
||||||
Object.assign(data[today]["frameworks"], { [framework]: 1 });
|
Object.assign(data[today]['frameworks'], { [framework]: 1 });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newEntry = { frameworks: { [framework]: 1 }, cdns: { [cdn]: 1 } };
|
newEntry = { frameworks: { [framework]: 1 }, cdns: { [cdn]: 1 } };
|
||||||
|
@ -24,28 +24,24 @@ var wrappers = {};
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
wrappers.setBadgeBackgroundColor = function (details) {
|
wrappers.setBadgeBackgroundColor = function (details) {
|
||||||
|
|
||||||
if (chrome.browserAction.setBadgeBackgroundColor !== undefined) {
|
if (chrome.browserAction.setBadgeBackgroundColor !== undefined) {
|
||||||
chrome.browserAction.setBadgeBackgroundColor(details);
|
chrome.browserAction.setBadgeBackgroundColor(details);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
wrappers.setBadgeText = function (details) {
|
wrappers.setBadgeText = function (details) {
|
||||||
|
|
||||||
if (chrome.browserAction.setBadgeText !== undefined) {
|
if (chrome.browserAction.setBadgeText !== undefined) {
|
||||||
chrome.browserAction.setBadgeText(details);
|
chrome.browserAction.setBadgeText(details);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
wrappers.setBadgeTextColor = function (details) {
|
wrappers.setBadgeTextColor = function (details) {
|
||||||
|
|
||||||
if (chrome.browserAction.setBadgeTextColor !== undefined) {
|
if (chrome.browserAction.setBadgeTextColor !== undefined) {
|
||||||
chrome.browserAction.setBadgeTextColor(details);
|
chrome.browserAction.setBadgeTextColor(details);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
wrappers.setIcon = function (details, type) {
|
wrappers.setIcon = function (details, type) {
|
||||||
|
|
||||||
if (chrome.browserAction.setIcon) {
|
if (chrome.browserAction.setIcon) {
|
||||||
details.path = IconType[details.path][type];
|
details.path = IconType[details.path][type];
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
var help = {};
|
var help = {};
|
||||||
|
|
||||||
help._onDocumentLoaded = function () {
|
help._onDocumentLoaded = function () {
|
||||||
|
|
||||||
let language = navigator.language;
|
let language = navigator.language;
|
||||||
|
|
||||||
help._languageSupported = helpers.languageIsFullySupported(language);
|
help._languageSupported = helpers.languageIsFullySupported(language);
|
||||||
|
@ -218,7 +218,7 @@ statistics._deleteStatistic = function () {
|
|||||||
let text = chrome.i18n.getMessage('dialogConfirmDeleteStatistics');
|
let text = chrome.i18n.getMessage('dialogConfirmDeleteStatistics');
|
||||||
if (confirm(text)) {
|
if (confirm(text)) {
|
||||||
chrome.storage.local.set({
|
chrome.storage.local.set({
|
||||||
[Setting.INTERNAL_STATISTICS_DATA]: {},
|
[Setting.INTERNAL_STATISTICS_DATA]: {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -24,42 +24,42 @@ var updates = {};
|
|||||||
/**
|
/**
|
||||||
* Private Methods
|
* Private Methods
|
||||||
*/
|
*/
|
||||||
updates._openRuleSet = function({target}) {
|
updates._openRuleSet = function ({ target }) {
|
||||||
|
|
||||||
let urls = mappings;
|
let urls = mappings;
|
||||||
let updateKey = target.getAttribute('data-option');
|
let updateKey = target.getAttribute('data-option');
|
||||||
|
|
||||||
let textArea = document.getElementById("generated-rules");
|
let textArea = document.getElementById('generated-rules');
|
||||||
let btnCopy = document.getElementById("button-copy-rule-set");
|
let btnCopy = document.getElementById('button-copy-rule-set');
|
||||||
|
|
||||||
let content = "";
|
let content = '';
|
||||||
|
|
||||||
textArea.style.display = "block";
|
textArea.style.display = 'block';
|
||||||
btnCopy.style.display = "block";
|
btnCopy.style.display = 'block';
|
||||||
|
|
||||||
for (var domain in urls) {
|
for (var domain in urls) {
|
||||||
if (updateKey === "uMatrix") {
|
if (updateKey === 'uMatrix') {
|
||||||
content += "* " + domain + " script allow" + '\n';
|
content += '* ' + domain + ' script allow' + '\n';
|
||||||
content += "* " + domain + " css allow" + '\n';
|
content += '* ' + domain + ' css allow' + '\n';
|
||||||
} else if (updateKey === "uBlock") {
|
} else if (updateKey === 'uBlock') {
|
||||||
content += "* " + domain + " * noop" + '\n';
|
content += '* ' + domain + ' * noop' + '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
textArea.value = content.replace(/\n+$/, "");
|
textArea.value = content.replace(/\n+$/, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
updates._copyRuleSet = function() {
|
updates._copyRuleSet = function () {
|
||||||
|
let textArea = document.getElementById('generated-rules');
|
||||||
let textArea = document.getElementById("generated-rules");
|
navigator.clipboard.writeText(textArea.value).then(
|
||||||
navigator.clipboard.writeText(textArea.value).then(function() {
|
function () {
|
||||||
textArea.select();
|
textArea.select();
|
||||||
}, function() {
|
},
|
||||||
alert("Rule set cannot be copied!");
|
function () {
|
||||||
});
|
alert('Rule set cannot be copied!');
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
updates._openHistoryReleaseNotes = function() {
|
updates._openHistoryReleaseNotes = function () {
|
||||||
|
|
||||||
let container = document.getElementById('history-release-notes');
|
let container = document.getElementById('history-release-notes');
|
||||||
let toggle = document.getElementById('history-indicator');
|
let toggle = document.getElementById('history-indicator');
|
||||||
|
|
||||||
@ -73,16 +73,15 @@ updates._openHistoryReleaseNotes = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
updates._onDocumentLoaded = function () {
|
updates._onDocumentLoaded = function () {
|
||||||
|
|
||||||
document.getElementById('generate-ublock-rules').checked = false;
|
document.getElementById('generate-ublock-rules').checked = false;
|
||||||
document.getElementById('generate-umatrix-rules').checked = false;
|
document.getElementById('generate-umatrix-rules').checked = false;
|
||||||
|
|
||||||
let updateElements = {
|
let updateElements = {
|
||||||
['ruleSets']: document.getElementsByName("rule-sets"),
|
['ruleSets']: document.getElementsByName('rule-sets'),
|
||||||
['copyRuleSet']: document.getElementById("button-copy-rule-set")
|
['copyRuleSet']: document.getElementById('button-copy-rule-set'),
|
||||||
};
|
};
|
||||||
|
|
||||||
for(let i = 0; i < updateElements.ruleSets.length; i++) {
|
for (let i = 0; i < updateElements.ruleSets.length; i++) {
|
||||||
updateElements.ruleSets[i].addEventListener('change', updates._openRuleSet);
|
updateElements.ruleSets[i].addEventListener('change', updates._openRuleSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,5 +96,4 @@ updates._onDocumentLoaded = function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', updates._onDocumentLoaded);
|
document.addEventListener('DOMContentLoaded', updates._onDocumentLoaded);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user