From 3ae0eccc3d5373d0c9dffb4651f8d790853e7f65 Mon Sep 17 00:00:00 2001 From: nobody Date: Sun, 28 Nov 2021 09:28:49 +0100 Subject: [PATCH] Code style improved --- core/request-analyzer.js | 89 +++++++++++++++++++-------------------- pages/options/options.css | 2 +- 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/core/request-analyzer.js b/core/request-analyzer.js index f96bae0e..a0e8f6a0 100644 --- a/core/request-analyzer.js +++ b/core/request-analyzer.js @@ -104,7 +104,8 @@ requestAnalyzer.getLocalTarget = function (requestDetails, initiator) { destinationHost, destinationPath, destinationSearchString, - initiator); + initiator + ); }; @@ -124,7 +125,7 @@ requestAnalyzer._matchBasePath = function (hostMappings, channelPath) { // eslint-disable-next-line max-len requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channelHost, channelPath, destinationSearchString, initiator) { - let resourcePath, versionNumber, resourcePattern, filename, shorthandResource; + let resourcePath, versionNumber, resourcePattern, shorthandResource; storageManager.type.get(Setting.LOGGING, function (items) { requestAnalyzer.logging = items.enableLogging; @@ -158,48 +159,47 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel } for (let resourceMold of Object.keys(resourceMappings)) { - if (!resourcePattern.startsWith(resourceMold)) { - continue; - } - let targetPath, versionDelivered, versionRequested, bundle; - targetPath = resourceMappings[resourceMold].path; - 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) { - return false; - } - versionDelivered = versionDelivered.toString(); - targetPath = targetPath.replace(versionNumber, versionDelivered); + if (resourcePattern.startsWith(resourceMold)) { + let targetPath, versionDelivered, versionRequested, bundle; + targetPath = resourceMappings[resourceMold].path; + 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) { + return false; + } + versionDelivered = versionDelivered.toString(); + targetPath = targetPath.replace(versionNumber, versionDelivered); - if (versionNumber === null) { - versionDelivered = targetPath.match(Resource.VERSION_EXPRESSION).toString(); - versionRequested = 'latest'; - } else { - versionRequested = versionNumber[0]; - } + if (versionNumber === null) { + versionDelivered = targetPath.match(Resource.VERSION_EXPRESSION).toString(); + versionRequested = 'latest'; + } else { + versionRequested = versionNumber[0]; + } - // Get bundle name - bundle = targets.determineBundle(targetPath); - if (bundle !== '') { - targetPath = requestAnalyzer._getPathOfBundle(initiator, channelPath, targetPath, bundle); - } - if (targetPath === false) { - break; - } + // Get bundle name + bundle = targets.determineBundle(targetPath); + if (bundle !== '') { + targetPath = requestAnalyzer._getPathOfBundle(initiator, channelHost, channelPath, targetPath, bundle); + } + if (targetPath === false) { + break; + } - if (requestAnalyzer.logging) { - console.log(`${LogString.PREFIX} ${LogString.REPLACED_RESOURCE} ${targetPath}`); - log.append(initiator, channelHost + channelPath, targetPath, false); + if (requestAnalyzer.logging) { + console.log(`${LogString.PREFIX} ${LogString.REPLACED_RESOURCE} ${targetPath}`); + log.append(initiator, channelHost + channelPath, targetPath, false); + } + // Prepare and return a local target. + return { + 'source': channelHost, + 'versionRequested': versionRequested, + 'versionDelivered': versionDelivered, + 'path': targetPath, + 'bundle': bundle + }; } - // Prepare and return a local target. - return { - 'source': channelHost, - 'versionRequested': versionRequested, - 'versionDelivered': versionDelivered, - 'path': targetPath, - 'bundle': bundle - }; } if (requestAnalyzer.logging && !IgnoredHost[channelHost]) { @@ -209,7 +209,7 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel return false; }; -requestAnalyzer._getPathOfBundle = function (initiator, channelPath, targetPath, bundle) { +requestAnalyzer._getPathOfBundle = function (initiator, channelHost, channelPath, targetPath, bundle) { let filename = channelPath.split('/').pop(); if (bundle === 'MathJax (Bundle)' && filename !== 'MathJax.js') { filename = channelPath.replace(Resource.MATHJAX, ''); @@ -219,10 +219,9 @@ requestAnalyzer._getPathOfBundle = function (initiator, channelPath, targetPath, return false; } } - return helpers.formatFilename( - filename.endsWith('.js') - ? `${targetPath + filename}m` - : targetPath + filename); + return helpers.formatFilename(filename.endsWith('.js') + ? `${targetPath + filename}m` + : targetPath + filename); }; requestAnalyzer._applyAllowlistedDomains = function () { diff --git a/pages/options/options.css b/pages/options/options.css index bef53e65..1a66798b 100644 --- a/pages/options/options.css +++ b/pages/options/options.css @@ -69,8 +69,8 @@ body { .div-selected-icon { margin-top: 10px; - width: 100%; padding-right: 25px; + width: 100%; } .div-selected-icon > label {