-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
37 lines (31 loc) · 1.25 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
function saveOptions(e) {
browser.storage.sync.set({
description: document.querySelector("#description").value ,
template: document.querySelector("#template").value
});
e.preventDefault();
}
function restoreOptions() {
var getting_description = browser.storage.sync.get('description');
var getting_template = browser.storage.sync.get('template');
getting_description.then((res) => {
document.querySelector("#description").value = res.description || 'copy markdown link';
});
getting_template.then((res) => {
document.querySelector("#template").value = res.template || '[$LINKTEXT]($URL)';
});
}
function prefillOptions(e) {
document.querySelector("#description").value = this.querySelector(".description").value;
document.querySelector("#template").value = this.querySelector(".template").value;
e.preventDefault();
}
function loadPrefillOptions() {
var examples = document.querySelectorAll(".examples");
for (let i = 0; i < examples.length; i++) {
examples[i].addEventListener("submit", prefillOptions);
}
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);
document.addEventListener('DOMContentLoaded', loadPrefillOptions);