Skip to content

Commit

Permalink
Change “Edit Rule” button behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Cimbali committed Mar 14, 2020
1 parent c3df3de commit 658a68a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion addon/modules/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ let Rules = {
return save_rules(Rules.all_rules)
},
reload: () => load_rules().then(loaded => Rules.all_rules = loaded),
replace: new_data => clear_rules().then(() => {
replace: new_data => clear_rules().then(() =>
{
Rules.all_rules = new_data;
return save_rules(Rules.all_rules);
}),
Expand Down
18 changes: 10 additions & 8 deletions addon/pages/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,12 @@ function reset_rules()

function prepopulate_rule(link)
{
let url = new URL(link)
document.getElementById('rule_selector').selectedIndex = 0;
document.querySelector('input[name="domain"]').value = url.hostname;
document.querySelector('input[name="path"]').value = url.pathname;
let url = new URL(link);
let rule = {domain: url.hostname, path: '^' + url.pathname + '$', ...default_actions};

rule_changed();
let opt = new Option(name_rule(rule), JSON.stringify(rule), false, true);
document.getElementById('rule_selector').appendChild(opt);
load_rule();
}


Expand Down Expand Up @@ -584,12 +584,14 @@ function add_listeners()
if (message.action === 'set prepopulate')
{
prepopulate_rule(message.link);
return browser.runtime.sendMessage({action: 'get prepopulate'})
return browser.runtime.sendMessage({action: 'get prepopulate'}).catch(() => {});
}
else if (message.action === 'rules')
Rules.reload().then(populate_rules);
return Rules.reload().then(populate_rules);
else if (message.action === 'reload options')
Prefs.reload().then(populate_options());
return Prefs.reload().then(populate_options());
else
return Promise.resolve('Options page ignored unknown message ' + message.action)
});
}

Expand Down

0 comments on commit 658a68a

Please sign in to comment.