1
0
mirror of https://codeberg.org/nobody/LocalCDN.git synced 2025-06-05 21:49:31 +02:00

Updated: Handling of Google Fonts (#85)

This commit is contained in:
nobody
2020-08-22 14:58:57 +02:00
parent db083a9f2f
commit 8e244f3a26
8 changed files with 143 additions and 141 deletions

View File

@ -76,7 +76,8 @@ const Setting = {
'BLOCK_GOOGLE_FONTS': 'blockGoogleFonts', 'BLOCK_GOOGLE_FONTS': 'blockGoogleFonts',
'SELECTED_ICON': 'selectedIcon', 'SELECTED_ICON': 'selectedIcon',
'INTERNAL_STATISTICS': 'internalStatistics', 'INTERNAL_STATISTICS': 'internalStatistics',
'INTERNAL_STATISTICS_DATA': 'internalStatisticsData' 'INTERNAL_STATISTICS_DATA': 'internalStatisticsData',
'ALLOWED_DOMAINS_GOOGLE_FONTS': 'allowedDomainsGoogleFonts'
}; };
const WebRequest = { const WebRequest = {

View File

@ -35,22 +35,22 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
if (!validCandidate) { if (!validCandidate) {
return { return {
cancel: false, 'cancel': false
}; };
} }
// Possible URLs of Google Fonts: https://fonts.googleapis.com/css targetDetails = requestAnalyzer.getLocalTarget(requestDetails);
// https://fonts.googleapis.com/css2 targetPath = targetDetails.path;
if (requestDetails.url.startsWith('https://fonts.googleapis.com/css')) {
if (interceptor.blockGoogleFonts === true || interceptor.blockMissing === true) { if (requestDetails.url.includes('fonts.googleapis.com') && !requestDetails.url.includes('Material+Icons')) {
let initiatorDomain = helpers.extractDomainFromUrl(tab.url, true);
// Check if the website is allowed to load Google Fonts
if (interceptor.blockGoogleFonts === true && !requestAnalyzer.domainsGoogleFonts[initiatorDomain]) {
return { return {
'cancel': true 'cancel': true
}; };
} }
} }
targetDetails = requestAnalyzer.getLocalTarget(requestDetails);
targetPath = targetDetails.path;
if (!targetDetails) { if (!targetDetails) {
return interceptor._handleMissingCandidate(requestDetails.url); return interceptor._handleMissingCandidate(requestDetails.url);
} }
@ -111,6 +111,10 @@ interceptor._handleStorageChanged = function (changes) {
if (Setting.BLOCK_GOOGLE_FONTS in changes) { if (Setting.BLOCK_GOOGLE_FONTS in changes) {
interceptor.blockGoogleFonts = changes.blockGoogleFonts.newValue; interceptor.blockGoogleFonts = changes.blockGoogleFonts.newValue;
} }
if (Setting.BLOCK_GOOGLE_FONTS in changes) {
interceptor.blockGoogleFonts = changes.blockGoogleFonts.newValue;
}
}; };
/** /**
@ -121,18 +125,21 @@ interceptor.amountInjected = 0;
interceptor.xhrTestDomain = Address.LOCALCDN; interceptor.xhrTestDomain = Address.LOCALCDN;
interceptor.blockMissing = false; interceptor.blockMissing = false;
interceptor.blockGoogleFonts = true; interceptor.blockGoogleFonts = true;
interceptor.allowedDomainsGoogleFonts = {};
interceptor.relatedSettings = []; interceptor.relatedSettings = [];
interceptor.relatedSettings.push(Setting.AMOUNT_INJECTED); interceptor.relatedSettings.push(Setting.AMOUNT_INJECTED);
interceptor.relatedSettings.push(Setting.XHR_TEST_DOMAIN); interceptor.relatedSettings.push(Setting.XHR_TEST_DOMAIN);
interceptor.relatedSettings.push(Setting.BLOCK_MISSING); interceptor.relatedSettings.push(Setting.BLOCK_MISSING);
interceptor.relatedSettings.push(Setting.ALLOWED_DOMAINS_GOOGLE_FONTS);
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;
interceptor.blockGoogleFonts = items.blockGoogleFonts || true; interceptor.blockGoogleFonts = items.blockGoogleFonts || true;
interceptor.allowedDomainsGoogleFonts = items.allowedDomainsGoogleFonts || {};
}); });
/** /**

View File

@ -43,7 +43,8 @@ main._initializeSettings = function () {
[Setting.DOMAINS_MANIPULATE_DOM]: {}, [Setting.DOMAINS_MANIPULATE_DOM]: {},
[Setting.NEGATE_HTML_FILTER_LIST]: false, [Setting.NEGATE_HTML_FILTER_LIST]: false,
[Setting.BLOCK_GOOGLE_FONTS]: true, [Setting.BLOCK_GOOGLE_FONTS]: true,
[Setting.SELECTED_ICON]: 'Default' [Setting.SELECTED_ICON]: 'Default',
[Setting.ALLOWED_DOMAINS_GOOGLE_FONTS]: {}
}; };
chrome.storage.sync.get(settingDefaults, function (items) { chrome.storage.sync.get(settingDefaults, function (items) {

View File

@ -187,6 +187,11 @@ requestAnalyzer._applyManipulateDOMDomains = function () {
requestAnalyzer.domainsManipulateDOM = items.domainsManipulateDOM || {}; requestAnalyzer.domainsManipulateDOM = items.domainsManipulateDOM || {};
}); });
}; };
requestAnalyzer._applyAllowedDomainsGoogleFonts = function () {
chrome.storage.sync.get(Setting.ALLOWED_DOMAINS_GOOGLE_FONTS, function (items) {
requestAnalyzer.domainsGoogleFonts = items.allowedDomainsGoogleFonts || {};
});
};
/** /**
* Initializations * Initializations
@ -197,9 +202,13 @@ requestAnalyzer._applyWhitelistedDomains();
requestAnalyzer.domainsManipulateDOM = {}; requestAnalyzer.domainsManipulateDOM = {};
requestAnalyzer._applyManipulateDOMDomains(); requestAnalyzer._applyManipulateDOMDomains();
requestAnalyzer.domainsGoogleFonts = {};
requestAnalyzer._applyAllowedDomainsGoogleFonts();
/** /**
* Event Handlers * Event Handlers
*/ */
chrome.storage.onChanged.addListener(requestAnalyzer._applyWhitelistedDomains); chrome.storage.onChanged.addListener(requestAnalyzer._applyWhitelistedDomains);
chrome.storage.onChanged.addListener(requestAnalyzer._applyManipulateDOMDomains); chrome.storage.onChanged.addListener(requestAnalyzer._applyManipulateDOMDomains);
chrome.storage.onChanged.addListener(requestAnalyzer._applyAllowedDomainsGoogleFonts);

View File

@ -250,16 +250,6 @@ body {
font-style: normal; font-style: normal;
} }
#block-google-fonts {
padding-left: 25px;
padding-bottom: 0px;
padding-top: 0.5rem;
}
#block-google-fonts-desc {
padding-left: 0px;
}
.option-disabled > .title-option > .b-contain, .option-disabled > .title-option > .b-contain,
.b-contain input[type="checkbox"]:disabled ~ .b-input { .b-contain input[type="checkbox"]:disabled ~ .b-input {
cursor: default !important; cursor: default !important;
@ -279,6 +269,16 @@ body {
border-color: gray !important; border-color: gray !important;
} }
#div-domains-whitelist-google-fonts {
margin-top: 1em;
}
#tf-domains-whitelist-google-fonts {
margin-top: 0px !important;
width: 100%;
box-sizing: border-box;
}
/** /**
* Right to Left * Right to Left
*/ */

