-
Notifications
You must be signed in to change notification settings - Fork 4
/
options.js
46 lines (42 loc) · 1.59 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
document.addEventListener("DOMContentLoaded", () => {
document.getElementById("save").addEventListener("click", () => {
const restrictedUrls = document
.getElementById("restrictedUrls")
.value.split("\n");
chrome.storage.sync.set({ restrictedUrls });
const markdownFormat = document.getElementById("markdownFormat").value;
chrome.storage.sync.set({ restrictedUrls, markdownFormat });
});
document.getElementById("presetFormats").addEventListener("change", (event) => {
document.getElementById("markdownFormat").value = event.target.value;
});
chrome.storage.sync.get(
["restrictedUrls", "markdownFormat"],
({ restrictedUrls, markdownFormat }) => {
if (restrictedUrls) {
document.getElementById("restrictedUrls").value =
restrictedUrls.join("\n");
} else {
setDefaultRestrictedUrls();
}
if (markdownFormat) {
document.getElementById("markdownFormat").value = markdownFormat;
} else {
setDefaultMarkdownFormat();
}
}
);
});
function setDefaultRestrictedUrls() {
const defaultRestrictedUrls = ["chrome-extension://", "extension://", "mail.google.com", "outlook.live.com"];
document.getElementById("restrictedUrls").value =
defaultRestrictedUrls.join("\n");
chrome.storage.sync.set({ restrictedUrls: defaultRestrictedUrls });
}
function setDefaultMarkdownFormat() {
const defaultMarkdownFormat = "## {title}\n[{url}]({url})\n\n";
document.getElementById("markdownFormat").value = defaultMarkdownFormat;
chrome.storage.sync.set({
markdownFormat: defaultMarkdownFormat,
});
}