LocalCDN-Firefox-Chrome-Brave/pages/options/options.js

567 lines
24 KiB
JavaScript
Raw Normal View History

2020-02-27 13:45:29 +01:00
/**
* Main Options Page
2020-06-30 18:41:58 +02:00
* Belongs to LocalCDN (since 2020-02-26)
* (Origin: Decentraleyes)
2020-02-27 13:45:29 +01:00
*
* @author Thomas Rientjes
* @since 2016-08-09
2020-06-30 18:41:58 +02:00
*
* @author nobody
* @since 2020-05-04
*
2020-02-27 13:45:29 +01:00
* @license MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
/**
* Options
*/
var options = {};
/**
* Private Methods
*/
options._renderContents = function () {
2020-04-07 12:19:32 +02:00
let translationComplete = true;
2020-02-27 13:45:29 +01:00
document.body.setAttribute('dir', options._scriptDirection);
2020-04-07 12:19:32 +02:00
translationComplete = helpers.insertI18nContentIntoDocument(document);
2020-02-27 13:45:29 +01:00
options._determineOptionValues().then(options._determineLocalOptionValues).then(options._renderOptionsPanel);
2020-05-29 08:20:53 +02:00
2020-04-07 12:19:32 +02:00
if (!translationComplete) {
options._renderLocaleNotice();
}
if (BrowserType.CHROMIUM) {
document.getElementById('html-filter-div').style.display = 'none';
document.getElementById('block-google-fonts').style.display = 'none';
document.getElementById('div-badged-text-color').style.display = 'none';
}
if (!chrome.browserAction.setIcon) {
2020-08-30 19:07:14 +02:00
document.getElementById('icon-style-div').style.display = 'none';
options._platformSupportIcons = false;
}
options._renderInfoPanel();
2020-08-30 19:07:14 +02:00
document.getElementById('label-version').textContent = helpers.formatVersion(chrome.runtime.getManifest().version);
2020-02-27 13:45:29 +01:00
};
options._renderOptionsPanel = function () {
2020-10-17 07:09:30 +02:00
let allowlistedDomains, domainAllowlist, elements, htmlFilterDomains, domainHtmlFilter, googleFontsDomains, domainAllowedGoogleFonts, url, bgColor, txtColor;
2020-02-27 13:45:29 +01:00
Object.assign(options._optionValues, { [Setting.INTERNAL_STATISTICS]: options._internalStatistics });
2020-08-08 07:28:41 +02:00
2020-10-17 07:09:30 +02:00
allowlistedDomains = options._optionValues.allowlistedDomains;
domainAllowlist = options._serializeAllowlistedDomains(allowlistedDomains);
2020-02-27 13:45:29 +01:00
htmlFilterDomains = options._optionValues.domainsManipulateDOM;
2020-10-17 07:09:30 +02:00
domainHtmlFilter = options._serializeAllowlistedDomains(htmlFilterDomains);
googleFontsDomains = options._optionValues.allowedDomainsGoogleFonts;
2020-10-17 07:09:30 +02:00
domainAllowedGoogleFonts = options._serializeAllowlistedDomains(googleFontsDomains);
2020-02-27 13:45:29 +01:00
elements = options._optionElements;
Object.assign(elements, { [Setting.INTERNAL_STATISTICS]: document.getElementById('checkbox-internal-statistics') });
2020-02-27 13:45:29 +01:00
Object.assign(elements, { [Setting.SELECTED_ICON]: document.getElementsByName('selected-icon') });
2020-02-27 13:45:29 +01:00
elements.showIconBadge.checked = options._optionValues.showIconBadge;
elements.blockMissing.checked = options._optionValues.blockMissing;
elements.disablePrefetch.checked = options._optionValues.disablePrefetch;
elements.stripMetadata.checked = options._optionValues.stripMetadata;
elements.hideReleaseNotes.checked = options._optionValues.hideReleaseNotes;
2020-03-29 10:23:16 +02:00
elements.enableLogging.checked = options._optionValues.enableLogging;
2020-10-17 07:09:30 +02:00
elements.allowlistedDomains.value = domainAllowlist;
elements.domainsManipulateDOM.value = domainHtmlFilter;
elements.negateHtmlFilterList.checked = options._optionValues.negateHtmlFilterList;
elements.blockGoogleFonts.checked = options._optionValues.blockGoogleFonts;
2020-08-08 07:28:41 +02:00
elements.internalStatistics.checked = options._optionValues.internalStatistics;
elements.allowedDomainsGoogleFonts.value = domainAllowedGoogleFonts;
2020-08-30 18:56:36 +02:00
elements.storageType = options._optionValues.storageType;
2020-02-27 13:45:29 +01:00
options._registerOptionChangedEventListeners(elements);
options._registerMiscellaneousEventListeners();
if (options._optionValues.blockMissing === true) {
options._renderBlockMissingNotice();
}
if (options._languageSupported === false) {
options._renderLocaleNotice();
}
if (elements.blockGoogleFonts.checked) {
2020-10-17 07:09:30 +02:00
document.getElementById('div-domains-allowlist-google-fonts').style.display = 'block';
} else {
2020-10-17 07:09:30 +02:00
document.getElementById('div-domains-allowlist-google-fonts').style.display = 'none';
}
2020-08-30 19:07:14 +02:00
if (elements.storageType === 'local') {
document.getElementById('storage-type-local').checked = true;
} else {
document.getElementById('storage-type-sync').checked = true;
}
if (options._platformSupportIcons) {
if (options._optionValues.selectedIcon === 'Default') {
document.getElementById('icon-default').checked = true;
} else if (options._optionValues.selectedIcon === 'Grey') {
document.getElementById('icon-grey').checked = true;
} else if (options._optionValues.selectedIcon === 'Light') {
document.getElementById('icon-light').checked = true;
}
url = chrome.runtime.getURL('icons/action/' + options._optionValues.selectedIcon.toLowerCase() + '/icon38-default.png');
document.getElementById('icon-badge-preview').src = url;
bgColor = options._optionValues.badgeColor || '#4A826C';
txtColor = options._optionValues.badgeTextColor || '#FFFFFF';
2020-09-25 16:37:02 +02:00
document.getElementById('counter-preview-badge').style.backgroundColor = bgColor;
document.getElementById('pre-badged-background-color').style.backgroundColor = bgColor;
document.getElementById('badged-background-color').value = bgColor;
2020-09-25 16:37:02 +02:00
document.getElementById('counter-preview-badge').style.color = txtColor;
document.getElementById('pre-badged-text-color').style.backgroundColor = txtColor;
document.getElementById('badged-text-color').value = txtColor;
}
2020-09-25 16:37:02 +02:00
document.getElementById('last-mapping-update').textContent += ' ' + mappings.lastMappingUpdate;
2020-08-30 19:07:14 +02:00
document.getElementById('negate-html-filter-list-warning').addEventListener('click', function () { options._onLinkClick(Links.CODEBERG_HTML_FILTER); });
document.getElementById('link-welcome-page').addEventListener('click', function () { options._onLinkClick(Links.WELCOME); });
document.getElementById('link-changelog').addEventListener('click', function () { options._onLinkClick(Links.CHANGELOG); });
document.getElementById('link-donate').addEventListener('click', function () { options._onLinkClick(Links.DONATE); });
document.getElementById('link-faq').addEventListener('click', function () { options._onLinkClick(Links.FAQ);});
document.getElementById('ruleset-help').addEventListener('click', function () { options._onLinkClick(Links.CODEBERG_RULESET); });
document.getElementById('sync-help').addEventListener('click', function () { options._onLinkClick(Links.FAQ + '#sync'); });
document.getElementById('link-statistic').addEventListener('click', function () { options._onLinkClick(Links.STATISTICS); });
document.getElementById('btn-general-tab').addEventListener('click', options._changeTab);
document.getElementById('btn-advanced-tab').addEventListener('click', options._changeTab);
document.getElementById('btn-export-import-tab').addEventListener('click', options._changeTab);
document.getElementById('btn-info-tab').addEventListener('click', options._changeTab);
2020-08-30 18:56:36 +02:00
document.getElementById('storage-type-local').addEventListener('change', options._onStorageOptionChanged);
document.getElementById('storage-type-sync').addEventListener('change', options._onStorageOptionChanged);
2020-08-30 19:07:14 +02:00
document.getElementById('export-data').addEventListener('click', storageManager.export);
document.getElementById('import-data').addEventListener('click', storageManager.startImportFilePicker);
document.getElementById('import-file-picker').addEventListener('change', storageManager.handleImportFilePicker);
2020-09-25 16:37:02 +02:00
if (options._platformSupportIcons) {
document.getElementById('badged-background-color').addEventListener('keyup', options._onChangedHexColor);
document.getElementById('badged-text-color').addEventListener('keyup', options._onChangedHexColor);
}
2020-09-25 16:37:02 +02:00
document.getElementById('restore-background-color').addEventListener('click', options._setDefaultColor);
document.getElementById('restore-text-color').addEventListener('click', options._setDefaultColor);
2020-02-27 13:45:29 +01:00
};
options._renderBlockMissingNotice = function () {
let blockMissingNoticeElement = document.getElementById('notice-block-missing');
blockMissingNoticeElement.setAttribute('class', 'notice notice-warning');
};
options._hideBlockMissingNotice = function () {
let blockMissingNoticeElement = document.getElementById('notice-block-missing');
blockMissingNoticeElement.setAttribute('class', 'notice notice-warning hidden');
};
options._renderLocaleNotice = function () {
let localeNoticeElement = document.getElementById('notice-locale');
localeNoticeElement.setAttribute('class', 'notice notice-default');
};
options._registerOptionChangedEventListeners = function (elements) {
elements.showIconBadge.addEventListener('change', options._onOptionChanged);
elements.blockMissing.addEventListener('change', options._onOptionChanged);
elements.disablePrefetch.addEventListener('change', options._onOptionChanged);
elements.stripMetadata.addEventListener('change', options._onOptionChanged);
2020-03-29 10:23:16 +02:00
elements.enableLogging.addEventListener('change', options._onOptionChanged);
elements.hideReleaseNotes.addEventListener('change', options._onOptionChanged);
2020-10-17 07:09:30 +02:00
elements.allowlistedDomains.addEventListener('keyup', options._onOptionChanged);
elements.domainsManipulateDOM.addEventListener('keyup', options._onOptionChanged);
elements.negateHtmlFilterList.addEventListener('change', options._onOptionChanged);
elements.blockGoogleFonts.addEventListener('change', options._onOptionChanged);
elements.selectedIcon[0].addEventListener('change', options._onOptionChanged);
elements.selectedIcon[1].addEventListener('change', options._onOptionChanged);
elements.selectedIcon[2].addEventListener('change', options._onOptionChanged);
2020-08-29 09:56:11 +02:00
elements.ruleSets[0].addEventListener('change', ruleGenerator.openRuleSet);
elements.ruleSets[1].addEventListener('change', ruleGenerator.openRuleSet);
2020-09-13 07:42:28 +02:00
elements.ruleSets[2].addEventListener('change', ruleGenerator.openRuleSet);
2020-08-29 09:56:11 +02:00
elements.copyRuleSet.addEventListener('click', ruleGenerator.copyRuleSet);
2020-08-08 07:28:41 +02:00
elements.internalStatistics.addEventListener('change', options._onOptionChanged);
elements.allowedDomainsGoogleFonts.addEventListener('keyup', options._onOptionChanged);
2020-02-27 13:45:29 +01:00
};
options._registerMiscellaneousEventListeners = function () {
let blockMissingButtonElement = document.getElementById('button-block-missing');
blockMissingButtonElement.addEventListener('click', function () {
let changeEvent = new Event('change');
options._optionElements.blockMissing.checked = false;
options._optionElements.blockMissing.dispatchEvent(changeEvent);
});
};
options._determineOptionValues = function () {
return new Promise((resolve) => {
let optionKeys = Object.keys(options._optionElements);
2020-08-30 18:56:36 +02:00
storageManager.type.get(optionKeys, function (items) {
2020-02-27 13:45:29 +01:00
options._optionValues = items;
resolve();
});
});
};
2020-08-08 07:28:41 +02:00
options._determineLocalOptionValues = function () {
return new Promise((resolve) => {
2020-08-30 18:56:36 +02:00
chrome.storage.local.get([Setting.INTERNAL_STATISTICS, Setting.STORAGE_TYPE], function (items) {
2020-08-08 07:28:41 +02:00
options._internalStatistics = items.internalStatistics;
2020-08-30 18:56:36 +02:00
options._storageType = items.storageType;
2020-08-08 07:28:41 +02:00
resolve();
});
});
};
2020-02-27 13:45:29 +01:00
options._getOptionElement = function (optionKey) {
return document.querySelector(`[data-option=${optionKey}]`);
};
options._getOptionElements = function () {
let optionElements = {
[Setting.SHOW_ICON_BADGE]: options._getOptionElement(Setting.SHOW_ICON_BADGE),
[Setting.BLOCK_MISSING]: options._getOptionElement(Setting.BLOCK_MISSING),
[Setting.DISABLE_PREFETCH]: options._getOptionElement(Setting.DISABLE_PREFETCH),
[Setting.STRIP_METADATA]: options._getOptionElement(Setting.STRIP_METADATA),
2020-10-17 07:09:30 +02:00
[Setting.ALLOWLISTED_DOMAINS]: options._getOptionElement(Setting.ALLOWLISTED_DOMAINS),
[Setting.HIDE_RELEASE_NOTES]: options._getOptionElement(Setting.HIDE_RELEASE_NOTES),
2020-03-29 10:23:16 +02:00
[Setting.LOGGING]: options._getOptionElement(Setting.LOGGING),
['ruleSets']: document.getElementsByName('rule-sets'),
['copyRuleSet']: document.getElementById('button-copy-rule-set'),
[Setting.NEGATE_HTML_FILTER_LIST]: options._getOptionElement(Setting.NEGATE_HTML_FILTER_LIST),
[Setting.DOMAINS_MANIPULATE_DOM]: options._getOptionElement(Setting.DOMAINS_MANIPULATE_DOM),
[Setting.BLOCK_GOOGLE_FONTS]: options._getOptionElement(Setting.BLOCK_GOOGLE_FONTS),
[Setting.SELECTED_ICON]: options._getOptionElement(Setting.SELECTED_ICON),
[Setting.ALLOWED_DOMAINS_GOOGLE_FONTS]: options._getOptionElement(Setting.ALLOWED_DOMAINS_GOOGLE_FONTS),
2020-09-25 16:37:02 +02:00
[Setting.STORAGE_TYPE]: options._getOptionElement(Setting.STORAGE_TYPE),
[Setting.BADGE_COLOR]: options._getOptionElement(Setting.BADGE_COLOR),
[Setting.BADGE_TEXT_COLOR]: options._getOptionElement(Setting.BADGE_TEXT_COLOR)
2020-02-27 13:45:29 +01:00
};
return optionElements;
};
options._configureLinkPrefetching = function (value) {
if (value === false) {
// Restore default values of related preference values.
chrome.privacy.network.networkPredictionEnabled.clear({});
} else {
chrome.privacy.network.networkPredictionEnabled.set({
value: false,
2020-02-27 13:45:29 +01:00
});
}
};
2020-10-17 07:09:30 +02:00
options._serializeAllowlistedDomains = function (allowlistedDomains) {
if (allowlistedDomains === undefined) return '';
2020-10-17 07:09:30 +02:00
let domainAllowlist, allowlistedDomainKeys;
2020-02-27 13:45:29 +01:00
2020-10-17 07:09:30 +02:00
allowlistedDomainKeys = Object.keys(allowlistedDomains);
domainAllowlist = '';
2020-02-27 13:45:29 +01:00
2020-10-17 07:09:30 +02:00
allowlistedDomainKeys.forEach(function (domain) {
domainAllowlist = `${domainAllowlist}${domain};`;
2020-02-27 13:45:29 +01:00
});
2020-10-17 07:09:30 +02:00
domainAllowlist = domainAllowlist.slice(0, -1);
domainAllowlist = domainAllowlist.replace(Allowlist.TRIM_EXPRESSION, '');
2020-02-27 13:45:29 +01:00
2020-10-17 07:09:30 +02:00
return domainAllowlist;
2020-02-27 13:45:29 +01:00
};
2020-10-17 07:09:30 +02:00
options._parseDomainAllowlist = function (domainAllowlist) {
let allowlistedDomains = {};
2020-02-27 13:45:29 +01:00
2020-10-17 07:09:30 +02:00
domainAllowlist.split(Allowlist.VALUE_SEPARATOR).forEach(function (domain) {
allowlistedDomains[helpers.normalizeDomain(domain)] = true;
2020-02-27 13:45:29 +01:00
});
2020-10-17 07:09:30 +02:00
return allowlistedDomains;
2020-02-27 13:45:29 +01:00
};
options._renderInfoPanel = function () {
let unsupportedFrameworks, btnCDNs, btnFrameworks;
unsupportedFrameworks = 0;
options._listOfFrameworks = {};
btnCDNs = document.getElementById('cdn');
btnCDNs.value = 'CDNs: ';
btnFrameworks = document.getElementById('framework');
btnFrameworks.value = 'Frameworks: ';
Object.values(Object.values(resources)).forEach((element) => {
let path = Object.values(element)[0];
path = path.split('/');
options._listOfFrameworks[path[1]] = true;
});
if (BrowserType.CHROMIUM) {
// Chromium based browser does not support Google Material Icons and Font Awesome
document.getElementById('unsupported-frameworks').style.display = 'block';
unsupportedFrameworks = 2;
}
options._createList('cdn');
document.getElementById('cdn').classList.add('btns-active');
btnFrameworks.addEventListener('click', options._btnCreateList);
btnCDNs.addEventListener('click', options._btnCreateList);
// Reduce CDNs by 3, because loli.net includes = cdn.css.net, cdnjs.loli.net, ajax.loli.net, fonts.loli.net
btnCDNs.value += Object.keys(mappings.cdn).length - 3;
btnFrameworks.value += Object.keys(options._listOfFrameworks).length - unsupportedFrameworks;
};
options._btnCreateList = function ({ target }) {
if (target.id === 'cdn') {
document.getElementById('cdn').classList.add('btns-active');
document.getElementById('framework').classList.remove('btns-active');
} else {
document.getElementById('cdn').classList.remove('btns-active');
document.getElementById('framework').classList.add('btns-active');
}
options._createList(target.id);
};
options._createList = function (type) {
let textArea, list;
textArea = document.getElementById('generated-list');
textArea.value = '';
if (type === 'cdn') {
list = Object.keys(mappings.cdn);
} else if (type === 'framework') {
list = Object.keys(options._listOfFrameworks);
} else {
return;
}
list.forEach((elem) => {
if (!(BrowserType.CHROMIUM && (elem === 'fontawesome' || elem === 'google-material-design-icons'))) {
textArea.value += elem + '\n';
}
});
};
options._colorPicker = function () {
2020-09-25 16:37:02 +02:00
const badgeBackgroundColor = new CP(document.getElementById('badged-background-color'));
badgeBackgroundColor.on('change', function(r, g, b) {
this.source.value = this.color(r, g, b);
});
badgeBackgroundColor.on('drag', function(r, g, b) {
options._backgroundColor = this.color(r, g, b);
this.source.value = options._backgroundColor
wrappers.setBadgeBackgroundColor({color: options._backgroundColor});
2020-09-25 07:54:01 +02:00
document.getElementById('counter-preview-badge').style.backgroundColor = options._backgroundColor;
document.getElementById('pre-badged-background-color').style.backgroundColor = options._backgroundColor;
2020-09-25 16:37:02 +02:00
});
2020-09-25 16:37:02 +02:00
const badgeTextColor = new CP(document.getElementById('badged-text-color'));
badgeTextColor.on('change', function(r, g, b) {
this.source.value = this.color(r, g, b);
});
badgeTextColor.on('drag', function(r, g, b) {
options._textColor = this.color(r, g, b);
this.source.value = options._textColor
wrappers.setBadgeTextColor({color: options._textColor});
document.getElementById('counter-preview-badge').style.color = options._textColor;
document.getElementById('pre-badged-text-color').style.backgroundColor = options._textColor;
});
};
options._setDefaultColor = function ({ target }) {
if (target.id === 'restore-text-color') {
options._textColor = '#FFFFFF';
wrappers.setBadgeTextColor({color: options._textColor});
document.getElementById('counter-preview-badge').style.color = options._textColor;
document.getElementById('pre-badged-text-color').style.backgroundColor = options._textColor;
document.getElementById('badged-text-color').value = options._textColor;
} else if (target.id === 'restore-background-color') {
options._backgroundColor = '#4A826C';
wrappers.setBadgeBackgroundColor({color: options._backgroundColor});
document.getElementById('counter-preview-badge').style.backgroundColor = options._backgroundColor;
document.getElementById('pre-badged-background-color').style.backgroundColor = options._backgroundColor;
document.getElementById('badged-background-color').value = options._backgroundColor;
}
};
2020-02-27 13:45:29 +01:00
/**
* Event Handlers
*/
options._onDocumentLoaded = function () {
let language = navigator.language;
options._optionElements = options._getOptionElements();
options._languageSupported = helpers.languageIsFullySupported(language);
options._scriptDirection = helpers.determineScriptDirection(language);
2020-09-26 06:38:04 +02:00
options._colorPicker();
2020-02-27 13:45:29 +01:00
options._renderContents();
};
options._onOptionChanged = function ({ target }) {
2020-08-30 18:56:36 +02:00
let optionKey, optionType, optionValue;
2020-02-27 13:45:29 +01:00
optionKey = target.getAttribute('data-option');
optionType = target.getAttribute('type');
2020-06-21 08:18:18 +02:00
if (optionType === 'checkbox') {
2020-02-27 13:45:29 +01:00
optionValue = target.checked;
2020-06-21 08:18:18 +02:00
} else {
2020-02-27 13:45:29 +01:00
optionValue = target.value;
}
if (optionKey === Setting.BLOCK_MISSING) {
if (optionValue === true) {
options._renderBlockMissingNotice();
} else {
options._hideBlockMissingNotice();
}
}
if (optionKey === Setting.DISABLE_PREFETCH) {
options._configureLinkPrefetching(optionValue);
}
2020-10-17 07:09:30 +02:00
if (optionKey === Setting.ALLOWLISTED_DOMAINS || optionKey === Setting.DOMAINS_MANIPULATE_DOM || optionKey === Setting.ALLOWED_DOMAINS_GOOGLE_FONTS) {
optionValue = options._parseDomainAllowlist(optionValue);
2020-02-27 13:45:29 +01:00
}
if (optionKey === Setting.BLOCK_GOOGLE_FONTS) {
if (optionValue === true) {
2020-10-17 07:09:30 +02:00
document.getElementById('div-domains-allowlist-google-fonts').style.display = 'block';
} else {
2020-10-17 07:09:30 +02:00
document.getElementById('div-domains-allowlist-google-fonts').style.display = 'none';
}
}
if (optionKey === Setting.NEGATE_HTML_FILTER_LIST) {
if (optionValue === true) {
document.getElementById('html-filter-domains-title-include').style.display = 'none';
document.getElementById('html-filter-domains-title-exclude').style.display = 'block';
} else {
document.getElementById('html-filter-domains-title-include').style.display = 'block';
document.getElementById('html-filter-domains-title-exclude').style.display = 'none';
}
}
if (optionKey === Setting.SELECTED_ICON) {
2020-08-29 09:56:11 +02:00
wrappers.setIcon({ path: optionValue }, 'Enabled');
let url = chrome.runtime.getURL('icons/action/' + optionValue.toLowerCase() + '/icon38-default.png');
document.getElementById('icon-badge-preview').src = url;
}
2020-08-30 18:56:36 +02:00
storageManager.type.set({
[optionKey]: optionValue,
2020-02-27 13:45:29 +01:00
});
};
2020-08-30 18:56:36 +02:00
options._onStorageOptionChanged = function ({ target }) {
chrome.storage.local.set({
[Setting.STORAGE_TYPE]: target.value,
});
if (target.value === 'local') {
storageManager.migrateData('local');
} else {
storageManager.migrateData('sync');
}
2020-08-30 18:56:36 +02:00
};
2020-08-30 19:07:14 +02:00
options._onLinkClick = function (url) {
chrome.tabs.create({
2020-08-30 19:07:14 +02:00
url: url,
active: true
});
2020-06-30 18:44:50 +02:00
};
2020-08-30 19:07:14 +02:00
options._changeTab = function ({ target }) {
let tabContent, tabButton, optionKey;
2020-06-28 14:59:07 +02:00
2020-08-30 19:07:14 +02:00
optionKey = target.getAttribute('data-option');
tabContent = document.getElementsByClassName('tab-content');
tabButton = document.getElementsByClassName('option-buttons');
2020-08-30 19:07:14 +02:00
for (let i = 0; i < tabContent.length; i++) {
if (tabContent[i].id === optionKey) {
tabContent[i].style.display = 'block';
tabButton[i].classList.add('option-buttons-active');
} else {
tabContent[i].style.display = 'none';
tabButton[i].classList.remove('option-buttons-active');
}
}
2020-08-08 07:28:41 +02:00
};
options._onChangedHexColor = function ({ target }) {
if (/#([a-f0-9]{3}){1,2}\b/i.test(target.value)) {
target.classList.remove('color-error');
if (target.id === 'badged-text-color') {
options._textColor = target.value;
wrappers.setBadgeTextColor({color: options._textColor});
document.getElementById('counter-preview-badge').style.color = options._textColor;
document.getElementById('pre-badged-text-color').style.backgroundColor = options._textColor;
} else {
options._backgroundColor = target.value;
wrappers.setBadgeBackgroundColor({color: options._backgroundColor});
document.getElementById('counter-preview-badge').style.backgroundColor = options._backgroundColor;
document.getElementById('pre-badged-background-color').style.backgroundColor = options._backgroundColor;
}
} else {
target.classList.add('color-error');
}
};
/**
* Updates the domain lists if the options page has no focus.
* document.hasFocus() prevents problems with keyboard input.
*/
options._updatesDomainLists = function (changes) {
let changedItems = Object.keys(changes);
if (!document.hasFocus()) {
2020-10-17 07:09:30 +02:00
if (changedItems[0] === 'allowlistedDomains') {
document.getElementById('tf-domains-allowlist').value = options._serializeAllowlistedDomains(changes['allowlistedDomains'].newValue);
} else if (changedItems[0] === 'domainsManipulateDOM') {
2020-10-17 07:09:30 +02:00
document.getElementById('tf-domains-manipulate-dom').value = options._serializeAllowlistedDomains(changes['domainsManipulateDOM'].newValue);
}
} else {
// document has the focus
}
};
2020-02-27 13:45:29 +01:00
/**
* Initializations
*/
2020-08-08 07:28:41 +02:00
options._internalStatistics = false;
2020-08-30 18:56:36 +02:00
options._storageType = 'local';
options._listOfFrameworks = {};
options._listOfCDNs = {};
options._platformSupportIcons = true;
2020-02-27 13:45:29 +01:00
document.addEventListener('DOMContentLoaded', options._onDocumentLoaded);
chrome.storage.onChanged.addListener(options._updatesDomainLists);