From 50a43bfc2e944a8e18c69dd50475cff3c59a186a Mon Sep 17 00:00:00 2001 From: Thomas Rientjes <synzvato@protonmail.com> Date: Sat, 26 Aug 2017 23:55:37 -0400 Subject: [PATCH] Fix domain whitelist formatting issue --- lib/main.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index bb38539..fe24d2a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -83,24 +83,41 @@ exports.main = function (options) { preferences.on('', function (preferenceName) { + let content = null; + if (preferenceName === 'amountInjected') { return; } + if (preferenceName === 'domainWhitelist') { + + let domainWhitelist = preferences.prefs['domainWhitelist']; + + content = { + 'whitelistedDomains': _parseDomainWhitelist(domainWhitelist) + }; + + } else { + + content = { + [preferenceName]: preferences.prefs[preferenceName] + }; + } + port.postMessage({ 'subject': 'update-preferences', - 'content': { - [preferenceName]: preferences.prefs[preferenceName] - } + 'content': content }); }); + let domainWhitelist = preferences.prefs['domainWhitelist']; + port.postMessage({ 'subject': 'migrate-preferences', 'content': { 'amountInjected': preferences.prefs['amountInjected'], 'blockMissing': preferences.prefs['blockMissing'], - 'domainWhitelist': preferences.prefs['domainWhitelist'], + 'whitelistedDomains': _parseDomainWhitelist(domainWhitelist), 'showReleaseNotes': preferences.prefs['showReleaseNotes'] } }); @@ -126,3 +143,29 @@ exports.broadcastInjection = function () { }); } }; + +/** + * Private Methods + */ + +function _parseDomainWhitelist(value) { + + let whitelistedDomains = {}; + + value.split(';').forEach(function (domain) { + whitelistedDomains[_normalizeDomain(domain)] = true; + }); + + return whitelistedDomains; +} + +function _normalizeDomain(domain) { + + domain = domain.toLowerCase().trim(); + + if (domain.startsWith('www.')) { + domain = domain.slice(4); + } + + return domain; +} -- GitLab