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

Added search for setting values and urls

For #623
This commit is contained in:
kkapsner 2024-12-21 22:09:53 +01:00
parent 5543d284f9
commit fd7e142681
2 changed files with 30 additions and 1 deletions

View File

@ -14,9 +14,17 @@
const extension = require("./extension");
const texts = [];
const callbacks = [];
scope.register = function(text, content){
switch (typeof text){
case "function":
callbacks.push({callback: text, content});
break;
default:
texts.push({text: text.toLowerCase(), content});
break;
}
};
scope.search = function(search){
const resultSets = search.split(/\s+/).filter(function(term){
@ -38,6 +46,11 @@
matching.add(text.content);
}
});
callbacks.forEach(function(callback){
if (callback.callback(term)){
matching.add(callback.content);
}
});
}
return matching;
});

View File

@ -576,6 +576,22 @@
settingStrings.getStrings(setting).forEach(function(string){
search.register(string, row);
});
if (setting.get){
search.register(function(term){
if (term.test(setting.get())){
return true;
}
if (setting.urlSpecific){
return setting.urlContainer.get().some(function(urlSetting){
if (urlSetting.hasOwnProperty(setting.name)){
return term.test(urlSetting.url) || term.test(urlSetting[setting.name]);
}
return false;
});
}
return false;
}, row);
}
section.addRow(row);
setupComputeDependenciesForDisplay(setting, section, row);