-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
54 lines (52 loc) · 1.52 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
$(document).ready(function(){
$.getJSON( "permissions.json", function(data) {
permissions = data;
var personal = $(".personal");
var friends = $(".friends");
var other = $(".other");
for(key in data) {
switch(data[key].type){
case "personal":
appendEl(personal, data[key]);
break;
case "friends":
appendEl(friends, data[key]);
break;
default:
appendEl(other, data[key]);
break;
}
}
});
function appendEl(container, el){
var id = ""+el.id;
chrome.storage.sync.get(id, function (obj) {
var value = obj[id];
el = $('<li>' +
'<label>' + el.value + '</label>' +
'<div class="green"><input type="radio" name="' + el.id + '" value="0"></div>' +
'<div class="yellow"><input type="radio" name="' + el.id + '" value="1"></div>' +
'<div class="red"><input type="radio" name="' + el.id + '" value="2"></div>' +
'</li>');
el.find(":radio[value="+ value +"]").prop("checked", true);
container.append(el);
});
}
//Save data when save it clicked
$("input[type='submit']").click(function(){
$("li").each(function(){
var id = $(this).find('input:checked').attr("name");
var value = $(this).find('input:checked').attr("value");
if(id != undefined && value != undefined){
var obj = {};
obj[id] = value;
chrome.storage.sync.set(obj, function () {
//chrome.storage.sync.get(id, function (obj) {
// console.log(obj);
//});
});
}
});
$(".info").slideDown().delay(3000).slideUp();
});
});