-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.js
55 lines (49 loc) · 1.82 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
47
48
49
50
51
52
53
54
55
// Saves options to localStorage.
function save_options() {
//artistfolder
var inputbox = document.getElementById("path");
var checkbox = document.getElementById("save-json");
var artistfoldercheckbox = document.getElementById("artistfolder");
var path = (inputbox.value == '') ? 'DeviantArtDownloader' : inputbox.value;
var savejson = checkbox.checked;
var artistfolder = artistfoldercheckbox.checked;
localStorage["path"] = path;
localStorage["save-json"] = savejson;
localStorage["artistfolder"] = artistfolder;
console.log(path);
console.log(savejson);
console.log(artistfolder);
// Update status to let user know options were saved.
var status = document.getElementById("status");
status.innerHTML = "Options Saved.";
setTimeout(function() {
status.innerHTML = "";
}, 750);
}
// Restores select box state to saved value from localStorage.
function restore_options() {
var favorite = localStorage["path"];
if (!favorite) {
console.log("DeviantArtDownloader: No path saved.")
} else {
var inputbox = document.getElementById("path");
inputbox.value = favorite;
}
var savejson = localStorage["save-json"];
if (!savejson) {
console.log("DeviantArtDownloader: No option set.")
} else {
var checkbox = document.getElementById("save-json");
checkbox.checked = savejson == 'true';
}
//artistfolder
var artistfolder = localStorage["artistfolder"];
if (!artistfolder) {
console.log("DeviantArtDownloader: No artistfolder option set.")
} else {
var artistfoldercheckbox = document.getElementById("artistfolder");
artistfoldercheckbox.checked = artistfolder == 'true';
}
}
document.addEventListener('DOMContentLoaded', restore_options);
document.querySelector('#save').addEventListener('click', save_options);