From 5ee66f2a99355b731b0d7c28fb8a7c5bdc635706 Mon Sep 17 00:00:00 2001 From: nobody Date: Fri, 13 Oct 2023 08:55:30 +0200 Subject: [PATCH] Allow Google fonts for Google services by default and permanently (#1560) --- .eslintrc | 1 + core/constants.js | 252 ++++++++++++++++++++++++++++++++++++ core/interceptor.js | 10 +- modules/internal/helpers.js | 4 + pages/updates/updates.html | 4 +- 5 files changed, 267 insertions(+), 4 deletions(-) diff --git a/.eslintrc b/.eslintrc index c1fa61c0..065d0b5b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -34,6 +34,7 @@ "BadResources": true, "LogString": true, "BlockedRequestMethods": true, + "GoogleDomains": true, "fileGuard": true, "files": true, diff --git a/core/constants.js b/core/constants.js index 80d91d65..c424af21 100644 --- a/core/constants.js +++ b/core/constants.js @@ -450,6 +450,258 @@ const LogString = { 'IFRAME': 'Possible iframe request:', }; +/** + * https://codeberg.org/nobody/LocalCDN/issues/1560 + */ +const GoogleDomains = { + 'google.com': true, + 'youtube.com': true, + 'ytimg.com': true, + 'withgoogle.com': true, + 'withyoutube.com': true, + 'google.ws': true, + 'google.vu': true, + 'google.vg': true, + 'google.tt': true, + 'google.to': true, + 'google.tn': true, + 'google.tm': true, + 'google.tl': true, + 'google.tk': true, + 'google.tg': true, + 'google.td': true, + 'google.st': true, + 'google.sr': true, + 'google.so': true, + 'google.sn': true, + 'google.sm': true, + 'google.sk': true, + 'google.si': true, + 'google.sh': true, + 'google.se': true, + 'google.sc': true, + 'google.rw': true, + 'google.ru': true, + 'google.rs': true, + 'google.ro': true, + 'google.pt': true, + 'google.ps': true, + 'google.pn': true, + 'google.pl': true, + 'google.nu': true, + 'google.nr': true, + 'google.no': true, + 'google.nl': true, + 'google.ne': true, + 'google.mw': true, + 'google.mv': true, + 'google.mu': true, + 'google.ms': true, + 'google.mn': true, + 'google.ml': true, + 'google.mk': true, + 'google.mg': true, + 'google.me': true, + 'google.md': true, + 'google.lv': true, + 'google.lu': true, + 'google.lt': true, + 'google.lk': true, + 'google.li': true, + 'google.la': true, + 'google.kz': true, + 'google.ki': true, + 'google.kg': true, + 'google.jo': true, + 'google.je': true, + 'google.it': true, + 'google.is': true, + 'google.iq': true, + 'google.io': true, + 'google.im': true, + 'google.ie': true, + 'google.hu': true, + 'google.ht': true, + 'google.hr': true, + 'google.hn': true, + 'google.gy': true, + 'google.gr': true, + 'google.gp': true, + 'google.gm': true, + 'google.gl': true, + 'google.gg': true, + 'google.gf': true, + 'google.ge': true, + 'google.ga': true, + 'google.fr': true, + 'google.fm': true, + 'google.fi': true, + 'google.es': true, + 'google.ee': true, + 'google.dz': true, + 'google.dm': true, + 'google.dk': true, + 'google.dj': true, + 'google.de': true, + 'google.cz': true, + 'google.cv': true, + 'google.com.vn': true, + 'google.com.vc': true, + 'google.com.uy': true, + 'google.com.ua': true, + 'google.com.tw': true, + 'google.com.tr': true, + 'google.com.tj': true, + 'google.com.sv': true, + 'google.com.sl': true, + 'google.com.sg': true, + 'google.com.sb': true, + 'google.com.sa': true, + 'google.com.qa': true, + 'google.com.py': true, + 'google.com.pr': true, + 'google.com.pk': true, + 'google.com.ph': true, + 'google.com.pg': true, + 'google.com.pe': true, + 'google.com.pa': true, + 'google.com.om': true, + 'google.com.np': true, + 'google.com.ni': true, + 'google.com.ng': true, + 'google.com.nf': true, + 'google.com.na': true, + 'google.com.my': true, + 'google.com.mx': true, + 'google.com.mt': true, + 'google.com.mm': true, + 'google.com.ly': true, + 'google.com.lc': true, + 'google.com.lb': true, + 'google.com.kw': true, + 'google.com.kh': true, + 'google.com.jm': true, + 'google.com.hk': true, + 'google.com.gt': true, + 'google.com.gi': true, + 'google.com.gh': true, + 'google.com.fj': true, + 'google.com.et': true, + 'google.com.eg': true, + 'google.com.ec': true, + 'google.com.do': true, + 'google.com.cy': true, + 'google.com.cu': true, + 'google.com.co': true, + 'google.com.bz': true, + 'google.com.br': true, + 'google.com.bo': true, + 'google.com.bn': true, + 'google.com.bh': true, + 'google.com.bd': true, + 'google.com.au': true, + 'google.com.ar': true, + 'google.com.ai': true, + 'google.com.ag': true, + 'google.com.af': true, + 'google.co.zw': true, + 'google.co.zm': true, + 'google.co.za': true, + 'google.co.vi': true, + 'google.co.ve': true, + 'google.co.uz': true, + 'google.co.uk': true, + 'google.co.ug': true, + 'google.co.tz': true, + 'google.co.th': true, + 'google.co.pn': true, + 'google.co.nz': true, + 'google.co.mz': true, + 'google.co.ma': true, + 'google.co.ls': true, + 'google.co.kr': true, + 'google.co.ke': true, + 'google.co.jp': true, + 'google.co.in': true, + 'google.co.il': true, + 'google.co.id': true, + 'google.co.cr': true, + 'google.co.ck': true, + 'google.co.bw': true, + 'google.co.ao': true, + 'google.cn': true, + 'google.cm': true, + 'google.cl': true, + 'google.ci': true, + 'google.ch': true, + 'google.cg': true, + 'google.cf': true, + 'google.cd': true, + 'google.cc': true, + 'google.cat': true, + 'google.ca': true, + 'google.by': true, + 'google.bt': true, + 'google.bs': true, + 'google.bj': true, + 'google.bi': true, + 'google.bg': true, + 'google.bf': true, + 'google.be': true, + 'google.ba': true, + 'google.az': true, + 'google.at': true, + 'google.as': true, + 'google.am': true, + 'google.al': true, + 'google.ae': true, + 'google.ad': true, + 'google.ac': true, + 'g.cn': true, + 'yt.be': true, + 'youtubegaming.com': true, + 'youtubeeducation.com': true, + 'youtube-nocookie.com': true, + 'youtu.be': true, + 'igoogle.com': true, + 'gooogle.com': true, + 'goolge.com': true, + 'googlr.com': true, + 'googlesyndication.com': true, + 'googlesource.com': true, + 'googlescholar.com': true, + 'googlepagecreator.com': true, + 'googlemembers.com': true, + 'googlemember.com': true, + 'googlemaps.com': true, + 'googlemail.com': true, + 'googleearth.com': true, + 'googlee.com': true, + 'googledrive.com': true, + 'googlecommerce.com': true, + 'googlecode.com': true, + 'googlebot.com': true, + 'googlearth.com': true, + 'googleapps.com': true, + 'googleapis.com': true, + 'googleanalytics.com': true, + 'googleadservices.com': true, + 'google.org': true, + 'google.net': true, + 'google-analytics.com': true, + 'googl.com': true, + 'googil.com': true, + 'googel.com': true, + 'goo.gl': true, + 'gogole.com': true, + 'gogle.com': true, + 'gmail.com': true, + 'ggoogle.com': true, + 'g.co': true, + 'android.com': true, + 'developer.android.com': true, +}; + // Supported charsets for TextDecoder() // https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/TextDecoder const EncodingTypes = { diff --git a/core/interceptor.js b/core/interceptor.js index 83fec9f3..feb07d6e 100644 --- a/core/interceptor.js +++ b/core/interceptor.js @@ -32,7 +32,7 @@ var interceptor = {}; interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) { let validCandidate, targetDetails, targetDomain, isGoogleFont, isGoogleMaterialIcons, initiatorDomain, isListed, - iframe; + iframe, isGoogleDomain; iframe = ''; if (tab.url !== requestDetails.originUrl) { @@ -95,8 +95,9 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) { if (BrowserType.FIREFOX && isGoogleFont && !isGoogleMaterialIcons) { initiatorDomain = helpers.extractDomainFromUrl(tab.url, true); isListed = helpers.checkAllowlisted(initiatorDomain, interceptor.allowedDomainsGoogleFonts); + isGoogleDomain = helpers.isGoogleDomain(initiatorDomain); // Check if the website is allowed to load Google Fonts - if (interceptor.blockGoogleFonts === true && isListed === false) { + if (interceptor.blockGoogleFonts === true && isListed === false && isGoogleDomain === false) { console.log(`${LogString.PREFIX} Google fonts blocked ${requestDetails.url}`); log.append(tab.url, requestDetails.url, '-', true, iframe); interceptor._handleMissingCandidate(requestDetails.url, tabIdentifier); @@ -104,6 +105,11 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) { return { 'redirectUrl': chrome.runtime.getURL('resources/google-fonts-placeholder.css') }; + } else if (isGoogleDomain === true) { + console.log(`${LogString.PREFIX} Google fonts allowed, because Google Website ${initiatorDomain}`); + return { + 'cancel': false + }; } else if (interceptor.blockGoogleFonts === false || isListed === true) { return { 'cancel': false diff --git a/modules/internal/helpers.js b/modules/internal/helpers.js index 90eaa62b..5799b0fc 100644 --- a/modules/internal/helpers.js +++ b/modules/internal/helpers.js @@ -294,3 +294,7 @@ helpers.compareVersion = function (v1, v2) { } return v1.length === v2.length ? true : v1.length < v2.length ? false : true; }; + +helpers.isGoogleDomain = function (initiatorDomain) { + return GoogleDomains[initiatorDomain.replace('www.', '')] || false; +}; diff --git a/pages/updates/updates.html b/pages/updates/updates.html index 461e4364..ef7df0e9 100644 --- a/pages/updates/updates.html +++ b/pages/updates/updates.html @@ -25,9 +25,9 @@

New in LocalCDN:

-

+

Improved