Skip to content

Commit 5513bcb

Browse files
committed
Search refinement and bugfixing
Fixes #242
1 parent 2271477 commit 5513bcb

4 files changed

Lines changed: 50 additions & 9 deletions

File tree

lib/search.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,35 @@
1919
texts.push({text: text.toLowerCase(), content});
2020
};
2121
scope.search = function(search){
22-
search = search.toLowerCase();
23-
const result = [];
24-
texts.forEach(function(text){
25-
if (text.text.indexOf(search) !== -1){
26-
result.push(text.content);
27-
}
22+
const resultSets = search.toLowerCase().split(/\s+/).filter(function(term){
23+
return term.trim();
24+
}).map(function(term){
25+
return new RegExp(term);
26+
}).map(function(term){
27+
const matching = new Set();
28+
texts.forEach(function(text){
29+
if (term.test(text.text)){
30+
matching.add(text.content);
31+
}
32+
});
33+
return matching;
2834
});
29-
return result;
35+
if (resultSets.length){
36+
return Array.from(
37+
resultSets.reduce(function(previousSet, set){
38+
var andSet = new Set();
39+
set.forEach(function(entry){
40+
if (previousSet.has(entry)){
41+
andSet.add(entry);
42+
}
43+
});
44+
return andSet;
45+
})
46+
);
47+
}
48+
else {
49+
return [];
50+
}
3051
};
3152
const searchListeners = [];
3253
scope.init = function(){

lib/settingStrings.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@
2323
}
2424
if (settingDefinition.options){
2525
settingDefinition.options.forEach(function(option){
26-
messages.push(settingDefinition.name + "_option." + option);
26+
if (option !== null){
27+
messages.push(settingDefinition.name + "_options." + option);
28+
}
29+
});
30+
}
31+
if (settingDefinition.inputs){
32+
settingDefinition.inputs.forEach(function(input){
33+
if (input){
34+
if (input.options){
35+
input.options.forEach(function(option){
36+
if (option !== null){
37+
messages.push(input.name + "_options." + option);
38+
}
39+
});
40+
}
41+
}
2742
});
2843
}
2944
return messages;

options/options.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,15 @@
176176
search.init()
177177
)
178178
);
179+
const searchOnly = window.location.search === "?searchOnly";
180+
if (searchOnly){
181+
document.body.classList.add("searching");
182+
}
179183
search.on(function({search, results, lastResults}){
180184
lastResults.forEach(function(node){
181185
node.classList.remove("found");
182186
});
183-
if (search){
187+
if (search || searchOnly){
184188
document.body.classList.add("searching");
185189
results.forEach(function(node){
186190
node.classList.add("found");

releaseNotes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Version 0.5.4:
1212
- added setting to control if notification details should be stored
1313
- state of the arrow for url specific values is saved
1414
- browser action icon gets grayed out if the page is whitelisted
15+
- added search to options page
1516

1617
fixes:
1718
- window and audio API were always blocked when using any of the "block ..." modes

0 commit comments

Comments
 (0)