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

View File

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

View File

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