View File

@ -48,15 +48,19 @@
<span class="badge badge-warning" data-i18n-content="advancedLabel"></span> <span class="badge badge-warning" data-i18n-content="advancedLabel"></span>
</div> </div>
<div class="description-option" data-i18n-content="blockMissingDescription"></div> <div class="description-option" data-i18n-content="blockMissingDescription"></div>
<div id="block-google-fonts" class="option option-disabled"> </section>
<section class="option">
<div class="title-option"> <div class="title-option">
<label class="b-contain"> <label class="b-contain">
<input id="block-google-fonts-chk" data-option="blockGoogleFonts" type="checkbox"> <input data-option="blockGoogleFonts" type="checkbox">
<span data-i18n-content="blockGoogleFontsTitle">Block Google Fonts</span> <span data-i18n-content="blockGoogleFontsTitle">Block Google Fonts</span>
<div class="b-input"></div> <div class="b-input"></div>
</label> </label>
</div> </div>
<div id="block-google-fonts-desc" class="description-option" data-i18n-content="blockGoogleFontsDescription">If you use the rules of the rule generator, requests to "fonts.googleapis.com" are allowed to substitute "Google Material Icons" automatically. If you want to block the other requests, enable this option.</div> <div class="description-option" data-i18n-content="blockGoogleFontsDescription">If you use the rules of the rule generator, requests to "fonts.googleapis.com" are allowed to substitute "Google Material Icons" automatically. If you want to block the other requests, enable this option.</div>
<div id="div-domains-whitelist-google-fonts">
<div class="description-option" data-i18n-content="labelDomainsWhitelistGoogleFonts">These domains are allowed to load Google Fonts. Separate multiple entries with semi-colons (;).</div>
<div class="description-option"><input id="tf-domains-whitelist-google-fonts" class="input-text without-checkbox" data-option="allowedDomainsGoogleFonts" type="text"></div>
</div> </div>
</section> </section>
<section class="option"> <section class="option">

