1
0
mirror of https://codeberg.org/nobody/LocalCDN.git synced 2025-02-18 12:50:49 +01:00

Fixed: Blocked Google Fonts in Chromium (#80)

This commit is contained in:
nobody 2020-08-19 09:58:28 +02:00
parent 0b821cff8a
commit f017311fa2
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
3 changed files with 11 additions and 33 deletions

View File

@ -29,28 +29,25 @@ var interceptor = {};
*/ */
interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) { interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
let validCandidate, targetDetails, targetPath; let validCandidate, targetDetails, targetPath;
validCandidate = requestAnalyzer.isValidCandidate(requestDetails, tab); validCandidate = requestAnalyzer.isValidCandidate(requestDetails, tab);
if (!validCandidate) {
return {
cancel: false,
};
}
// Possible URLs of Google Fonts: https://fonts.googleapis.com/css // Possible URLs of Google Fonts: https://fonts.googleapis.com/css
// https://fonts.googleapis.com/css2 // https://fonts.googleapis.com/css2
if (requestDetails.url.startsWith('https://fonts.googleapis.com/css')) { if (requestDetails.url.startsWith('https://fonts.googleapis.com/css')) {
if(interceptor.blockGoogleFonts === true || interceptor.blockMissing === true) { if (interceptor.blockGoogleFonts === true || interceptor.blockMissing === true) {
return { return {
'cancel': true 'cancel': true
}; };
} }
} }
if (!validCandidate) {
return {
'cancel': false
};
}
targetDetails = requestAnalyzer.getLocalTarget(requestDetails); targetDetails = requestAnalyzer.getLocalTarget(requestDetails);
targetPath = targetDetails.path; targetPath = targetDetails.path;
@ -72,18 +69,15 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
*/ */
interceptor._handleMissingCandidate = function (requestUrl, preserveUrl) { interceptor._handleMissingCandidate = function (requestUrl, preserveUrl) {
let requestUrlSegments; let requestUrlSegments;
if (interceptor.blockMissing === true) { if (interceptor.blockMissing === true) {
return { return {
'cancel': true 'cancel': true
}; };
} }
if (preserveUrl === true) { if (preserveUrl === true) {
return { return {
'cancel': false 'cancel': false
}; };
@ -92,16 +86,13 @@ interceptor._handleMissingCandidate = function (requestUrl, preserveUrl) {
requestUrlSegments = new URL(requestUrl); requestUrlSegments = new URL(requestUrl);
if (requestUrlSegments.protocol === Address.HTTP) { if (requestUrlSegments.protocol === Address.HTTP) {
requestUrlSegments.protocol = Address.HTTPS; requestUrlSegments.protocol = Address.HTTPS;
requestUrl = requestUrlSegments.toString(); requestUrl = requestUrlSegments.toString();
return { return {
'redirectUrl': requestUrl 'redirectUrl': requestUrl
}; };
} else { } else {
return { return {
'cancel': false 'cancel': false
}; };
@ -109,7 +100,6 @@ interceptor._handleMissingCandidate = function (requestUrl, preserveUrl) {
}; };
interceptor._handleStorageChanged = function (changes) { interceptor._handleStorageChanged = function (changes) {
if (Setting.XHR_TEST_DOMAIN in changes) { if (Setting.XHR_TEST_DOMAIN in changes) {
interceptor.xhrTestDomain = changes.xhrTestDomain.newValue; interceptor.xhrTestDomain = changes.xhrTestDomain.newValue;
} }
@ -139,7 +129,6 @@ interceptor.relatedSettings.push(Setting.XHR_TEST_DOMAIN);
interceptor.relatedSettings.push(Setting.BLOCK_MISSING); interceptor.relatedSettings.push(Setting.BLOCK_MISSING);
chrome.storage.sync.get(interceptor.relatedSettings, function (items) { chrome.storage.sync.get(interceptor.relatedSettings, function (items) {
interceptor.amountInjected = items.amountInjected || 0; interceptor.amountInjected = items.amountInjected || 0;
interceptor.xhrTestDomain = items.xhrTestDomain || Address.LOCALCDN; interceptor.xhrTestDomain = items.xhrTestDomain || Address.LOCALCDN;
interceptor.blockMissing = items.blockMissing || false; interceptor.blockMissing = items.blockMissing || false;

View File

@ -29,7 +29,6 @@ var requestAnalyzer = {};
*/ */
requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) { requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) {
let initiatorDomain, isWhitelisted; let initiatorDomain, isWhitelisted;
initiatorDomain = helpers.extractDomainFromUrl(tabDetails.url, true); initiatorDomain = helpers.extractDomainFromUrl(tabDetails.url, true);
@ -45,11 +44,11 @@ requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) {
} }
// Font Awesome injections in Chromium deactivated (https://gitlab.com/nobody42/localcdn/-/issues/67) // Font Awesome injections in Chromium deactivated (https://gitlab.com/nobody42/localcdn/-/issues/67)
if (BrowserType.CHROMIUM){ if (BrowserType.CHROMIUM) {
if (/(font-awesome|fontawesome)/.test(requestDetails.url)) { if (/(font-awesome|fontawesome)/.test(requestDetails.url)) {
console.warn('[ LocalCDN ] Font Awesome is not fully supported by your browser.'); console.warn('[ LocalCDN ] Font Awesome is not fully supported by your browser.');
return false; return false;
} else if (requestDetails.url === 'https://fonts.googleapis.com/icon?family=Material+Icons') { } else if (requestDetails.url.startsWith('https://fonts.googleapis.com')) {
// also valid for Google Material icons // also valid for Google Material icons
console.warn('[ LocalCDN ] Google Material Icons are not fully supported by your browser.'); console.warn('[ LocalCDN ] Google Material Icons are not fully supported by your browser.');
return false; return false;
@ -66,7 +65,6 @@ requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) {
}; };
requestAnalyzer.getLocalTarget = function (requestDetails) { requestAnalyzer.getLocalTarget = function (requestDetails) {
let destinationUrl, destinationHost, destinationPath, hostMappings, basePath, resourceMappings; let destinationUrl, destinationHost, destinationPath, hostMappings, basePath, resourceMappings;
let destinationSearchString = ''; let destinationSearchString = '';
@ -102,9 +100,7 @@ requestAnalyzer.getLocalTarget = function (requestDetails) {
*/ */
requestAnalyzer._matchBasePath = function (hostMappings, channelPath) { requestAnalyzer._matchBasePath = function (hostMappings, channelPath) {
for (let basePath of Object.keys(hostMappings)) { for (let basePath of Object.keys(hostMappings)) {
if (channelPath.startsWith(basePath)) { if (channelPath.startsWith(basePath)) {
return basePath; return basePath;
} }
@ -114,7 +110,6 @@ requestAnalyzer._matchBasePath = function (hostMappings, channelPath) {
}; };
requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channelHost, channelPath, destinationSearchString) { requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channelHost, channelPath, destinationSearchString) {
let resourcePath, versionNumber, resourcePattern, filename, shorthandResource; let resourcePath, versionNumber, resourcePattern, filename, shorthandResource;
chrome.storage.sync.get(Setting.LOGGING, function (items) { chrome.storage.sync.get(Setting.LOGGING, function (items) {
@ -134,14 +129,11 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
} }
for (let resourceMold of Object.keys(resourceMappings)) { for (let resourceMold of Object.keys(resourceMappings)) {
if (resourcePattern.startsWith(resourceMold)) { if (resourcePattern.startsWith(resourceMold)) {
let targetPath, hostShorthands, versionDelivered, versionRequested; let targetPath, hostShorthands, versionDelivered, versionRequested;
targetPath = resourceMappings[resourceMold].path; targetPath = resourceMappings[resourceMold].path;
targetPath = targetPath.replace(Resource.VERSION_PLACEHOLDER, versionNumber); targetPath = targetPath.replace(Resource.VERSION_PLACEHOLDER, versionNumber);
// Replace the requested version with the latest depending on major version // Replace the requested version with the latest depending on major version
versionDelivered = helpers.setLastVersion(targetPath, versionNumber).toString(); versionDelivered = helpers.setLastVersion(targetPath, versionNumber).toString();
targetPath = targetPath.replace(versionNumber, versionDelivered); targetPath = targetPath.replace(versionNumber, versionDelivered);
@ -151,19 +143,17 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
hostShorthands = shorthands[channelHost]; hostShorthands = shorthands[channelHost];
if (hostShorthands && hostShorthands[targetPath]) { if (hostShorthands && hostShorthands[targetPath]) {
let shorthand = hostShorthands[targetPath]; let shorthand = hostShorthands[targetPath];
targetPath = shorthand.path; targetPath = shorthand.path;
versionDelivered = shorthand.version; versionDelivered = shorthand.version;
} else if (versionNumber === null) { } else if (versionNumber === null) {
versionDelivered = targetPath.match(Resource.VERSION_EXPRESSION).toString(); versionDelivered = targetPath.match(Resource.VERSION_EXPRESSION).toString();
} }
// Get bundle name // Get bundle name
let bundle = helpers.determineBundle(channelPath); let bundle = helpers.determineBundle(channelPath);
if(bundle !== '') { if (bundle !== '') {
filename = channelPath.split('/').pop(); filename = channelPath.split('/').pop();
targetPath = ( RegExp('.*\.css$').test(filename) ) ? targetPath + filename : targetPath + filename + 'm'; targetPath = ( RegExp('.*\.css$').test(filename) ) ? targetPath + filename : targetPath + filename + 'm';
} }
@ -188,13 +178,11 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
}; };
requestAnalyzer._applyWhitelistedDomains = function () { requestAnalyzer._applyWhitelistedDomains = function () {
chrome.storage.sync.get(Setting.WHITELISTED_DOMAINS, function (items) { chrome.storage.sync.get(Setting.WHITELISTED_DOMAINS, function (items) {
requestAnalyzer.whitelistedDomains = items.whitelistedDomains || {}; requestAnalyzer.whitelistedDomains = items.whitelistedDomains || {};
}); });
}; };
requestAnalyzer._applyManipulateDOMDomains = function () { requestAnalyzer._applyManipulateDOMDomains = function () {
chrome.storage.sync.get(Setting.DOMAINS_MANIPULATE_DOM, function (items) { chrome.storage.sync.get(Setting.DOMAINS_MANIPULATE_DOM, function (items) {
requestAnalyzer.domainsManipulateDOM = items.domainsManipulateDOM || {}; requestAnalyzer.domainsManipulateDOM = items.domainsManipulateDOM || {};
}); });

View File

@ -24,6 +24,7 @@
New in LocalCDN: New in LocalCDN:
</div> </div>
<ul> <ul>
<li>Fixed: Blocked Google Fonts in Chromium (<a href="https://codeberg.org/nobody/LocalCDN/issues/80">#80</a>)</li>
</ul> </ul>
<div id="generator-section"> <div id="generator-section">
<div class="topic-label"> <div class="topic-label">