diff --git a/inject.js b/inject.js index 4c6f39a..73226ca 100644 --- a/inject.js +++ b/inject.js @@ -280,7 +280,7 @@ // the first element of the target, which may not be the parent. this.parent.insertBefore(fragment, this.parent.firstChild); } - return wrapper; + return wrapper; } } @@ -297,7 +297,16 @@ return; } - var regexp = new RegExp(escapeStringRegExp(match)); + if (match.startsWith('/')) { + try { + var regexp = new RegExp(match); + } catch(err) { + return; + } + } else { + var regexp = new RegExp(escapeStringRegExp(match)); + } + if (regexp.test(location.href)) { blacklisted = true; return; diff --git a/options.html b/options.html index 770dd34..765809b 100644 --- a/options.html +++ b/options.html @@ -109,7 +109,12 @@
- +
diff --git a/options.js b/options.js index 7d2c728..8bc0719 100644 --- a/options.js +++ b/options.js @@ -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