View File

@ -29,15 +29,12 @@ var options = {};
*/ */
options._renderContents = function () { options._renderContents = function () {
let translationComplete = true; let translationComplete = true;
document.body.setAttribute('dir', options._scriptDirection); document.body.setAttribute('dir', options._scriptDirection);
translationComplete = helpers.insertI18nContentIntoDocument(document); translationComplete = helpers.insertI18nContentIntoDocument(document);
options._determineOptionValues() options._determineOptionValues().then(options._determineLocalOptionValues).then(options._renderOptionsPanel);
.then(options._determineLocalOptionValues)
.then(options._renderOptionsPanel);
if (!translationComplete) { if (!translationComplete) {
options._renderLocaleNotice(); options._renderLocaleNotice();
@ -54,8 +51,7 @@ options._renderContents = function () {
}; };
options._renderOptionsPanel = function () { options._renderOptionsPanel = function () {
let whitelistedDomains, domainWhitelist, elements, htmlFilterDomains, domainHtmlFilter, googleFontsDomains, domainAllowedGoogleFonts;
let whitelistedDomains, domainWhitelist, elements, htmlFilterDomains, domainHtmlFilter;
Object.assign(options._optionValues, { [Setting.INTERNAL_STATISTICS]: options._internalStatistics }); Object.assign(options._optionValues, { [Setting.INTERNAL_STATISTICS]: options._internalStatistics });
@ -65,6 +61,9 @@ options._renderOptionsPanel = function () {
htmlFilterDomains = options._optionValues.domainsManipulateDOM; htmlFilterDomains = options._optionValues.domainsManipulateDOM;
domainHtmlFilter = options._serializeWhitelistedDomains(htmlFilterDomains); domainHtmlFilter = options._serializeWhitelistedDomains(htmlFilterDomains);
googleFontsDomains = options._optionValues.allowedDomainsGoogleFonts;
domainAllowedGoogleFonts = options._serializeWhitelistedDomains(googleFontsDomains);
elements = options._optionElements; elements = options._optionElements;
Object.assign(elements, { [Setting.INTERNAL_STATISTICS]: document.getElementById('checkbox-internal-statistics') }); Object.assign(elements, { [Setting.INTERNAL_STATISTICS]: document.getElementById('checkbox-internal-statistics') });
@ -80,6 +79,7 @@ options._renderOptionsPanel = function () {
elements.blockGoogleFonts.checked = options._optionValues.blockGoogleFonts; elements.blockGoogleFonts.checked = options._optionValues.blockGoogleFonts;
elements.selectedIcon.value = options._optionValues.selectedIcon; elements.selectedIcon.value = options._optionValues.selectedIcon;
elements.internalStatistics.checked = options._optionValues.internalStatistics; elements.internalStatistics.checked = options._optionValues.internalStatistics;
elements.allowedDomainsGoogleFonts.value = domainAllowedGoogleFonts;
options._registerOptionChangedEventListeners(elements); options._registerOptionChangedEventListeners(elements);
options._registerMiscellaneousEventListeners(); options._registerMiscellaneousEventListeners();
@ -92,14 +92,10 @@ options._renderOptionsPanel = function () {
options._renderLocaleNotice(); options._renderLocaleNotice();
} }
options._displayBlockGoogleFonts(options._optionValues.blockMissing); if (elements.blockGoogleFonts.checked) {
document.getElementById('div-domains-whitelist-google-fonts').style.display = 'block';
if(elements.negateHtmlFilterList.checked === true) {
document.getElementById('html-filter-domains-title-include').style.display = "none";
document.getElementById('html-filter-domains-title-exclude').style.display = "block";
} else { } else {
document.getElementById('html-filter-domains-title-include').style.display = "block"; document.getElementById('div-domains-whitelist-google-fonts').style.display = 'none';
document.getElementById('html-filter-domains-title-exclude').style.display = "none";
} }
document.getElementById('last-mapping-update').textContent += ' ' + lastMappingUpdate; document.getElementById('last-mapping-update').textContent += ' ' + lastMappingUpdate;
@ -113,25 +109,21 @@ options._renderOptionsPanel = function () {
}; };
options._renderBlockMissingNotice = function () { options._renderBlockMissingNotice = function () {
let blockMissingNoticeElement = document.getElementById('notice-block-missing'); let blockMissingNoticeElement = document.getElementById('notice-block-missing');
blockMissingNoticeElement.setAttribute('class', 'notice notice-warning'); blockMissingNoticeElement.setAttribute('class', 'notice notice-warning');
}; };
options._hideBlockMissingNotice = function () { options._hideBlockMissingNotice = function () {
let blockMissingNoticeElement = document.getElementById('notice-block-missing'); let blockMissingNoticeElement = document.getElementById('notice-block-missing');
blockMissingNoticeElement.setAttribute('class', 'notice notice-warning hidden'); blockMissingNoticeElement.setAttribute('class', 'notice notice-warning hidden');
}; };
options._renderLocaleNotice = function () { options._renderLocaleNotice = function () {
let localeNoticeElement = document.getElementById('notice-locale'); let localeNoticeElement = document.getElementById('notice-locale');
localeNoticeElement.setAttribute('class', 'notice notice-default'); localeNoticeElement.setAttribute('class', 'notice notice-default');
}; };
options._registerOptionChangedEventListeners = function (elements) { options._registerOptionChangedEventListeners = function (elements) {
elements.showIconBadge.addEventListener('change', options._onOptionChanged); elements.showIconBadge.addEventListener('change', options._onOptionChanged);
elements.blockMissing.addEventListener('change', options._onOptionChanged); elements.blockMissing.addEventListener('change', options._onOptionChanged);
elements.disablePrefetch.addEventListener('change', options._onOptionChanged); elements.disablePrefetch.addEventListener('change', options._onOptionChanged);
@ -149,14 +141,13 @@ options._registerOptionChangedEventListeners = function (elements) {
} }
elements.copyRuleSet.addEventListener('click', options._copyRuleSet); elements.copyRuleSet.addEventListener('click', options._copyRuleSet);
elements.internalStatistics.addEventListener('change', options._onOptionChanged); elements.internalStatistics.addEventListener('change', options._onOptionChanged);
elements.allowedDomainsGoogleFonts.addEventListener('keyup', options._onOptionChanged);
}; };
options._registerMiscellaneousEventListeners = function () { options._registerMiscellaneousEventListeners = function () {
let blockMissingButtonElement = document.getElementById('button-block-missing'); let blockMissingButtonElement = document.getElementById('button-block-missing');
blockMissingButtonElement.addEventListener('click', function () { blockMissingButtonElement.addEventListener('click', function () {
let changeEvent = new Event('change'); let changeEvent = new Event('change');
options._optionElements.blockMissing.checked = false; options._optionElements.blockMissing.checked = false;
@ -165,9 +156,7 @@ options._registerMiscellaneousEventListeners = function () {
}; };
options._determineOptionValues = function () { options._determineOptionValues = function () {
return new Promise((resolve) => { return new Promise((resolve) => {
let optionKeys = Object.keys(options._optionElements); let optionKeys = Object.keys(options._optionElements);
chrome.storage.sync.get(optionKeys, function (items) { chrome.storage.sync.get(optionKeys, function (items) {
@ -178,7 +167,6 @@ options._determineOptionValues = function () {
}; };
options._determineLocalOptionValues = function () { options._determineLocalOptionValues = function () {
return new Promise((resolve) => { return new Promise((resolve) => {
chrome.storage.local.get([Setting.INTERNAL_STATISTICS], function (items) { chrome.storage.local.get([Setting.INTERNAL_STATISTICS], function (items) {
options._internalStatistics = items.internalStatistics; options._internalStatistics = items.internalStatistics;
@ -192,7 +180,6 @@ options._getOptionElement = function (optionKey) {
}; };
options._getOptionElements = function () { options._getOptionElements = function () {
let optionElements = { let optionElements = {
[Setting.SHOW_ICON_BADGE]: options._getOptionElement(Setting.SHOW_ICON_BADGE), [Setting.SHOW_ICON_BADGE]: options._getOptionElement(Setting.SHOW_ICON_BADGE),
[Setting.BLOCK_MISSING]: options._getOptionElement(Setting.BLOCK_MISSING), [Setting.BLOCK_MISSING]: options._getOptionElement(Setting.BLOCK_MISSING),
@ -201,34 +188,30 @@ options._getOptionElements = function () {
[Setting.WHITELISTED_DOMAINS]: options._getOptionElement(Setting.WHITELISTED_DOMAINS), [Setting.WHITELISTED_DOMAINS]: options._getOptionElement(Setting.WHITELISTED_DOMAINS),
[Setting.HIDE_RELEASE_NOTES]: options._getOptionElement(Setting.HIDE_RELEASE_NOTES), [Setting.HIDE_RELEASE_NOTES]: options._getOptionElement(Setting.HIDE_RELEASE_NOTES),
[Setting.LOGGING]: options._getOptionElement(Setting.LOGGING), [Setting.LOGGING]: options._getOptionElement(Setting.LOGGING),
['ruleSets']: document.getElementsByName("rule-sets"), ['ruleSets']: document.getElementsByName('rule-sets'),
['copyRuleSet']: document.getElementById("button-copy-rule-set"), ['copyRuleSet']: document.getElementById('button-copy-rule-set'),
[Setting.NEGATE_HTML_FILTER_LIST]: options._getOptionElement(Setting.NEGATE_HTML_FILTER_LIST), [Setting.NEGATE_HTML_FILTER_LIST]: options._getOptionElement(Setting.NEGATE_HTML_FILTER_LIST),
[Setting.DOMAINS_MANIPULATE_DOM]: options._getOptionElement(Setting.DOMAINS_MANIPULATE_DOM), [Setting.DOMAINS_MANIPULATE_DOM]: options._getOptionElement(Setting.DOMAINS_MANIPULATE_DOM),
[Setting.BLOCK_GOOGLE_FONTS]: options._getOptionElement(Setting.BLOCK_GOOGLE_FONTS), [Setting.BLOCK_GOOGLE_FONTS]: options._getOptionElement(Setting.BLOCK_GOOGLE_FONTS),
[Setting.SELECTED_ICON]: options._getOptionElement(Setting.SELECTED_ICON) [Setting.SELECTED_ICON]: options._getOptionElement(Setting.SELECTED_ICON),
[Setting.ALLOWED_DOMAINS_GOOGLE_FONTS]: options._getOptionElement(Setting.ALLOWED_DOMAINS_GOOGLE_FONTS),
}; };
return optionElements; return optionElements;
}; };
options._configureLinkPrefetching = function (value) { options._configureLinkPrefetching = function (value) {
if (value === false) { if (value === false) {
// Restore default values of related preference values. // Restore default values of related preference values.
chrome.privacy.network.networkPredictionEnabled.clear({}); chrome.privacy.network.networkPredictionEnabled.clear({});
} else { } else {
chrome.privacy.network.networkPredictionEnabled.set({ chrome.privacy.network.networkPredictionEnabled.set({
'value': false value: false,
}); });
} }
}; };
options._serializeWhitelistedDomains = function (whitelistedDomains) { options._serializeWhitelistedDomains = function (whitelistedDomains) {
if (whitelistedDomains === undefined) return; if (whitelistedDomains === undefined) return;
let domainWhitelist, whitelistedDomainKeys; let domainWhitelist, whitelistedDomainKeys;
@ -247,7 +230,6 @@ options._serializeWhitelistedDomains = function (whitelistedDomains) {
}; };
options._parseDomainWhitelist = function (domainWhitelist) { options._parseDomainWhitelist = function (domainWhitelist) {
let whitelistedDomains = {}; let whitelistedDomains = {};
domainWhitelist.split(Whitelist.VALUE_SEPARATOR).forEach(function (domain) { domainWhitelist.split(Whitelist.VALUE_SEPARATOR).forEach(function (domain) {
@ -262,7 +244,6 @@ options._parseDomainWhitelist = function (domainWhitelist) {
*/ */
options._onDocumentLoaded = function () { options._onDocumentLoaded = function () {
let language = navigator.language; let language = navigator.language;
options._optionElements = options._getOptionElements(); options._optionElements = options._getOptionElements();
@ -273,7 +254,6 @@ options._onDocumentLoaded = function () {
}; };
options._onOptionChanged = function ({ target }) { options._onOptionChanged = function ({ target }) {
let optionKey, optionType, optionValue, storageType; let optionKey, optionType, optionValue, storageType;
optionKey = target.getAttribute('data-option'); optionKey = target.getAttribute('data-option');
@ -286,13 +266,10 @@ options._onOptionChanged = function ({target}) {
} }
if (optionKey === Setting.BLOCK_MISSING) { if (optionKey === Setting.BLOCK_MISSING) {
if (optionValue === true) { if (optionValue === true) {
options._renderBlockMissingNotice(); options._renderBlockMissingNotice();
options._displayBlockGoogleFonts(true);
} else { } else {
options._hideBlockMissingNotice(); options._hideBlockMissingNotice();
options._displayBlockGoogleFonts(false);
} }
} }
@ -300,24 +277,35 @@ options._onOptionChanged = function ({target}) {
options._configureLinkPrefetching(optionValue); options._configureLinkPrefetching(optionValue);
} }
if (optionKey === Setting.WHITELISTED_DOMAINS || optionKey === Setting.DOMAINS_MANIPULATE_DOM) { if (optionKey === Setting.WHITELISTED_DOMAINS || optionKey === Setting.DOMAINS_MANIPULATE_DOM || optionKey === Setting.ALLOWED_DOMAINS_GOOGLE_FONTS) {
optionValue = options._parseDomainWhitelist(optionValue); optionValue = options._parseDomainWhitelist(optionValue);
} }
if (optionKey === Setting.BLOCK_GOOGLE_FONTS) {
if (optionValue === true) {
document.getElementById('div-domains-whitelist-google-fonts').style.display = 'block';
} else {
document.getElementById('div-domains-whitelist-google-fonts').style.display = 'none';
}
}
if (optionKey === Setting.NEGATE_HTML_FILTER_LIST) { if (optionKey === Setting.NEGATE_HTML_FILTER_LIST) {
if (optionValue === true) { if (optionValue === true) {
document.getElementById('html-filter-domains-title-include').style.display = "none"; document.getElementById('html-filter-domains-title-include').style.display = 'none';
document.getElementById('html-filter-domains-title-exclude').style.display = "block"; document.getElementById('html-filter-domains-title-exclude').style.display = 'block';
} else { } else {
document.getElementById('html-filter-domains-title-include').style.display = "block"; document.getElementById('html-filter-domains-title-include').style.display = 'block';
document.getElementById('html-filter-domains-title-exclude').style.display = "none"; document.getElementById('html-filter-domains-title-exclude').style.display = 'none';
} }
} }
if (optionKey === Setting.SELECTED_ICON) { if (optionKey === Setting.SELECTED_ICON) {
wrappers.setIcon({ wrappers.setIcon(
'path': optionValue {
}, 'Enabled'); path: optionValue,
},
'Enabled'
);
} }
if (optionKey === Setting.INTERNAL_STATISTICS) { if (optionKey === Setting.INTERNAL_STATISTICS) {
@ -327,87 +315,89 @@ options._onOptionChanged = function ({target}) {
} }
storageType.set({ storageType.set({
[optionKey]: optionValue [optionKey]: optionValue,
}); });
}; };
options._openRuleSet = function ({ target }) { options._openRuleSet = function ({ target }) {
let urls = mappings; let urls = mappings;
let optionKey = target.getAttribute('data-option'); let optionKey = target.getAttribute('data-option');
let textArea = document.getElementById("generated-rules"); let textArea = document.getElementById('generated-rules');
let btnCopy = document.getElementById("button-copy-rule-set"); let btnCopy = document.getElementById('button-copy-rule-set');
let content = ""; let content = '';
textArea.style.display = "block"; textArea.style.display = 'block';
btnCopy.style.display = "block"; btnCopy.style.display = 'block';
for (var domain in urls) { for (var domain in urls) {
if (optionKey === "uMatrix") { if (optionKey === 'uMatrix') {
content += "* " + domain + " script allow" + '\n'; content += '* ' + domain + ' script allow' + '\n';
content += "* " + domain + " css allow" + '\n'; content += '* ' + domain + ' css allow' + '\n';
} else if (optionKey === "uBlock") { } else if (optionKey === 'uBlock') {
content += "* " + domain + " * noop" + '\n'; content += '* ' + domain + ' * noop' + '\n';
} }
} }
textArea.value = content.replace(/\n+$/, ""); textArea.value = content.replace(/\n+$/, '');
}; };
options._copyRuleSet = function () { options._copyRuleSet = function () {
let textArea = document.getElementById("generated-rules"); let textArea = document.getElementById('generated-rules');
navigator.clipboard.writeText(textArea.value).then(function() { navigator.clipboard.writeText(textArea.value).then(
function () {
textArea.select(); textArea.select();
}, function() { },
alert("Rule set cannot be copied!"); function () {
}); alert('Rule set cannot be copied!');
}
);
}; };
options._onClickHTMLFilterWarning = function () { options._onClickHTMLFilterWarning = function () {
chrome.tabs.create({ chrome.tabs.create({
'url': 'https://codeberg.org/nobody/LocalCDN/wiki/Blank-websites-or-weird-characters', url: 'https://codeberg.org/nobody/LocalCDN/wiki/Blank-websites-or-weird-characters',
'active': true active: true,
}); });
}; };
options._onClickWelcomePage = function () { options._onClickWelcomePage = function () {
chrome.tabs.create({ chrome.tabs.create({
'url': chrome.extension.getURL('pages/welcome/welcome.html'), url: chrome.extension.getURL('pages/welcome/welcome.html'),
'active': true active: true,
}); });
}; };
options._onClickDonate = function () { options._onClickDonate = function () {
chrome.tabs.create({ chrome.tabs.create({
'url': chrome.extension.getURL('pages/donate/donate.html'), url: chrome.extension.getURL('pages/donate/donate.html'),
'active': true active: true,
}); });
}; };
options._onClickChangelog = function () { options._onClickChangelog = function () {
chrome.tabs.create({ chrome.tabs.create({
'url': chrome.extension.getURL('pages/updates/updates.html'), url: chrome.extension.getURL('pages/updates/updates.html'),
'active': true active: true,
}); });
}; };
options._onClickFaq = function () { options._onClickFaq = function () {
chrome.tabs.create({ chrome.tabs.create({
'url': chrome.extension.getURL('pages/help/help.html'), url: chrome.extension.getURL('pages/help/help.html'),
'active': true active: true,
}); });
}; };
options._onClickRulesetHelp = function () { options._onClickRulesetHelp = function () {
chrome.tabs.create({ chrome.tabs.create({
'url': 'https://codeberg.org/nobody/LocalCDN/wiki/Ruleset-generator-for-uBlock-Origin-or-uMatrix', url: 'https://codeberg.org/nobody/LocalCDN/wiki/Ruleset-generator-for-uBlock-Origin-or-uMatrix',
'active': true active: true,
}); });
}; };
options._onClickStatistics = function () { options._onClickStatistics = function () {
chrome.tabs.create({ chrome.tabs.create({
'url': chrome.extension.getURL('pages/statistics/statistics.html'), url: chrome.extension.getURL('pages/statistics/statistics.html'),
'active': true active: true,
}); });
}; };
@ -416,7 +406,6 @@ options._onClickStatistics = function() {
* document.hasFocus() prevents problems with keyboard input. * document.hasFocus() prevents problems with keyboard input.
*/ */
options._updatesDomainLists = function (changes) { options._updatesDomainLists = function (changes) {
let changedItems = Object.keys(changes); let changedItems = Object.keys(changes);
if (!document.hasFocus()) { if (!document.hasFocus()) {
@ -430,16 +419,6 @@ options._updatesDomainLists = function(changes) {
} }
}; };
options._displayBlockGoogleFonts = function(value) {
if (value === true) {
document.getElementById('block-google-fonts').classList.add('option-disabled');
document.getElementById('block-google-fonts-chk').disabled = true;
} else {
document.getElementById('block-google-fonts').classList.remove('option-disabled');
document.getElementById('block-google-fonts-chk').disabled = false;
}
};
/** /**
* Initializations * Initializations
*/ */

View File

@ -30,6 +30,7 @@
<li>Updated: jQuery Fancybox v3.5.7 (<a href="https://codeberg.org/nobody/LocalCDN/issues/86">#86</a>)</li> <li>Updated: jQuery Fancybox v3.5.7 (<a href="https://codeberg.org/nobody/LocalCDN/issues/86">#86</a>)</li>
<li>Added: Fancybox to cdn.jsdelivr.net (<a href="https://codeberg.org/nobody/LocalCDN/issues/86">#86</a>)</li> <li>Added: Fancybox to cdn.jsdelivr.net (<a href="https://codeberg.org/nobody/LocalCDN/issues/86">#86</a>)</li>
<li>Added: Mapping of Google Material Icons (<a href="https://codeberg.org/nobody/LocalCDN/issues/87">#87</a>)</li> <li>Added: Mapping of Google Material Icons (<a href="https://codeberg.org/nobody/LocalCDN/issues/87">#87</a>)</li>
<li>Updated: Handling of Google Fonts (<a href="https://codeberg.org/nobody/LocalCDN/issues/85">#85</a>)</li>
</ul> </ul>
<div id="generator-section"> <div id="generator-section">
<div class="topic-label"> <div class="topic-label">