-
Notifications
You must be signed in to change notification settings - Fork 64
/
options.js
37 lines (29 loc) · 995 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
37
import DFWP, { Rule, Rules, RuleView } from "./dfwp.js";
const { browser, storage } = DFWP;
let rules = new Rules();
function displayRules(container) {
while (container.firstChild) {
container.removeChild(container.firstChild);
}
storage.get({ rules: [] }, ({ rules: values }) => {
rules = Rules.deserialize(values);
rules.forEach((rule) => new RuleView(rule, rules).render(container));
});
}
document.addEventListener('DOMContentLoaded', () => {
const container = document.querySelector('.container');
const form = document.querySelector('.form');
form.addEventListener('submit', (event) => {
event.preventDefault();
storage.set({ rules: rules.serialize() });
});
document.querySelector('.add').addEventListener('click', () => {
const rule = new Rule();
rules.add(rule);
new RuleView(rule, rules).render(container);
});
browser.storage.onChanged.addListener(() => {
displayRules(container);
});
displayRules(container);
});