forked from scpwiki/S-CSS-P
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.js
84 lines (77 loc) · 2.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
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
82
83
84
// Saves options to chrome.storage
function save_options() {
var layout = document.getElementById('layout').value;
var color = document.getElementById('color').value;
var logo = document.getElementById('logo').value;
var font = document.getElementById('font').value;
var rating = document.getElementById('rating').value;
chrome.storage.sync.set({
activeLayout: layout,
activeColor: color,
activeLogo: logo,
activeFont: font,
activeRating: rating
}, 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() {
chrome.storage.sync.get({
activeLayout: 'none',
activeColor: 'none',
activeLogo: 'none',
activeFont: 'none',
activeRating: 'none'
}, function(items) {
document.getElementById('layout').value = items.activeLayout;
document.getElementById('color').value = items.activeColor;
document.getElementById('logo').value = items.activeLogo;
document.getElementById('font').value = items.activeFont;
document.getElementById('rating').value = items.activeRating;
changeImgLayout();
changeImgColor();
changeImgLogo();
changeImgFont();
changeImgRating();
});
}
document.addEventListener('DOMContentLoaded', restore_options);
var save = document.getElementById('save')
if(save) {
addEventListener('click',
save_options);
}
function changeImgLayout() {
var layout = document.getElementById("layout").value;
document.getElementById("select-layout").src = "/img/layout/" + layout + ".png";
}
function changeImgColor() {
var color = document.getElementById("color").value;
document.getElementById("select-color").src = "/img/color/" + color + ".png";
}
function changeImgLogo() {
var logo = document.getElementById("logo").value;
document.getElementById("select-logo").src = "/img/logo/" + logo + ".png";
}
function changeImgFont() {
var font = document.getElementById("font").value;
document.getElementById("select-font").src = "/img/font/" + font + ".png";
}
function changeImgRating() {
var rating = document.getElementById("rating").value;
document.getElementById("select-rating").src = "/img/rating/" + rating + ".png";
}
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('.layout').addEventListener('change', changeImgLayout);
document.querySelector('.color').addEventListener('change', changeImgColor);
document.querySelector('.logo').addEventListener('change', changeImgLogo);
document.querySelector('.font').addEventListener('change', changeImgFont);
document.querySelector('.rating').addEventListener('change', changeImgRating);
});