-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
81 lines (73 loc) · 2.94 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Saves options to localStorage.
function save_options() {
//artist folder
var inputBox = document.getElementById("path");
var saveJsonCheckBox = document.getElementById("save-json");
var artistFolderCheckBox = document.getElementById("artist-folder");
var artworkFolderCheckBox = document.getElementById("artwork-folder");
var artworkRenameCheckBox = document.getElementById("artwork-rename");
var path = (inputBox.value == '') ? 'ArtstationDownloader' : inputBox.value;
var saveJson = saveJsonCheckBox.checked;
var artistFolder = artistFolderCheckBox.checked;
var artworkFolder = artworkFolderCheckBox.checked;
var artworkRename = artworkRenameCheckBox.checked;
localStorage["ad-path"] = path;
localStorage["ad-save-json"] = saveJson;
localStorage["ad-artist-folder"] = artistFolder;
localStorage["ad-artwork-folder"] = artworkFolder;
localStorage["ad-artwork-rename"] = artworkRename;
console.log(path);
console.log(saveJson);
console.log(artistFolder);
console.log(artworkFolder);
console.log(artworkRename);
// 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["ad-path"];
if (!favorite) {
console.log("ArtstationDownloader: No path saved.")
} else {
var inputBox = document.getElementById("path");
inputBox.value = favorite;
}
var saveJson = localStorage["ad-save-json"];
if (!saveJson) {
console.log("ArtstationDownloader: No option set.")
} else {
var checkbox = document.getElementById("save-json");
checkbox.checked = (saveJson === 'true');
}
//artist folder
var artistFolder = localStorage["ad-artist-folder"];
if (!artistFolder) {
console.log("ArtstationDownloader: No artist-folder option set.")
} else {
var artistFolderCheckBox = document.getElementById("artist-folder");
artistFolderCheckBox.checked = (artistFolder === 'true');
}
//artwork folder
var artworkFolder = localStorage["ad-artwork-folder"];
if (!artworkFolder) {
console.log("ArtstationDownloader: No artwork-folder option set.")
} else {
var artworkFolderCheckBox = document.getElementById("artwork-folder");
artworkFolderCheckBox.checked = (artworkFolder === 'true');
}
//artwork folder
var artworkRename = localStorage["ad-artwork-rename"];
if (!artworkRename) {
console.log("ArtstationDownloader: No artwork-rename option set.")
} else {
var artworkRenameCheckBox = document.getElementById("artwork-rename");
artworkRenameCheckBox.checked = (artworkRename === 'true');
}
}
document.addEventListener('DOMContentLoaded', restore_options);
document.querySelector('#save').addEventListener('click', save_options);