-
Notifications
You must be signed in to change notification settings - Fork 9
/
options.js
61 lines (60 loc) · 2.63 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
'use strict';
// Saves options to chrome.storage
function save_options() {
var searchResultTarget = document.getElementById('searchResultTarget').checked;
var firstUrl = document.getElementById('firstUrl').value;
var firstUrlIcon = document.getElementById('firstUrlIcon').value;
var secondUrl = document.getElementById('secondUrl').value;
var secondUrlIcon = document.getElementById('secondUrlIcon').value;
var thirdUrl = document.getElementById('thirdUrl').value;
var thirdUrlIcon = document.getElementById('thirdUrlIcon').value;
var fourthUrl = document.getElementById('fourthUrl').value;
var fourthUrlIcon = document.getElementById('fourthUrlIcon').value;
chrome.storage.sync.set({
searchResultTarget: searchResultTarget,
firstUrl: firstUrl,
firstUrlIcon: firstUrlIcon,
secondUrl: secondUrl,
secondUrlIcon: secondUrlIcon,
thirdUrl: thirdUrl,
thirdUrlIcon: thirdUrlIcon,
fourthUrl: fourthUrl,
fourthUrlIcon: fourthUrlIcon
}, function () {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function () {
status.textContent = '';
}, 750);
});
}
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
// Use default value color = 'red' and likesColor = true.
chrome.storage.sync.get({
searchResultTarget: false,
firstUrl: "",
firstUrlIcon: "",
secondUrl: "",
secondUrlIcon: "",
thirdUrl: "",
thirdUrlIcon: "",
fourthUrl: "",
fourthUrlIcon: ""
}, function (items) {
document.getElementById('searchResultTarget').checked = items.searchResultTarget;
document.getElementById('firstUrl').value = items.firstUrl;
document.getElementById('firstUrlIcon').value = items.firstUrlIcon;
document.getElementById('secondUrl').value = items.secondUrl;
document.getElementById('secondUrlIcon').value = items.secondUrlIcon;
document.getElementById('thirdUrl').value = items.thirdUrl;
document.getElementById('thirdUrlIcon').value = items.thirdUrlIcon;
document.getElementById('fourthUrl').value = items.fourthUrl;
document.getElementById('fourthUrlIcon').value = items.fourthUrlIcon;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save_options);
document.getElementById('restore').addEventListener('click', restore_options);