forked from jswanner/DontF-WithPaste
-
Notifications
You must be signed in to change notification settings - Fork 21
/
options.js
36 lines (29 loc) · 1015 Bytes
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(function() {
let rules = new DFWP.Rules();
function displayRules(container) {
while(container.firstChild) {
container.removeChild(container.firstChild);
}
DFWP.storage.get({ rules: [] }, ({ rules: values }) => {
rules = DFWP.Rules.deserialize(values);
rules.forEach((rule) => new DFWP.RuleView(rule, rules).render(container));
});
}
document.addEventListener('DOMContentLoaded', () => {
const container = document.querySelector('.container');
const form = document.querySelector('.form');
form.addEventListener('submit', (event) => {
event.preventDefault();
DFWP.storage.set({ rules: rules.serialize() });
});
document.querySelector('.add').addEventListener('click', () => {
const rule = new DFWP.Rule();
rules.add(rule);
new DFWP.RuleView(rule, rules).render(container);
});
DFWP.browser.storage.onChanged.addListener(() => {
displayRules(container);
});
displayRules(container);
});
})();