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';
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Options
|
|
|
|
*/
|
|
|
|
|
|
|
|
var options = {};
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2020-08-22 14:58:57 +02: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();
|
|
|
|
}
|
|
|
|
|
2020-08-22 14:58:57 +02:00
|
|
|
if (BrowserType.CHROMIUM) {
|
2020-07-12 15:49:37 +02:00
|
|
|
document.getElementById('html-filter-div').style.display = 'none';
|
2020-08-31 08:18:58 +02:00
|
|
|
document.getElementById('block-google-fonts').style.display = 'none';
|
2020-09-28 18:12:21 +02:00
|
|
|
document.getElementById('div-badged-text-color').style.display = 'none';
|
2020-07-05 08:55:24 +02:00
|
|
|
}
|
|
|
|
|
2020-08-22 14:58:57 +02:00
|
|
|
if (!chrome.browserAction.setIcon) {
|
2020-08-30 19:07:14 +02:00
|
|
|
document.getElementById('icon-style-div').style.display = 'none';
|
2020-09-27 11:46:32 +02:00
|
|
|
options._platformSupportIcons = false;
|
2020-07-22 07:23:00 +02:00
|
|
|
}
|
2020-09-02 06:40:43 +02:00
|
|
|
options._renderInfoPanel();
|
2021-01-16 07:56:50 +01:00
|
|
|
document.getElementById('label-version').textContent = chrome.runtime.getManifest().version;
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
options._renderOptionsPanel = function () {
|
2021-02-17 07:01:08 +01:00
|
|
|
let allowlistedDomains, domainAllowlist, elements, htmlFilterDomains, domainHtmlFilter,
|
|
|
|
googleFontsDomains, domainAllowedGoogleFonts, url, bgColor, txtColor;
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2021-02-17 07:01:08 +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
|
|
|
|
2020-06-25 07:54:17 +02:00
|
|
|
htmlFilterDomains = options._optionValues.domainsManipulateDOM;
|
2020-10-17 07:09:30 +02:00
|
|
|
domainHtmlFilter = options._serializeAllowlistedDomains(htmlFilterDomains);
|
2020-06-25 07:54:17 +02:00
|
|
|
|
2020-08-22 14:58:57 +02:00
|
|
|
googleFontsDomains = options._optionValues.allowedDomainsGoogleFonts;
|
2020-10-17 07:09:30 +02:00
|
|
|
domainAllowedGoogleFonts = options._serializeAllowlistedDomains(googleFontsDomains);
|
2020-08-22 14:58:57 +02:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
elements = options._optionElements;
|
2021-02-17 07:01:08 +01:00
|
|
|
Object.assign(elements, {[Setting.INTERNAL_STATISTICS]: document.getElementById('checkbox-internal-statistics')});
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
Object.assign(elements, {[Setting.SELECTED_ICON]: document.getElementsByName('selected-icon')});
|
2020-08-31 08:18:58 +02:00
|
|
|
|
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;
|
2020-11-14 12:31:17 +01:00
|
|
|
elements.updateNotification.value = options._optionValues.updateNotification;
|
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;
|
2020-06-25 07:54:17 +02:00
|
|
|
elements.domainsManipulateDOM.value = domainHtmlFilter;
|
|
|
|
elements.negateHtmlFilterList.checked = options._optionValues.negateHtmlFilterList;
|
2020-07-03 08:37:00 +02:00
|
|
|
elements.blockGoogleFonts.checked = options._optionValues.blockGoogleFonts;
|
2020-08-08 07:28:41 +02:00
|
|
|
elements.internalStatistics.checked = options._optionValues.internalStatistics;
|
2020-08-22 14:58:57 +02:00
|
|
|
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();
|
|
|
|
}
|
2020-03-08 12:30:03 +01:00
|
|
|
|
2020-08-22 14:58:57 +02:00
|
|
|
if (elements.blockGoogleFonts.checked) {
|
2020-10-17 07:09:30 +02:00
|
|
|
document.getElementById('div-domains-allowlist-google-fonts').style.display = 'block';
|
2020-06-26 19:49:34 +02:00
|
|
|
} else {
|
2020-10-17 07:09:30 +02:00
|
|
|
document.getElementById('div-domains-allowlist-google-fonts').style.display = 'none';
|
2020-06-26 19:49:34 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-09-27 11:46:32 +02:00
|
|
|
if (options._platformSupportIcons) {
|
2021-02-17 07:01:08 +01:00
|
|
|
let selectedIcon = options._optionValues.selectedIcon;
|
|
|
|
|
|
|
|
if (selectedIcon === 'Default') {
|
2020-09-27 11:46:32 +02:00
|
|
|
document.getElementById('icon-default').checked = true;
|
2021-02-17 07:01:08 +01:00
|
|
|
} else if (selectedIcon === 'Grey') {
|
2020-09-27 11:46:32 +02:00
|
|
|
document.getElementById('icon-grey').checked = true;
|
2021-02-17 07:01:08 +01:00
|
|
|
} else if (selectedIcon === 'Light') {
|
2020-09-27 11:46:32 +02:00
|
|
|
document.getElementById('icon-light').checked = true;
|
|
|
|
}
|
2021-02-17 07:01:08 +01:00
|
|
|
url = chrome.runtime.getURL(`icons/action/${selectedIcon.toLowerCase()}/icon38-default.png`);
|
2020-09-27 11:46:32 +02:00
|
|
|
document.getElementById('icon-badge-preview').src = url;
|
2020-09-25 07:37:09 +02:00
|
|
|
|
2020-09-27 11:46:32 +02:00
|
|
|
bgColor = options._optionValues.badgeColor || '#4A826C';
|
|
|
|
txtColor = options._optionValues.badgeTextColor || '#FFFFFF';
|
2020-09-25 16:37:02 +02:00
|
|
|
|
2020-09-27 11:46:32 +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
|
|
|
|
2020-09-27 11:46:32 +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
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
document.getElementById('last-mapping-update').textContent += ` ${mappings.lastMappingUpdate}`;
|
|
|
|
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);
|
|
|
|
});
|
2020-08-30 19:07:14 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2020-09-27 11:46:32 +02:00
|
|
|
if (options._platformSupportIcons) {
|
|
|
|
document.getElementById('badged-background-color').addEventListener('keyup', options._onChangedHexColor);
|
2020-09-28 18:12:21 +02:00
|
|
|
document.getElementById('badged-text-color').addEventListener('keyup', options._onChangedHexColor);
|
2020-09-27 11:46:32 +02:00
|
|
|
}
|
2020-09-25 16:37:02 +02:00
|
|
|
|
2020-09-25 16:18:08 +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);
|
2020-11-14 12:31:17 +01:00
|
|
|
elements.updateNotification.addEventListener('change', options._onOptionChanged);
|
2020-10-17 07:09:30 +02:00
|
|
|
elements.allowlistedDomains.addEventListener('keyup', options._onOptionChanged);
|
2020-06-25 07:54:17 +02:00
|
|
|
elements.domainsManipulateDOM.addEventListener('keyup', options._onOptionChanged);
|
|
|
|
elements.negateHtmlFilterList.addEventListener('change', options._onOptionChanged);
|
2020-07-03 08:37:00 +02:00
|
|
|
elements.blockGoogleFonts.addEventListener('change', options._onOptionChanged);
|
2020-08-31 08:18:58 +02:00
|
|
|
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);
|
2020-08-22 14:58:57 +02:00
|
|
|
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),
|
2020-11-14 12:31:17 +01:00
|
|
|
[Setting.UPDATE_NOTIFICATION]: options._getOptionElement(Setting.UPDATE_NOTIFICATION),
|
2020-03-29 10:23:16 +02:00
|
|
|
[Setting.LOGGING]: options._getOptionElement(Setting.LOGGING),
|
2020-08-22 14:58:57 +02:00
|
|
|
['ruleSets']: document.getElementsByName('rule-sets'),
|
|
|
|
['copyRuleSet']: document.getElementById('button-copy-rule-set'),
|
2020-06-25 07:54:17 +02:00
|
|
|
[Setting.NEGATE_HTML_FILTER_LIST]: options._getOptionElement(Setting.NEGATE_HTML_FILTER_LIST),
|
2020-07-03 08:37:00 +02:00
|
|
|
[Setting.DOMAINS_MANIPULATE_DOM]: options._getOptionElement(Setting.DOMAINS_MANIPULATE_DOM),
|
2020-07-08 16:37:03 +02:00
|
|
|
[Setting.BLOCK_GOOGLE_FONTS]: options._getOptionElement(Setting.BLOCK_GOOGLE_FONTS),
|
2020-08-22 14:58:57 +02:00
|
|
|
[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({
|
2021-02-17 07:01:08 +01:00
|
|
|
'value': false,
|
2020-02-27 13:45:29 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-17 07:09:30 +02:00
|
|
|
options._serializeAllowlistedDomains = function (allowlistedDomains) {
|
2021-02-17 07:01:08 +01:00
|
|
|
if (allowlistedDomains === undefined) {
|
|
|
|
return '';
|
|
|
|
}
|
2020-06-25 07:54:17 +02:00
|
|
|
|
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) {
|
2021-01-18 19:04:01 +01:00
|
|
|
domainAllowlist = `${domainAllowlist}${domain}\n`;
|
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
|
|
|
};
|
|
|
|
|
2020-09-02 06:40:43 +02:00
|
|
|
options._renderInfoPanel = function () {
|
2020-09-04 20:53:36 +02:00
|
|
|
let unsupportedFrameworks, btnCDNs, btnFrameworks;
|
2020-09-02 06:40:43 +02:00
|
|
|
|
2020-09-04 20:53:36 +02:00
|
|
|
unsupportedFrameworks = 0;
|
|
|
|
options._listOfFrameworks = {};
|
2020-09-02 06:40:43 +02:00
|
|
|
|
2020-09-04 20:53:36 +02:00
|
|
|
btnCDNs = document.getElementById('cdn');
|
|
|
|
btnCDNs.value = 'CDNs: ';
|
|
|
|
|
|
|
|
btnFrameworks = document.getElementById('framework');
|
|
|
|
btnFrameworks.value = 'Frameworks: ';
|
2020-09-02 06:40:43 +02:00
|
|
|
|
|
|
|
|
2020-09-04 20:53:36 +02:00
|
|
|
Object.values(Object.values(resources)).forEach((element) => {
|
|
|
|
let path = Object.values(element)[0];
|
|
|
|
path = path.split('/');
|
|
|
|
options._listOfFrameworks[path[1]] = true;
|
|
|
|
});
|
2020-09-02 06:40:43 +02:00
|
|
|
|
|
|
|
if (BrowserType.CHROMIUM) {
|
2020-09-04 20:53:36 +02:00
|
|
|
// Chromium based browser does not support Google Material Icons and Font Awesome
|
2020-09-02 06:40:43 +02:00
|
|
|
document.getElementById('unsupported-frameworks').style.display = 'block';
|
2020-09-04 20:53:36 +02:00
|
|
|
unsupportedFrameworks = 2;
|
2020-09-02 06:40:43 +02:00
|
|
|
}
|
2020-09-04 20:53:36 +02:00
|
|
|
|
|
|
|
options._createList('cdn');
|
2020-09-25 07:37:09 +02:00
|
|
|
document.getElementById('cdn').classList.add('btns-active');
|
2020-09-04 20:53:36 +02:00
|
|
|
|
|
|
|
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
|
2020-10-11 12:52:17 +02:00
|
|
|
btnCDNs.value += Object.keys(mappings.cdn).length - 3;
|
2020-09-04 20:53:36 +02:00
|
|
|
btnFrameworks.value += Object.keys(options._listOfFrameworks).length - unsupportedFrameworks;
|
|
|
|
};
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
options._btnCreateList = function ({target}) {
|
2020-09-25 07:37:09 +02:00
|
|
|
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');
|
|
|
|
}
|
2020-09-04 20:53:36 +02:00
|
|
|
options._createList(target.id);
|
|
|
|
};
|
|
|
|
|
|
|
|
options._createList = function (type) {
|
|
|
|
let textArea, list;
|
|
|
|
|
|
|
|
textArea = document.getElementById('generated-list');
|
|
|
|
textArea.value = '';
|
|
|
|
|
|
|
|
if (type === 'cdn') {
|
2020-10-11 12:52:17 +02:00
|
|
|
list = Object.keys(mappings.cdn);
|
2020-09-04 20:53:36 +02:00
|
|
|
} else if (type === 'framework') {
|
|
|
|
list = Object.keys(options._listOfFrameworks);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
list.forEach((elem) => {
|
|
|
|
if (!(BrowserType.CHROMIUM && (elem === 'fontawesome' || elem === 'google-material-design-icons'))) {
|
2021-02-17 07:01:08 +01:00
|
|
|
textArea.value += `${elem}\n`;
|
2020-09-04 20:53:36 +02:00
|
|
|
}
|
|
|
|
});
|
2020-09-02 06:40:43 +02:00
|
|
|
};
|
|
|
|
|
2020-09-25 07:34:59 +02:00
|
|
|
options._colorPicker = function () {
|
2021-02-17 07:01:08 +01:00
|
|
|
/* eslint-disable no-undef, no-invalid-this */
|
2020-09-25 16:37:02 +02:00
|
|
|
const badgeBackgroundColor = new CP(document.getElementById('badged-background-color'));
|
2021-02-17 07:01:08 +01:00
|
|
|
badgeBackgroundColor.on('change', function (r, g, b) {
|
2020-09-25 16:37:02 +02:00
|
|
|
this.source.value = this.color(r, g, b);
|
|
|
|
});
|
2021-02-17 07:01:08 +01:00
|
|
|
badgeBackgroundColor.on('drag', function (r, g, b) {
|
2020-09-25 16:37:02 +02:00
|
|
|
options._backgroundColor = this.color(r, g, b);
|
2021-02-17 07:01:08 +01:00
|
|
|
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 07:34:59 +02:00
|
|
|
|
2020-09-25 16:37:02 +02:00
|
|
|
const badgeTextColor = new CP(document.getElementById('badged-text-color'));
|
2021-02-17 07:01:08 +01:00
|
|
|
badgeTextColor.on('change', function (r, g, b) {
|
2020-09-25 16:37:02 +02:00
|
|
|
this.source.value = this.color(r, g, b);
|
|
|
|
});
|
2021-02-17 07:01:08 +01:00
|
|
|
badgeTextColor.on('drag', function (r, g, b) {
|
2020-09-25 16:37:02 +02:00
|
|
|
options._textColor = this.color(r, g, b);
|
2021-02-17 07:01:08 +01:00
|
|
|
this.source.value = options._textColor;
|
|
|
|
wrappers.setBadgeTextColor({'color': options._textColor});
|
2020-09-25 16:37:02 +02:00
|
|
|
document.getElementById('counter-preview-badge').style.color = options._textColor;
|
|
|
|
document.getElementById('pre-badged-text-color').style.backgroundColor = options._textColor;
|
2020-09-25 07:34:59 +02:00
|
|
|
});
|
2021-02-17 07:01:08 +01:00
|
|
|
/* eslint-enable no-undef, no-invalid-this */
|
2020-09-25 07:34:59 +02:00
|
|
|
};
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
options._setDefaultColor = function ({target}) {
|
2020-09-25 16:18:08 +02:00
|
|
|
if (target.id === 'restore-text-color') {
|
|
|
|
options._textColor = '#FFFFFF';
|
2021-02-17 07:01:08 +01:00
|
|
|
wrappers.setBadgeTextColor({'color': options._textColor});
|
2020-09-25 16:18:08 +02:00
|
|
|
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';
|
2021-02-17 07:01:08 +01:00
|
|
|
wrappers.setBadgeBackgroundColor({'color': options._backgroundColor});
|
2020-09-25 16:18:08 +02:00
|
|
|
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-09-25 07:34:59 +02:00
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-11-28 17:38:50 +01:00
|
|
|
if (optionKey === Setting.UPDATE_NOTIFICATION) {
|
|
|
|
optionValue = parseInt(optionValue);
|
|
|
|
}
|
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
if (optionKey === Setting.BLOCK_MISSING) {
|
|
|
|
if (optionValue === true) {
|
|
|
|
options._renderBlockMissingNotice();
|
|
|
|
} else {
|
|
|
|
options._hideBlockMissingNotice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optionKey === Setting.DISABLE_PREFETCH) {
|
|
|
|
options._configureLinkPrefetching(optionValue);
|
|
|
|
}
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
if (optionKey === Setting.ALLOWLISTED_DOMAINS ||
|
|
|
|
optionKey === Setting.DOMAINS_MANIPULATE_DOM ||
|
|
|
|
optionKey === Setting.ALLOWED_DOMAINS_GOOGLE_FONTS) {
|
|
|
|
|
2020-10-17 07:09:30 +02:00
|
|
|
optionValue = options._parseDomainAllowlist(optionValue);
|
2020-02-27 13:45:29 +01:00
|
|
|
}
|
|
|
|
|
2020-08-22 14:58:57 +02: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';
|
2020-08-22 14:58:57 +02:00
|
|
|
} else {
|
2020-10-17 07:09:30 +02:00
|
|
|
document.getElementById('div-domains-allowlist-google-fonts').style.display = 'none';
|
2020-08-22 14:58:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 19:49:34 +02:00
|
|
|
if (optionKey === Setting.NEGATE_HTML_FILTER_LIST) {
|
2020-08-22 14:58:57 +02:00
|
|
|
if (optionValue === true) {
|
|
|
|
document.getElementById('html-filter-domains-title-include').style.display = 'none';
|
|
|
|
document.getElementById('html-filter-domains-title-exclude').style.display = 'block';
|
2020-06-26 19:49:34 +02:00
|
|
|
} else {
|
2020-08-22 14:58:57 +02:00
|
|
|
document.getElementById('html-filter-domains-title-include').style.display = 'block';
|
|
|
|
document.getElementById('html-filter-domains-title-exclude').style.display = 'none';
|
2020-06-26 19:49:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 20:58:18 +02:00
|
|
|
if (optionKey === Setting.SELECTED_ICON) {
|
2021-02-17 07:01:08 +01:00
|
|
|
wrappers.setIcon({'path': optionValue}, 'Enabled');
|
|
|
|
let url = chrome.runtime.getURL(`icons/action/${optionValue.toLowerCase()}/icon38-default.png`);
|
2020-09-25 07:34:59 +02:00
|
|
|
document.getElementById('icon-badge-preview').src = url;
|
2020-07-08 16:37:03 +02:00
|
|
|
}
|
2020-08-30 18:56:36 +02:00
|
|
|
storageManager.type.set({
|
2020-08-22 14:58:57 +02:00
|
|
|
[optionKey]: optionValue,
|
2020-02-27 13:45:29 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
options._onStorageOptionChanged = function ({target}) {
|
2020-08-30 18:56:36 +02:00
|
|
|
chrome.storage.local.set({
|
|
|
|
[Setting.STORAGE_TYPE]: target.value,
|
|
|
|
});
|
2020-09-06 11:19:35 +02:00
|
|
|
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) {
|
2020-06-25 07:54:17 +02:00
|
|
|
chrome.tabs.create({
|
2021-02-17 07:01:08 +01:00
|
|
|
'url': url,
|
|
|
|
'active': true
|
2020-06-25 07:54:17 +02:00
|
|
|
});
|
2020-06-30 18:44:50 +02:00
|
|
|
};
|
2020-06-25 07:54:17 +02:00
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
options._changeTab = function ({target}) {
|
2020-08-30 19:07:14 +02:00
|
|
|
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-07-14 20:43:56 +02:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
options._onChangedHexColor = function ({target}) {
|
2020-09-25 16:19:34 +02:00
|
|
|
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;
|
2021-02-17 07:01:08 +01:00
|
|
|
wrappers.setBadgeTextColor({'color': options._textColor});
|
2020-09-25 16:19:34 +02:00
|
|
|
document.getElementById('counter-preview-badge').style.color = options._textColor;
|
|
|
|
document.getElementById('pre-badged-text-color').style.backgroundColor = options._textColor;
|
|
|
|
} else {
|
|
|
|
options._backgroundColor = target.value;
|
2021-02-17 07:01:08 +01:00
|
|
|
wrappers.setBadgeBackgroundColor({'color': options._backgroundColor});
|
2020-09-25 16:19:34 +02:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-30 18:51:00 +02:00
|
|
|
/**
|
|
|
|
* Updates the domain lists if the options page has no focus.
|
|
|
|
* document.hasFocus() prevents problems with keyboard input.
|
|
|
|
*/
|
2020-08-22 14:58:57 +02:00
|
|
|
options._updatesDomainLists = function (changes) {
|
2020-06-30 18:51:00 +02:00
|
|
|
let changedItems = Object.keys(changes);
|
|
|
|
|
2020-08-22 14:58:57 +02:00
|
|
|
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);
|
2020-06-30 18:51:00 +02:00
|
|
|
} 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);
|
2020-06-30 18:51:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// document has the focus
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
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';
|
2020-09-04 20:53:36 +02:00
|
|
|
options._listOfFrameworks = {};
|
|
|
|
options._listOfCDNs = {};
|
2020-09-27 11:46:32 +02:00
|
|
|
options._platformSupportIcons = true;
|
2020-02-27 13:45:29 +01:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', options._onDocumentLoaded);
|
2020-06-30 18:51:00 +02:00
|
|
|
|
|
|
|
chrome.storage.onChanged.addListener(options._updatesDomainLists);
|