-
Notifications
You must be signed in to change notification settings - Fork 6
/
optsave.js
69 lines (48 loc) · 1.54 KB
/
optsave.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
(function(){
chrome.runtime.getBackgroundPage(function(bgPage){
var list_el = document.getElementById('list'),
add_button_el = document.getElementById('addButton'),
colors;
var remove = function(e){
var id = e.target.id;
var index = parseInt(id.slice(4));
if(isFinite(index)){
colors.splice(index,1);
bgPage.localStorage.letBlocks = JSON.stringify(colors);
refresh();
}
}
add_button_el.onclick = function(){
var character = document.getElementById('add_character').value;
var color = document.getElementById('add_color').value;
colors.push({str: character, clr:color});
bgPage.localStorage.letBlocks = JSON.stringify(colors);
refresh();
};
var refresh = function(){
colors = JSON.parse(bgPage.localStorage.letBlocks);
var str = "";
colors.forEach(function(elm, index){
str = str + "<li>"+elm.str+" : "+elm.clr+"<button id='btn_+"+index+"'> X </button></li>"
});
list_el.innerHTML = str;
list_el.addEventListener("click", remove, false)
}
document.getElementById('resetButton').onclick = function(){
var item = Array(5);
item[0] = {str: 'e', clr: '#800000'}; //maroon
item[1] = {str: 'a',clr: '#008000'}; //green
item[2] = {str: 'I', clr: '#0000ff'}; //blue
item[3] = {str: 'O', clr:'#008080'}; //teal
item[4] = {str:'U',clr: '#800080'}; //purple
bgPage.localStorage.letBlocks = JSON.stringify(item);
refresh();
}
refresh();
});
setColors = function(colors){
chrome.runtime.getBackgroundPage(function(bgPage){
bgPage.localStorage.letBlocks = JSON.stringify(colors);
});
};
})();