-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpop.js
More file actions
71 lines (64 loc) · 1.92 KB
/
pop.js
File metadata and controls
71 lines (64 loc) · 1.92 KB
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
var bg, txt, border, lbg, ltxt, lborder, state;
function applyChange(id, val) {
localStorage.setItem('contrast-chrome-extension-'+id, val);
chrome.runtime.sendMessage({what:""+id, value:""+val});
}
// set current values in popup.html
function initPreset() {
bg = document.getElementById('background');
txt = document.getElementById('text');
border = document.getElementById('border');
state = document.getElementById('state');
lbg = localStorage.getItem('contrast-chrome-extension-background');
ltxt = localStorage.getItem('contrast-chrome-extension-text');
lborder = localStorage.getItem('contrast-chrome-extension-border');
if (lbg != null)
bg.value = lbg;
if (ltxt != null)
txt.value = ltxt;
if (lborder != null)
border.value = lborder;
}
//
function changeColorInputState(state) {
document.getElementById('state').checked = !state;
var list1 = document.getElementsByClassName('container');
var val = "";
if (state) val = "none";
else val = "block";
list1[0].style.display = val;
list1[1].style.display = val;
list1[2].style.display = val;
}
// add input listeners to color-input elements
function initListeners() {
bg.addEventListener('input', function () {
applyChange('background', bg.value);
});
txt.addEventListener('input', function () {
applyChange('text', txt.value);
});
border.addEventListener('input', function () {
applyChange('border', border.value);
});
state.addEventListener('change', function () {
if (this.checked) {
localStorage.setItem('contrast-chrome-extension-state', 'enabled');
changeColorInputState(false);
} else {
localStorage.setItem('contrast-chrome-extension-state', 'disabled');
changeColorInputState(true);
}
});
}
window.onload = (function () {
initPreset();
initListeners();
var result = localStorage.getItem('contrast-chrome-extension-state');
if (result == "enabled") {
changeColorInputState(false);
}
else {
changeColorInputState(true);
}
});