-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
46 lines (35 loc) · 1.07 KB
/
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
38
39
40
41
42
43
44
45
46
"use strict";
/* global chrome, window, document */
const textarea = document.getElementById("textarea");
const save = document.getElementById("save");
const checkbox = document.getElementById("checkbox");
textarea.placeholder = [
"facebook.com",
"instagram.com",
"youtube.com",
"twitter.com",
"reddit.com"
].join("\n");
save.addEventListener("click", () => {
const blocked = textarea.value.split("\n").map(s => s.trim()).filter(Boolean);
chrome.storage.local.set({ blocked });
});
checkbox.addEventListener("change", (event) => {
const enabled = event.target.checked;
chrome.storage.local.set({ enabled });
});
window.addEventListener("DOMContentLoaded", () => {
chrome.storage.local.get(["blocked", "enabled"], function (local) {
const { blocked, enabled } = local;
if (!Array.isArray(blocked)) {
return;
}
// blocked
var value = blocked.join("\r\n"); // display every blocked in new line
textarea.value = value;
// enabled
checkbox.checked = enabled;
// show controls
document.body.classList.add("ready");
});
});