diff --git a/lib/search.js b/lib/search.js index 6971e94..0371fd0 100644 --- a/lib/search.js +++ b/lib/search.js @@ -19,14 +19,35 @@ texts.push({text: text.toLowerCase(), content}); }; scope.search = function(search){ - search = search.toLowerCase(); - const result = []; - texts.forEach(function(text){ - if (text.text.indexOf(search) !== -1){ - result.push(text.content); - } + const resultSets = search.toLowerCase().split(/\s+/).filter(function(term){ + return term.trim(); + }).map(function(term){ + return new RegExp(term); + }).map(function(term){ + const matching = new Set(); + texts.forEach(function(text){ + if (term.test(text.text)){ + matching.add(text.content); + } + }); + return matching; }); - return result; + if (resultSets.length){ + return Array.from( + resultSets.reduce(function(previousSet, set){ + var andSet = new Set(); + set.forEach(function(entry){ + if (previousSet.has(entry)){ + andSet.add(entry); + } + }); + return andSet; + }) + ); + } + else { + return []; + } }; const searchListeners = []; scope.init = function(){ diff --git a/lib/settingStrings.js b/lib/settingStrings.js index a534d17..f085782 100644 --- a/lib/settingStrings.js +++ b/lib/settingStrings.js @@ -23,7 +23,22 @@ } if (settingDefinition.options){ settingDefinition.options.forEach(function(option){ - messages.push(settingDefinition.name + "_option." + option); + if (option !== null){ + messages.push(settingDefinition.name + "_options." + option); + } + }); + } + if (settingDefinition.inputs){ + settingDefinition.inputs.forEach(function(input){ + if (input){ + if (input.options){ + input.options.forEach(function(option){ + if (option !== null){ + messages.push(input.name + "_options." + option); + } + }); + } + } }); } return messages; diff --git a/options/options.js b/options/options.js index c674aad..60b39ad 100644 --- a/options/options.js +++ b/options/options.js @@ -176,11 +176,15 @@ search.init() ) ); + const searchOnly = window.location.search === "?searchOnly"; + if (searchOnly){ + document.body.classList.add("searching"); + } search.on(function({search, results, lastResults}){ lastResults.forEach(function(node){ node.classList.remove("found"); }); - if (search){ + if (search || searchOnly){ document.body.classList.add("searching"); results.forEach(function(node){ node.classList.add("found"); diff --git a/releaseNotes.txt b/releaseNotes.txt index caf7b4f..69e9c61 100644 --- a/releaseNotes.txt +++ b/releaseNotes.txt @@ -12,6 +12,7 @@ Version 0.5.4: - added setting to control if notification details should be stored - state of the arrow for url specific values is saved - browser action icon gets grayed out if the page is whitelisted + - added search to options page fixes: - window and audio API were always blocked when using any of the "block ..." modes