From 62d3eefd675a9336232e594e41f4ddfbb01e4707 Mon Sep 17 00:00:00 2001 From: Ray Lothian Date: Sun, 4 Nov 2018 10:37:09 +0100 Subject: [PATCH] exact matching preference; fixes #26 --- common.js | 21 ++++++++++++++++++--- data/options/index.html | 3 +++ data/options/index.js | 3 +++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/common.js b/common.js index fe0b4a0..bbee2e4 100644 --- a/common.js +++ b/common.js @@ -14,7 +14,8 @@ var prefs = { custom: {}, mode: 'blacklist', color: '#ffa643', - cache: true + cache: true, + exactMatch: false }; chrome.storage.local.get(prefs, ps => { Object.assign(prefs, ps); @@ -160,13 +161,27 @@ function match({url, tabId}) { if (prefs.mode === 'blacklist') { if (prefs.blacklist.length) { const h = hostname(url); - return prefs.blacklist.some(s => s === h); + return prefs.blacklist.some(s => () => { + if (s === h) { + return true; + } + else if (prefs.exactMatch === false) { + return s.endsWith(h) || h.endsWith(s); + } + }); } } else if (prefs.mode === 'whitelist') { if (prefs.whitelist.length) { const h = hostname(url); - return prefs.whitelist.some(s => s === h) === false; + return prefs.whitelist.some(s => { + if (s === h) { + return true; + } + else if (prefs.exactMatch === false) { + return s.endsWith(h) || h.endsWith(s); + } + }) === false; } else { return true; diff --git a/data/options/index.html b/data/options/index.html index 6d3e285..2befbd8 100644 --- a/data/options/index.html +++ b/data/options/index.html @@ -45,6 +45,9 @@ + + + diff --git a/data/options/index.js b/data/options/index.js index 4fbf0bc..ba923a9 100644 --- a/data/options/index.js +++ b/data/options/index.js @@ -29,6 +29,7 @@ function save() { } chrome.storage.local.set({ + exactMatch: document.getElementById('exactMatch').checked, faqs: document.getElementById('faqs').checked, cache: document.getElementById('cache').checked, blacklist: prepare(document.getElementById('blacklist').value), @@ -43,6 +44,7 @@ function save() { function restore() { chrome.storage.local.get({ + exactMatch: false, faqs: true, cache: true, mode: 'blacklist', @@ -50,6 +52,7 @@ function restore() { blacklist: [], custom: {} }, prefs => { + document.getElementById('exactMatch').checked = prefs.exactMatch; document.getElementById('faqs').checked = prefs.faqs; document.getElementById('cache').checked = prefs.cache; document.querySelector(`[name="mode"][value="${prefs.mode}"`).checked = true;