From 10c08870575931e46f9a97071c187a897aed08c3 Mon Sep 17 00:00:00 2001 From: nobody Date: Sun, 5 Dec 2021 07:30:31 +0100 Subject: [PATCH] Code style --- core/manipulate-dom.js | 13 +++++++------ core/request-analyzer.js | 22 ++++++++++++++-------- core/shorthands.js | 11 +++++++---- pages/statistics/statistics.js | 14 ++++++++------ 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/core/manipulate-dom.js b/core/manipulate-dom.js index a00bebb1..8b07b373 100644 --- a/core/manipulate-dom.js +++ b/core/manipulate-dom.js @@ -141,13 +141,14 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) { manipulateDOM._searchCharset = function (str, charset) { if (str.indexOf(`charset="${charset}"`) > 0) { return str.replace(`charset="${charset}"`, 'charset="utf8"'); - } else if (str.indexOf(`charset='${charset}'`) > 0) { - return str.replace(`charset='${charset}'`, 'charset=\'utf8\''); - } else if (str.indexOf(`charset=${charset}`) > 0) { - return str.replace(`charset=${charset}`, 'charset=utf8'); - } else { - return str; } + if (str.indexOf(`charset='${charset}'`) > 0) { + return str.replace(`charset='${charset}'`, 'charset=\'utf8\''); + } + if (str.indexOf(`charset=${charset}`) > 0) { + return str.replace(`charset=${charset}`, 'charset=utf8'); + } + return str; }; /** diff --git a/core/request-analyzer.js b/core/request-analyzer.js index 694a6327..13f905e8 100644 --- a/core/request-analyzer.js +++ b/core/request-analyzer.js @@ -106,7 +106,7 @@ requestAnalyzer.getLocalTarget = function (requestDetails, initiator) { }; } - basePath = requestAnalyzer._matchBasePath(hostMappings, destinationPath); + basePath = requestAnalyzer._matchBasePath(hostMappings, destinationPath)['result']; resourceMappings = hostMappings[basePath]; if (!resourceMappings) { @@ -135,11 +135,15 @@ requestAnalyzer.getLocalTarget = function (requestDetails, initiator) { requestAnalyzer._matchBasePath = function (hostMappings, channelPath) { for (let basePath of Object.keys(hostMappings)) { if (channelPath.startsWith(basePath)) { - return basePath; + return { + 'result': basePath, + }; } } - return false; + return { + 'result': false, + }; }; // eslint-disable-next-line max-len @@ -165,7 +169,7 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel } shorthandResource = shorthands.specialFiles(channelHost, channelPath, destinationSearchString); - if (shorthandResource) { + if (shorthandResource['result'] !== false) { if (requestAnalyzer.logging) { console.log(`${LogString.PREFIX} ${LogString.REPLACED_RESOURCE} ${shorthandResource.path}`); log.append(initiator, channelHost + channelPath, shorthandResource.path, false); @@ -186,12 +190,12 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel targetPath = targetPath.replace(Resource.VERSION_PLACEHOLDER, versionNumber); // Replace the requested version with the latest depending on major version versionDelivered = targets.setLastVersion(targetPath, versionNumber); - if (versionDelivered === false) { + if (versionDelivered === '') { return { 'result': false, }; } - versionDelivered = versionDelivered.toString(); + targetPath = targetPath.replace(versionNumber, versionDelivered); if (versionNumber === null) { @@ -206,7 +210,7 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel if (bundle !== '') { targetPath = requestAnalyzer._getPathOfBundle(initiator, channelHost, channelPath, targetPath, bundle); } - if (targetPath === false) { + if (targetPath['result'] === false) { break; } @@ -241,7 +245,9 @@ requestAnalyzer._getPathOfBundle = function (initiator, channelHost, channelPath if (!MathJaxFiles[filename]) { console.warn(`${LogString.PREFIX} ${LogString.MISSING_RESOURCE} ${channelHost + channelPath}`); log.append(initiator, channelHost + channelPath, '-', true); - return false; + return { + 'result': false, + }; } } return helpers.formatFilename(filename.endsWith('.js') diff --git a/core/shorthands.js b/core/shorthands.js index 96676a1b..2b13675b 100644 --- a/core/shorthands.js +++ b/core/shorthands.js @@ -204,8 +204,10 @@ shorthands.specialFiles = function (channelHost, channelPath, searchString) { } else if ((/cdn\.jsdelivr\.net\/npm\/vue@(2|3)/).test(CompleteURL)) { let version = CompleteURL.match(Resource.VERSION_EXPRESSION); lastVersion = targets.setLastVersion(`/vue/${version}.`); - if (lastVersion === false) { - return false; + if (lastVersion === '') { + return { + 'result': false, + }; } return { 'source': channelHost, @@ -232,7 +234,8 @@ shorthands.specialFiles = function (channelHost, channelPath, searchString) { 'path': 'resources/jquery/1.11.2/jquery.min.jsm', 'bundle': '' }; - } else { - return false; } + return { + 'result': false, + }; }; diff --git a/pages/statistics/statistics.js b/pages/statistics/statistics.js index 23a6c087..8d552b0c 100644 --- a/pages/statistics/statistics.js +++ b/pages/statistics/statistics.js @@ -95,16 +95,18 @@ statistics._filterAndSortData = function () { statistics._mergeObjects = function (obj, arr) { for (let [key, value] of Object.entries(obj)) { - let bundle = targets.determineBundle(key); + let domain, bundle; + domain = key; + bundle = targets.determineBundle(domain); if (bundle !== '') { - bundle = key.split('/'); - key = `${bundle[0]}/${bundle[1]}/${bundle[2]}/`; + bundle = domain.split('/'); + domain = `${bundle[0]}/${bundle[1]}/${bundle[2]}/`; } // If CDN/Framework exists, add it, otherwise create new one - if (arr[key]) { - arr[key] += value; + if (arr[domain]) { + arr[domain] += value; } else { - arr[key] = value; + arr[domain] = value; } } };