1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-05-29 09:28:06 +02:00

Search refinement and bugfixing

Fixes #242
This commit is contained in:
kkapsner 2018-09-19 09:15:19 +02:00
parent 2271477376
commit 5513bcbb61
4 changed files with 50 additions and 9 deletions

View File

@ -19,14 +19,35 @@
texts.push({text: text.toLowerCase(), content}); texts.push({text: text.toLowerCase(), content});
}; };
scope.search = function(search){ scope.search = function(search){
search = search.toLowerCase(); const resultSets = search.toLowerCase().split(/\s+/).filter(function(term){
const result = []; return term.trim();
texts.forEach(function(text){ }).map(function(term){
if (text.text.indexOf(search) !== -1){ return new RegExp(term);
result.push(text.content); }).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 = []; const searchListeners = [];
scope.init = function(){ scope.init = function(){

View File

@ -23,7 +23,22 @@
} }
if (settingDefinition.options){ if (settingDefinition.options){
settingDefinition.options.forEach(function(option){ 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; return messages;

View File

@ -176,11 +176,15 @@
search.init() search.init()
) )
); );
const searchOnly = window.location.search === "?searchOnly";
if (searchOnly){
document.body.classList.add("searching");
}
search.on(function({search, results, lastResults}){ search.on(function({search, results, lastResults}){
lastResults.forEach(function(node){ lastResults.forEach(function(node){
node.classList.remove("found"); node.classList.remove("found");
}); });
if (search){ if (search || searchOnly){
document.body.classList.add("searching"); document.body.classList.add("searching");
results.forEach(function(node){ results.forEach(function(node){
node.classList.add("found"); node.classList.add("found");

View File

@ -12,6 +12,7 @@ Version 0.5.4:
- added setting to control if notification details should be stored - added setting to control if notification details should be stored
- state of the arrow for url specific values is saved - state of the arrow for url specific values is saved
- browser action icon gets grayed out if the page is whitelisted - browser action icon gets grayed out if the page is whitelisted
- added search to options page
fixes: fixes:
- window and audio API were always blocked when using any of the "block ..." modes - window and audio API were always blocked when using any of the "block ..." modes