Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn user about invalid rules #71

Merged
merged 1 commit into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions _locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@
"message": "Konfiguration speichern",
"description": "Save configuration"
},
"rule missing target": {
"message": "Fehler: Jede Regel muss eine Zieldomain enthalten. Regel mit leerer Zieldomain und Ursprungsdomain $ORIGIN$ wird ignoriert!",
"description": "Error message shown when the user tries to save a rule with origin domain set and empty target domain",
"placeholders": {
"origin": {
"content": "$1",
"example": "\"www.example.com\""
}
}
},
"config backup title": {
"message": "Einstellungen sichern/wiederherstellen",
"description": "Title for the configuration backup/restore section"
Expand Down
10 changes: 10 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@
"message": "Save configuration",
"description": "Save configuration"
},
"rule missing target": {
"message": "Error: Every rule must have a target domain. Ignoring rule with empty target and origin $ORIGIN$!",
"description": "Error message shown when the user tries to save a rule with origin domain set and empty target domain",
"placeholders": {
"origin": {
"content": "$1",
"example": "\"www.example.com\""
}
}
},
"config backup title": {
"message": "Configuration Backup/Restore",
"description": "Title for the configuration backup/restore section"
Expand Down
31 changes: 20 additions & 11 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,31 @@ function saveOptions()
for (let entry of entries)
{
let host = entry.querySelector(".hostname").value.trim();
if (host.length > 0)
let origin = entry.querySelector(".origin-domain").value.trim();

if (host.length == 0)
{
let act = entry.querySelector(".action");
let rule = {
domain: host,
action: act.options[act.selectedIndex].value,
referer: entry.querySelector(".referer").value.trim()
};
let origin = entry.querySelector(".origin-domain").value.trim();
if (origin !== "")
if (origin.length > 0)
{
rule.origin = origin;
window.alert(browser.i18n.getMessage(
"rule missing target", JSON.stringify(origin)));
}
domains.push(rule);
continue;
}

let act = entry.querySelector(".action");
let rule = {
domain: host,
action: act.options[act.selectedIndex].value,
referer: entry.querySelector(".referer").value.trim()
};
if (origin !== "")
{
rule.origin = origin;
}
domains.push(rule);
}

let any_action = document.querySelector("#any_action");
let any_referer = document.querySelector("#any_referer");
let same_action = document.querySelector("#same_action");
Expand Down