Allow regex in blacklist fixes #167 #542 (#546)

* Allow regex in blacklist fixes #167 #542
* Added protection against invalid regex causing failed initialization
* Added regex input validation
This commit is contained in:
Chad Bailey
2019-11-25 15:43:05 -06:00
committed by Ilya Grigorik
parent c4a26e3da2
commit ac7471edfc
3 changed files with 40 additions and 3 deletions

View File

@@ -163,8 +163,31 @@ function createKeyBindings(item) {
keyBindings.push({action: action, key: key, value: value, force: force, predefined: predefined});
}
// Validates settings before saving
function validate() {
var valid = true;
var status = document.getElementById('status');
document.getElementById('blacklist').value.split("\n").forEach(match => {
match = match.replace(regStrip,'')
if (match.startsWith('/')) {
try {
var regexp = new RegExp(match);
} catch(err) {
status.textContent = 'Error: Invalid Regex: ' + match
+ '. Unable to save';
valid = false;
return;
}
}
})
return valid;
}
// Saves options to chrome.storage
function save_options() {
if (validate() === false) {
return;
}
keyBindings = [];
Array.from(document.querySelectorAll(".customs")).forEach(item => createKeyBindings(item)); // Remove added shortcuts