-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.html
165 lines (153 loc) · 4.45 KB
/
options.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!doctype html>
<html>
<head>
<title>ByteSized for Chrome options</title>
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
<style>
#status {
position: absolute;
top:0;left:50%;
width: 200px;
background: #76857e;
border-radius: 0 0 6px 6px;
padding: 5px 10px;
text-align: center;
display: none;
}
#accounts {
margin: 20px 0;
}
#accounts .account {
font: bold 18px/1.2em Georgia, serif;
color: #f9f9f9;
padding: 5px 10px;
border-radius: 12px;
box-shadow: 0 0 4px #444;
background-color: #76857e;
background-image: -webkit-gradient(linear,left top,left bottom,
color-stop(0, #76857e),
color-stop(1, #444));
/*display: inline-block;*/
text-shadow: 1px 1px 3px #444;
margin: 20px 20px 0 0;
}
.account .user {
margin: 0 20px 0 0;
}
.account .boxes {
margin: 0 20px 0 0;
color: #888;
}
.account .delete {
border-radius: 12px;
box-shadow: 0 0 4px #444;
background-color: #CF0C13;
background-image: -webkit-gradient(linear,left top,left bottom,
color-stop(0, #CF0C13),
color-stop(1, #000));
position: relative;
float: right;
/*bottom: 10px;*/
left: 10px;
bottom: 8px;
padding: 10px;
margin-left: -20px;
}
.account .delete a {
text-decoration: none;
}
</style>
<script src="http://code.jquery.com/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="js/options.js" type="text/javascript"></script>
<script>
var form = $('<section><form>'+
'<div><label for="apikey">API-key:</label><input name="apikey" type="text" required style="width: 300px"></div>'+
'<div><button class="save">Save</button></div></form></section>');
var displayAccounts = function(){
var accounts = (localStorage.accounts) ? JSON.parse(localStorage.accounts) : [];
$('.account').detach();
if(accounts.length){
accounts.forEach(function(apikey,i){
var data = JSON.parse(localStorage[apikey]);
$('#accounts').append('<div class="account a'+i+'" apikey="'+apikey+'" style="display: none;">'+
'<span class="user">'+data.login+'</span><span class="pass"></span>'+
'</div>');
var boxes = Object.keys(data.boxes);
boxes.forEach(function(box,x){
$('.a'+i).append('<span class="boxes">'+box+'</span>');
});
$('.a'+i).append('<span class="delete"><a href="#" class="a'+i+'">X</a></span>');
$('.a'+i).fadeIn(500);
});
} else {
$('#content').append(form.clone().attr('index','0'));
}
};
$(function(){
displayAccounts();
// hooks
$('#add-box').click(function(){
$('#content').append(form.clone().attr('index',$('form').length));
});
$('button.save').live('click', function(){
var $this = $(this);
chrome.extension.sendRequest({
method: 'save',
page: 'options',
apikey: $this.parent().parent().find('input[name=apikey]').val()
}, function(res){
if(res.status == 'OK'){
$('#status').fadeIn(500).delay(2000).fadeOut(1000);
$('#status').text('Account saved.');
var timeout = setTimeout(function(){
displayAccounts();
}, 1000);
$this.parent().parent().parent().detach();
} else {
$('#status').fadeIn(500).delay(2000).fadeOut(1000);
$('#status').text('Could not save account. Error '+res.status);
}
});
return false;
});
$('.delete a').live('click', function(){
var $this = $(this);
chrome.extension.sendRequest({
method: 'delete'
,page: 'options'
,apikey: $this.parent().parent().attr('apikey')
}, function(res){
if(res.status == 'OK'){
$('#status').fadeIn(500).delay(2000).fadeOut(1000);
$('#status').text('Account removed.');
var timeout = setTimeout(function(){
displayAccounts();
}, 1000);
}
});
});
});
</script>
</head>
<body>
<div id="container">
<div id="header">
<span style="float:left;margin-bottom:4px">
<a href="http://bytesized-hosting.com/home">
<h1><img alt="Logo" src="http://bytesized-hosting.com/images/logo.png?1300985868" /></h1>
<span style="display:none">
<h1>Bytesized</h1>
<h2>Seedboxes</h2>
</span>
</a>
</div>
</div>
<p id="status"></p>
<div id="content">
<h1>Your ByteSized Accounts</h1>
<div id="accounts"></div>
<p><a href="#" id="add-box">Add another account</a></p>
</div>
</div>
</body>
</html>