Fixed: Blocked Google Fonts in Chromium (#80)
This commit is contained in:
parent
0b821cff8a
commit
f017311fa2
|
@ -29,11 +29,16 @@ 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')) {
|
||||
|
@ -43,14 +48,6 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -29,7 +29,6 @@ var requestAnalyzer = {};
|
|||
*/
|
||||
|
||||
requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) {
|
||||
|
||||
let initiatorDomain, isWhitelisted;
|
||||
|
||||
initiatorDomain = helpers.extractDomainFromUrl(tabDetails.url, true);
|
||||
|
@ -49,7 +48,7 @@ requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) {
|
|||
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,12 +143,10 @@ 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();
|
||||
}
|
||||
|
@ -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 || {};
|
||||
});
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Reference in New Issue