1
0
mirror of https://codeberg.org/nobody/LocalCDN.git synced 2025-06-05 21:49:31 +02:00

small improvements

This commit is contained in:
nobody
2025-03-28 18:43:18 +01:00
parent 8157dbcd3a
commit ee7258c518
18 changed files with 129 additions and 160 deletions

View File

@@ -21,7 +21,7 @@
* File Guard
*/
let fileGuard = {};
const fileGuard = {};
/**
@@ -30,7 +30,7 @@ let fileGuard = {};
fileGuard._startListening = function () {
let randomHexString = helpers.generateRandomHexString(24);
const randomHexString = helpers.generateRandomHexString(24);
fileGuard.secret = `?_=${randomHexString}`;
chrome.webRequest.onBeforeRequest.addListener(
@@ -42,7 +42,7 @@ fileGuard._startListening = function () {
fileGuard._verifyRequest = function (requestDetails) {
let redirectUrl = chrome.runtime.getURL(Address.ROOT_PATH);
const redirectUrl = chrome.runtime.getURL(Address.ROOT_PATH);
if (!requestDetails.url.endsWith(fileGuard.secret)) {
return {redirectUrl};

View File

@@ -23,7 +23,7 @@
* Interceptor
*/
let interceptor = {};
const interceptor = {};
/**
@@ -31,15 +31,13 @@ let interceptor = {};
*/
interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
let validCandidate, targetDetails, targetDomain, isGoogleFont, isGoogleMaterialIcons, initiatorDomain, isListed,
iframe, isGoogleDomain, isOnAllowlist;
isOnAllowlist = helpers.checkAllowlisted(
const isOnAllowlist = helpers.checkAllowlisted(
helpers.extractDomainFromUrl(tab.url, true),
requestAnalyzer.allowlistedDomains
);
iframe = '';
let iframe = '';
if (tab.url !== requestDetails.originUrl) {
console.log(`${LogString.PREFIX} ${LogString.IFRAME} ${tab.url} -> ${requestDetails.originUrl}`);
iframe = requestDetails.originUrl;
@@ -51,11 +49,10 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
};
}
targetDetails = requestAnalyzer.getLocalTarget(requestDetails, tab.url);
const targetDetails = requestAnalyzer.getLocalTarget(requestDetails, tab.url);
if (targetDetails['result'] === 'blocked') {
let source, resource;
source = helpers.extractDomainFromUrl(tab.url, true);
resource = tab.url;
const source = helpers.extractDomainFromUrl(tab.url, true);
const resource = tab.url;
return {
'redirectUrl': chrome.runtime.getURL(`resources/blocked/index.html?source=${source}&resource=${resource}`)
};
@@ -74,7 +71,7 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
};
}
validCandidate = requestAnalyzer.isValidCandidate(requestDetails, tab);
const validCandidate = requestAnalyzer.isValidCandidate(requestDetails, tab);
if (!validCandidate) {
return {
'cancel': false
@@ -89,14 +86,14 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
};
}
targetDomain = helpers.extractDomainFromUrl(requestDetails.url, true);
isGoogleFont = requestAnalyzer.isGoogleFont(targetDomain);
isGoogleMaterialIcons = requestAnalyzer.isGoogleMaterialIcons(requestDetails.url);
const targetDomain = helpers.extractDomainFromUrl(requestDetails.url, true);
const isGoogleFont = requestAnalyzer.isGoogleFont(targetDomain);
const isGoogleMaterialIcons = requestAnalyzer.isGoogleMaterialIcons(requestDetails.url);
if (BrowserType.FIREFOX && isGoogleFont && !isGoogleMaterialIcons) {
initiatorDomain = helpers.extractDomainFromUrl(tab.url, true);
isListed = helpers.checkAllowlisted(initiatorDomain, interceptor.allowedDomainsGoogleFonts);
isGoogleDomain = helpers.isGoogleDomain(initiatorDomain);
const initiatorDomain = helpers.extractDomainFromUrl(tab.url, true);
const isListed = helpers.checkAllowlisted(initiatorDomain, interceptor.allowedDomainsGoogleFonts);
const isGoogleDomain = helpers.isGoogleDomain(initiatorDomain);
// Check if the website is allowed to load Google Fonts
if (interceptor.blockGoogleFonts === true && isListed === false && isGoogleDomain === false) {
console.log(`${LogString.PREFIX} Google fonts blocked ${requestDetails.url}`);
@@ -139,12 +136,10 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
*/
interceptor._handleMissingCandidate = function (requestUrl, tabIdentifier) {
let requestUrlSegments, injectionCount, missingCount, blockedCount;
if (stateManager.showIconBadge === true) {
injectionCount = Object.keys(stateManager.tabs[tabIdentifier].injections).length || 0;
missingCount = stateManager.tabs[tabIdentifier].missing || 0;
blockedCount = stateManager.tabs[tabIdentifier].blocked || 0;
let injectionCount = Object.keys(stateManager.tabs[tabIdentifier].injections).length || 0;
const missingCount = stateManager.tabs[tabIdentifier].missing || 0;
const blockedCount = stateManager.tabs[tabIdentifier].blocked || 0;
injectionCount = injectionCount + missingCount + blockedCount;
@@ -164,7 +159,7 @@ interceptor._handleMissingCandidate = function (requestUrl, tabIdentifier) {
};
}
requestUrlSegments = new URL(requestUrl);
const requestUrlSegments = new URL(requestUrl);
if (requestUrlSegments.protocol === Address.HTTP) {
requestUrlSegments.protocol = Address.HTTPS;

View File

@@ -23,7 +23,7 @@
* Main
*/
let main = {};
const main = {};
/**

View File

@@ -19,7 +19,7 @@
* Manipulate DOM
*/
let manipulateDOM = {};
const manipulateDOM = {};
/**
@@ -45,16 +45,12 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) {
if (header && manipulateDOM.checkHtmlFilterEnabled(initiatorDomain)) {
let mimeType, isAllowlisted;
mimeType = header.value.replace(/;.*/, '').toLowerCase();
isAllowlisted = stateManager._domainIsListed(initiatorDomain);
const mimeType = header.value.replace(/;.*/, '').toLowerCase();
const isAllowlisted = stateManager._domainIsListed(initiatorDomain);
if (!isAllowlisted && mimeType === 'text/html') {
let initDecoder, decoder, encoder, charset, isFirstData, filter, data;
charset = (/charset\s*=/).test(header.value) && header.value.replace(/^.*?charset\s*=\s*/, '').replace(/["']?/g, '');
const charset = (/charset\s*=/).test(header.value) && header.value.replace(/^.*?charset\s*=\s*/, '').replace(/["']?/g, '');
// Check if charset is supported by TextDecoder()
if ((/charset\s*=/).test(header.value) && !EncodingTypes[charset.toString().toLowerCase()]) {
@@ -64,11 +60,13 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) {
}
// Use charset of the response header in the initial TextDecoder. ASCII only as fallback.
initDecoder = new TextDecoder(charset === false ? 'ASCII' : charset);
encoder = new TextEncoder();
isFirstData = true;
filter = browser.webRequest.filterResponseData(details.requestId);
data = [];
const initDecoder = new TextDecoder(charset === false ? 'ASCII' : charset);
const encoder = new TextEncoder();
const filter = browser.webRequest.filterResponseData(details.requestId);
let isFirstData = true;
let data = [];
let decoder;
header.value = 'text/html; charset=UTF-8';
@@ -171,9 +169,8 @@ manipulateDOM._startWithUtf8Bom = function (str) {
*/
manipulateDOM.checkHtmlFilterEnabled = function (url) {
let listedToManipulateDOM, negateHtmlFilter;
listedToManipulateDOM = stateManager._domainIsListed(url, 'manipulate-dom');
negateHtmlFilter = stateManager.getInvertOption;
const listedToManipulateDOM = stateManager._domainIsListed(url, 'manipulate-dom');
const negateHtmlFilter = stateManager.getInvertOption;
if ((negateHtmlFilter || listedToManipulateDOM) && !(negateHtmlFilter && listedToManipulateDOM)) {
return true;
@@ -186,7 +183,7 @@ manipulateDOM.checkHtmlFilterEnabled = function (url) {
*/
/* eslint-disable one-var */
let cdnDomainsRE = new RegExp(`//(${Object.keys(mappings.cdn).map((m) => m.replace(/\W/g, '\\$&')).join('|')})/`);
const cdnDomainsRE = new RegExp(`//(${Object.keys(mappings.cdn).map((m) => m.replace(/\W/g, '\\$&')).join('|')})/`);
/* eslint-enable one-var */

View File

@@ -23,7 +23,7 @@
* Mappings
*/
let mappings = {};
const mappings = {};
/*
* Date of last update.

View File

@@ -23,7 +23,7 @@
* Messenger
*/
let messenger = {};
const messenger = {};
/**
@@ -32,11 +32,9 @@ let messenger = {};
messenger._handleMessageReceived = function (message, sender, sendResponse) {
let topic, value, popup;
topic = message.topic;
value = message.value;
popup = {};
const topic = message.topic;
const value = message.value;
const popup = {};
switch (topic) {

View File

@@ -23,7 +23,7 @@
* Request Analyzer
*/
let requestAnalyzer = {};
const requestAnalyzer = {};
/**
@@ -31,21 +31,19 @@ let requestAnalyzer = {};
*/
requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) {
let initiatorDomain, requestedDomain, isAllowlisted;
initiatorDomain = helpers.extractDomainFromUrl(tabDetails.url, true);
const initiatorDomain = helpers.extractDomainFromUrl(tabDetails.url, true);
if (initiatorDomain === null) {
initiatorDomain = Address.EXAMPLE;
}
// If requested Domain not in mappings.js it is not relevant
requestedDomain = helpers.extractDomainFromUrl(requestDetails.url, true);
const requestedDomain = helpers.extractDomainFromUrl(requestDetails.url, true);
if (mappings['cdn'][requestedDomain] === undefined) {
return false;
}
isAllowlisted = helpers.checkAllowlisted(initiatorDomain, requestAnalyzer.allowlistedDomains);
const isAllowlisted = helpers.checkAllowlisted(initiatorDomain, requestAnalyzer.allowlistedDomains);
if (isAllowlisted) {
return false;
}
@@ -93,20 +91,19 @@ requestAnalyzer.isGoogleFont = function (domain) {
};
requestAnalyzer.getLocalTarget = function (requestDetails, initiator) {
let destinationUrl, destinationHost, destinationPath, hostMappings, basePath,
resourceMappings, destinationSearchString;
let destinationSearchString;
destinationSearchString = '';
destinationUrl = new URL(requestDetails.url);
const destinationUrl = new URL(requestDetails.url);
destinationHost = destinationUrl.host;
destinationPath = destinationUrl.pathname;
const destinationHost = destinationUrl.host;
const destinationPath = destinationUrl.pathname;
if (destinationUrl.search) {
destinationSearchString = destinationUrl.search;
}
// Use the proper mappings for the targeted host.
hostMappings = mappings.cdn[destinationHost];
const hostMappings = mappings.cdn[destinationHost];
// Resource mapping files are never locally available.
if (Resource.MAPPING_EXPRESSION.test(destinationPath)) {
@@ -115,8 +112,8 @@ requestAnalyzer.getLocalTarget = function (requestDetails, initiator) {
};
}
basePath = requestAnalyzer._matchBasePath(hostMappings, destinationPath)['result'];
resourceMappings = hostMappings[basePath];
const basePath = requestAnalyzer._matchBasePath(hostMappings, destinationPath)['result'];
const resourceMappings = hostMappings[basePath];
if (!resourceMappings) {
return {
@@ -142,7 +139,7 @@ requestAnalyzer.getLocalTarget = function (requestDetails, initiator) {
*/
requestAnalyzer._matchBasePath = function (hostMappings, channelPath) {
for (let basePath of Object.keys(hostMappings)) {
for (const basePath of Object.keys(hostMappings)) {
if (channelPath.startsWith(basePath)) {
return {
'result': basePath,
@@ -309,7 +306,7 @@ requestAnalyzer._handleUncompressedFiles = function (filename) {
};
requestAnalyzer._handleTinyMCE = function (channelPath, channelHost, initiator) {
let filename = channelPath.replace(Resource.TINYMCE, '');
const filename = channelPath.replace(Resource.TINYMCE, '');
if (filename.startsWith('plugins/')) {
console.warn(`${LogString.PREFIX} ${LogString.MISSING_RESOURCE} ${channelHost + channelPath}`);
log.append(initiator, channelHost + channelPath, '-', true);

View File

@@ -18,7 +18,7 @@
* Request Sanitizer
*/
let requestSanitizer = {};
const requestSanitizer = {};
/**
@@ -38,7 +38,7 @@ const ExtraInfoSpec = BrowserType.FIREFOX
*/
requestSanitizer.enable = function () {
let onBeforeSendHeaders = chrome.webRequest.onBeforeSendHeaders;
const onBeforeSendHeaders = chrome.webRequest.onBeforeSendHeaders;
onBeforeSendHeaders.addListener(requestSanitizer._stripMetadata, {
'urls': stateManager.validHosts
@@ -46,7 +46,7 @@ requestSanitizer.enable = function () {
};
requestSanitizer.disable = function () {
let onBeforeSendHeaders = chrome.webRequest.onBeforeSendHeaders;
const onBeforeSendHeaders = chrome.webRequest.onBeforeSendHeaders;
onBeforeSendHeaders.removeListener(requestSanitizer._stripMetadata, {
'urls': stateManager.validHosts
@@ -59,11 +59,9 @@ requestSanitizer.disable = function () {
*/
requestSanitizer._stripMetadata = function (requestDetails) {
let sensitiveHeaders, initiatorDomain, allowlistedDomains;
sensitiveHeaders = [Header.COOKIE, Header.ORIGIN, Header.REFERER];
initiatorDomain = helpers.extractDomainFromUrl(requestDetails.initiator, true);
allowlistedDomains = helpers.checkAllowlisted(initiatorDomain, requestAnalyzer.allowlistedDomains);
const sensitiveHeaders = [Header.COOKIE, Header.ORIGIN, Header.REFERER];
const initiatorDomain = helpers.extractDomainFromUrl(requestDetails.initiator, true);
const allowlistedDomains = helpers.checkAllowlisted(initiatorDomain, requestAnalyzer.allowlistedDomains);
if (allowlistedDomains) {
return {

View File

@@ -23,7 +23,7 @@
* Resources
*/
let resources = {
const resources = {
// Ajax Bootstrap Select
'ajaxBootstrapSelect': {

View File

@@ -23,7 +23,7 @@
* Shorthands
*/
let shorthands = {};
const shorthands = {};
shorthands.specialFiles = function (channelHost, channelPath, searchString) {

View File

@@ -23,7 +23,7 @@
* State Manager
*/
let stateManager = {};
const stateManager = {};
/**
@@ -31,26 +31,24 @@ let stateManager = {};
*/
stateManager.registerInjection = function (tabIdentifier, injection, url) {
let injectionIdentifier, registeredTab, injectionCount, missingCount, blockedCount,
initiatorDomain, htmlFilterIsActive;
let registeredTab;
if (injection['result'] !== false) {
injectionIdentifier = injection.source + injection.path;
const injectionIdentifier = injection.source + injection.path;
registeredTab = stateManager.tabs[tabIdentifier];
registeredTab.injections[injectionIdentifier] = injection;
}
initiatorDomain = helpers.extractDomainFromUrl(url, true) || Address.EXAMPLE;
htmlFilterIsActive = manipulateDOM.checkHtmlFilterEnabled(initiatorDomain);
if (registeredTab !== undefined) {
injectionCount = Object.keys(registeredTab.injections).length || 0;
missingCount = registeredTab.missing || 0;
blockedCount = registeredTab.blocked || 0;
} else {
if (registeredTab === undefined) {
return;
}
const initiatorDomain = helpers.extractDomainFromUrl(url, true) || Address.EXAMPLE;
const htmlFilterIsActive = manipulateDOM.checkHtmlFilterEnabled(initiatorDomain);
const injectionCount = Object.keys(registeredTab.injections).length || 0;
const missingCount = registeredTab.missing || 0;
const blockedCount = registeredTab.blocked || 0;
if (injectionCount > 0) {
chrome.browserAction.setTitle({
'tabId': tabIdentifier,
@@ -96,9 +94,7 @@ stateManager.addDomainToAllowlist = function (domain) {
stateManager.removeDomainFromAllowlist = function (domain) {
return new Promise((resolve) => {
let allowlistedDomains;
allowlistedDomains = requestAnalyzer.allowlistedDomains;
const allowlistedDomains = requestAnalyzer.allowlistedDomains;
if (allowlistedDomains[domain]) {
delete allowlistedDomains[domain];
@@ -117,7 +113,7 @@ stateManager.removeDomainFromAllowlist = function (domain) {
stateManager.addDomainToManipulateDOMlist = function (domain) {
return new Promise((resolve) => {
let domainsManipulateDOM = requestAnalyzer.domainsManipulateDOM;
const domainsManipulateDOM = requestAnalyzer.domainsManipulateDOM;
domainsManipulateDOM[domain] = true;
@@ -127,7 +123,7 @@ stateManager.addDomainToManipulateDOMlist = function (domain) {
stateManager.removeDomainFromManipulateDOMlist = function (domain) {
return new Promise((resolve) => {
let domainsManipulateDOM = requestAnalyzer.domainsManipulateDOM;
const domainsManipulateDOM = requestAnalyzer.domainsManipulateDOM;
delete domainsManipulateDOM[domain];
@@ -137,7 +133,7 @@ stateManager.removeDomainFromManipulateDOMlist = function (domain) {
stateManager.addDomainToGoogleFontsList = function (domain) {
return new Promise((resolve) => {
let allowedDomainsGoogleFonts = interceptor.allowedDomainsGoogleFonts;
const allowedDomainsGoogleFonts = interceptor.allowedDomainsGoogleFonts;
allowedDomainsGoogleFonts[domain] = true;
@@ -147,7 +143,7 @@ stateManager.addDomainToGoogleFontsList = function (domain) {
stateManager.removeDomainFromGoogleFontsList = function (domain) {
return new Promise((resolve) => {
let allowedDomainsGoogleFonts = interceptor.allowedDomainsGoogleFonts;
const allowedDomainsGoogleFonts = interceptor.allowedDomainsGoogleFonts;
delete allowedDomainsGoogleFonts[domain];
@@ -160,9 +156,7 @@ stateManager.removeDomainFromGoogleFontsList = function (domain) {
*/
stateManager._createTab = function (tab) {
let tabIdentifier, requestFilters;
tabIdentifier = tab.id;
const tabIdentifier = tab.id;
stateManager.tabs[tabIdentifier] = {
'injections': {},
@@ -170,7 +164,7 @@ stateManager._createTab = function (tab) {
'blocked': 0
};
requestFilters = {
const requestFilters = {
'tabId': tabIdentifier,
'urls': stateManager.validHosts
};
@@ -186,11 +180,10 @@ stateManager._removeTab = function (tabIdentifier) {
};
stateManager._updateTab = function (details) {
let tabDomain, domainIsAllowlisted, frameIdentifier, tabIdentifier;
tabDomain = helpers.extractDomainFromUrl(details.url, true);
domainIsAllowlisted = stateManager._domainIsListed(tabDomain);
frameIdentifier = details.frameId;
tabIdentifier = details.tabId;
const tabDomain = helpers.extractDomainFromUrl(details.url, true);
const domainIsAllowlisted = stateManager._domainIsListed(tabDomain);
const frameIdentifier = details.frameId;
const tabIdentifier = details.tabId;
if (frameIdentifier !== 0 || tabIdentifier === -1) {
return;
@@ -268,13 +261,13 @@ stateManager._removeIconBadgeFromTab = function (tab) {
stateManager._domainIsListed = function (domain, listname) {
if (domain !== null) {
let allowlistRecord, isAllowlisted;
let isAllowlisted;
if (listname === 'manipulate-dom') {
allowlistRecord = helpers.checkAllowlisted(domain, requestAnalyzer.domainsManipulateDOM);
const allowlistRecord = helpers.checkAllowlisted(domain, requestAnalyzer.domainsManipulateDOM);
isAllowlisted = Boolean(allowlistRecord);
} else {
allowlistRecord = helpers.checkAllowlisted(domain, requestAnalyzer.allowlistedDomains);
const allowlistRecord = helpers.checkAllowlisted(domain, requestAnalyzer.allowlistedDomains);
isAllowlisted = Boolean(allowlistRecord);
}
return isAllowlisted;
@@ -304,7 +297,7 @@ stateManager.hideDonationButton = false;
stateManager.changeBadgeColorMissingResources = false;
stateManager.logging = false;
for (let mapping in mappings.cdn) {
for (const mapping in mappings.cdn) {
let supportedHost = Address.ANY_PROTOCOL + mapping + Address.ANY_PATH;
stateManager.validHosts.push(supportedHost);
}
@@ -374,7 +367,7 @@ chrome.webRequest.onErrorOccurred.addListener(function (requestDetails) {
}, {'urls': [Address.ANY]});
chrome.webRequest.onBeforeRedirect.addListener(function (requestDetails) {
let knownRequest = stateManager.requests[requestDetails.requestId];
const knownRequest = stateManager.requests[requestDetails.requestId];
if (knownRequest) {
stateManager.registerInjection(
knownRequest.tabIdentifier,

View File

@@ -26,7 +26,7 @@ const InvalidFile = 'Invalid file!';
* Storage Manager
*/
let storageManager = {};
const storageManager = {};
/**
@@ -120,10 +120,9 @@ storageManager.startImportFilePicker = function () {
};
storageManager.handleImportFilePicker = function () {
let file, reader;
file = document.getElementById('import-file-picker').files[0];
const file = document.getElementById('import-file-picker').files[0];
const reader = new FileReader();
reader = new FileReader();
reader.readAsText(file, 'UTF-8');
reader.onload = (ev) => {

View File

@@ -23,7 +23,7 @@
* Helpers
*/
let helpers = {};
const helpers = {};
/**
@@ -31,14 +31,12 @@ let helpers = {};
*/
helpers.insertI18nContentIntoDocument = function (document) {
let scriptDirection, i18nElements, translationComplete;
translationComplete = true;
scriptDirection = helpers.determineScriptDirection(navigator.language);
i18nElements = document.querySelectorAll('[data-i18n-content]');
const translationComplete = true;
const scriptDirection = helpers.determineScriptDirection(navigator.language);
const i18nElements = document.querySelectorAll('[data-i18n-content]');
i18nElements.forEach(function (i18nElement) {
let i18nMessageName = i18nElement.getAttribute('data-i18n-content');
const i18nMessageName = i18nElement.getAttribute('data-i18n-content');
if (chrome.i18n.getMessage(i18nMessageName) !== '') {
if (i18nElement.type === 'button') {
@@ -56,10 +54,8 @@ helpers.insertI18nContentIntoDocument = function (document) {
};
helpers.insertI18nTitlesIntoDocument = function (document) {
let scriptDirection, i18nElements;
scriptDirection = helpers.determineScriptDirection(navigator.language);
i18nElements = document.querySelectorAll('[data-i18n-title]');
const scriptDirection = helpers.determineScriptDirection(navigator.language);
const i18nElements = document.querySelectorAll('[data-i18n-title]');
i18nElements.forEach(function (i18nElement) {
let i18nMessageName = i18nElement.getAttribute('data-i18n-title');
@@ -70,11 +66,10 @@ helpers.insertI18nTitlesIntoDocument = function (document) {
};
helpers.languageIsFullySupported = function (language) {
let languageSupported, supportedLanguages;
languageSupported = false;
let languageSupported = false;
supportedLanguages = [
const supportedLanguages = [
'ar',
'bg',
'ca',
@@ -126,7 +121,7 @@ helpers.languageIsFullySupported = function (language) {
'zh_Hant'
];
for (let supportedLanguage of supportedLanguages) {
for (const supportedLanguage of supportedLanguages) {
if (language.search(supportedLanguage) !== -1) {
languageSupported = true;
}
@@ -178,7 +173,7 @@ helpers.getWildcard = function (initiatorDomain) {
};
helpers.getTopLevelDomain = function (initiatorDomain) {
let domain = initiatorDomain.split('.');
const domain = initiatorDomain.split('.');
domain[domain.length - 2] = '*';
return `${domain[domain.length - 2]}.${domain[domain.length - 1]}`;
@@ -211,23 +206,22 @@ helpers.getAllSubdomains = function (domain) {
};
helpers.extractFilenameFromPath = function (path) {
let pathSegments, filename;
pathSegments = path.split('/');
filename = pathSegments[pathSegments.length - 1];
const pathSegments = path.split('/');
const filename = pathSegments[pathSegments.length - 1];
return filename === '' ? pathSegments[1] : filename;
};
helpers.generateRandomHexString = function (length) {
let randomValues, randomHexString;
let randomHexString;
randomValues = crypto.getRandomValues(new Uint8Array(length));
const randomValues = crypto.getRandomValues(new Uint8Array(length));
randomHexString = '';
for (let value of randomValues) {
for (const value of randomValues) {
// eslint-disable-next-line no-bitwise
let hexValue = (0 ^ (value & (15 >> (0 / 4)))).toString(16);
const hexValue = (0 ^ (value & (15 >> (0 / 4)))).toString(16);
randomHexString += hexValue;
}
@@ -239,9 +233,9 @@ helpers.determineCdnName = function (domainName) {
};
helpers.determineScriptDirection = function (language) {
let rightToLeftLanguages, scriptDirection;
let scriptDirection;
rightToLeftLanguages = ['ar', 'he'];
const rightToLeftLanguages = ['ar', 'he'];
if (rightToLeftLanguages.indexOf(language) === -1) {
scriptDirection = 'ltr';
@@ -313,7 +307,7 @@ helpers.compareVersion = function (v1, v2) {
};
helpers.isGoogleDomain = function (initiatorDomain) {
let parts = initiatorDomain.split('.');
const parts = initiatorDomain.split('.');
// remove subdomains if exist
if (parts.length > 2) {

View File

@@ -19,7 +19,7 @@
* Log
*/
let log = {};
const log = {};
log.append = function (initiator, resource, target, highlight, iframe = '') {
storageManager.type.get(Setting.LOGGING, function (items) {

View File

@@ -19,7 +19,7 @@
* Updates
*/
let ruleGenerator = {};
const ruleGenerator = {};
/**
@@ -27,13 +27,12 @@ let ruleGenerator = {};
*/
ruleGenerator.openRuleSet = function ({target}) {
let urls, key, textArea, btnCopy, content;
const urls = mappings.cdn;
const key = target.getAttribute('data-ruleset');
const textArea = document.getElementById('generated-rules');
const btnCopy = document.getElementById('button-copy-rule-set');
urls = mappings.cdn;
key = target.getAttribute('data-ruleset');
textArea = document.getElementById('generated-rules');
btnCopy = document.getElementById('button-copy-rule-set');
content = '';
let content = '';
textArea.style.display = 'block';
btnCopy.style.display = 'block';
@@ -59,7 +58,7 @@ ruleGenerator.openRuleSet = function ({target}) {
};
ruleGenerator.copyRuleSet = function () {
let textArea = document.getElementById('generated-rules');
const textArea = document.getElementById('generated-rules');
navigator.clipboard.writeText(textArea.value).then(
function () {
textArea.select();

View File

@@ -20,7 +20,7 @@
* Stats
*/
let stats = {};
const stats = {};
/**
@@ -28,11 +28,10 @@ let stats = {};
*/
stats.setStats = function (injection) {
let data, today, cdn, framework, newEntry, pathSegments;
data = storageManager.statistics;
today = new Date().toISOString().slice(0, 10);
cdn = injection.source;
const data = storageManager.statistics;
const today = new Date().toISOString().slice(0, 10);
const cdn = injection.source;
let framework, pathSegments, newEntry;
if (injection.bundle !== '') {
pathSegments = injection.path.split('/');

View File

@@ -19,7 +19,7 @@
* Targets
*/
let targets = {};
const targets = {};
/**

View File

@@ -22,7 +22,7 @@
* Wrappers
*/
let wrappers = {};
const wrappers = {};
/**