Skip to content

Commit

Permalink
Merge pull request #71 from airtower-luna/invalid-rule-warning
Browse files Browse the repository at this point in the history
Warn user about invalid rules
  • Loading branch information
airtower-luna authored Aug 14, 2022
2 parents ab781bc + 26bc96b commit ad21f33
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
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

0 comments on commit ad21f33

Please sign in to comment.