1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

Added tag search

This commit is contained in:
kkapsner 2024-04-08 00:09:37 +02:00
parent 54c625cd26
commit 56401048d1
2 changed files with 18 additions and 9 deletions

View File

@ -19,17 +19,26 @@
texts.push({text: text.toLowerCase(), content});
};
scope.search = function(search){
const resultSets = search.toLowerCase().split(/\s+/).filter(function(term){
const resultSets = search.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);
}
});
if (term.match(/^:[a-z]+$/i)){
const tag = term.substring(1);
texts.forEach(function(text){
if (text.content.querySelector(`.${tag}`)){
matching.add(text.content);
}
});
}
else {
term = new RegExp(term.toLowerCase());
texts.forEach(function(text){
if (term.test(text.text)){
matching.add(text.content);
}
});
}
return matching;
});
if (resultSets.length){

View File

@ -3,7 +3,7 @@ Version 1.10.1:
-
new features:
-
- added tag search
fixes:
- lag and functionality loss on google sites