mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-03 12:06:31 +02:00
parent
2271477376
commit
5513bcbb61
4 changed files with 50 additions and 9 deletions
|
@ -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(){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue