forked from cezarsa/silver_bird
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.html
executable file
·361 lines (325 loc) · 12.4 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/options.css" />
<link rel="stylesheet" type="text/css" href="css/colorpicker/colorpicker.css" />
<script type="text/javascript" src="lib/3rdparty/jquery.js"></script>
<script type="text/javascript" src="lib/3rdparty/colorpicker.js"></script>
<script type="text/javascript" src="lib/shortener_lib.js"></script>
<title>Chromed Bird Options</title>
<script type="text/javascript">
var OptionsBackend = chrome.extension.getBackgroundPage().OptionsBackend;
function Options() {
this.optionsMap = {};
this.load = function(forceDefault) {
this.optionsMap = OptionsBackend.load(forceDefault);
var _this = this;
$('input,select,canvas.color_selector').each(function() {
var $this = $(this);
var name = $this.attr('name');
if(name) {
if($this.is('[type="checkbox"]')) {
$this.attr('checked', _this.optionsMap[name]);
} else if($this.is('canvas')) {
$this.attr('hexColor', _this.optionsMap[name]);
paintIcon($this[0], _this.optionsMap[name]);
$this.ColorPickerSetColor(_this.optionsMap[name]);
} else {
$this.val(_this.optionsMap[name]);
}
}
});
};
this.loadDefaults = function() {
this.load(true);
this.save();
};
this.save = function() {
this.clearErrors();
var hasErrors = false;
var _this = this;
$('input,select').each(function() {
var $this = $(this);
var validator = $this.attr('validator');
if(validator) {
var validatorsArray = validator.split(',');
for(var i = 0; i < validatorsArray.length; ++i) {
var validInfo = Validator[validatorsArray[i]]($this);
if(validInfo !== true) {
hasErrors = true;
_this.addValidationError($this, validInfo);
return true;
}
}
}
});
if(!hasErrors) {
$('input,select,canvas.color_selector').each(function() {
var $this = $(this);
var name = $this.attr('name');
if(name) {
if($this.is('[type="checkbox"]')) {
_this.optionsMap[name] = $this.attr('checked');
} else if($this.is('canvas')) {
_this.optionsMap[name] = $this.attr('hexColor');
} else {
var elValue = $this.val();
var intValue = parseInt(elValue );
if(intValue == elValue) {
elValue = intValue;
}
_this.optionsMap[name] = elValue;
}
}
});
OptionsBackend.save(this.optionsMap);
$(document).scrollTop(0);
$("#saved_notice").stop().show().css('opacity', '1.0').fadeOut(5000);
}
};
this.addValidationError = function($el, error) {
var errorEl = $("<span>").attr('class', 'error').html(error);
$el.after(errorEl);
};
this.clearErrors = function() {
$('.error').remove();
};
}
/* ---- validation ---- */
Validator = {
global: function() {
},
required: function ($el) {
var val = $el.val()
if(!val)
return 'It can\'t be empty.';
return true;
},
number: function ($el) {
var intVal = parseInt($el.val());
if(isNaN(intVal))
return 'It should be a number.';
return true;
},
positive: function ($el) {
if(parseInt($el.val()) <= 0)
return 'It should be positive.';
return true;
},
minRefresh: function ($el) {
if(parseInt($el.val()) < 20000)
return 'Minimum interval is 20000ms';
return true;
},
url: function ($el) {
if($el.val().match(/(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i)) {
return true;
}
return 'It should be a valid URL.';
}
}
/* ---- end validation ---- */
var IconCreator = chrome.extension.getBackgroundPage().IconCreator;
var twitterBackend = chrome.extension.getBackgroundPage().TweetManager.instance.twitterBackend;
var options = new Options();
var imgEl = null;
function paintIcon(canvas, color) {
if(!imgEl) {
var img = $('<img>').attr('src', 'img/icon19.png');
img.load(function() {
imgEl = img[0];
var imgData = IconCreator.paintIcon(imgEl, color);
canvas.getContext("2d").putImageData(imgData, 0, 0);
});
} else {
var imgData = IconCreator.paintIcon(imgEl, color);
canvas.getContext("2d").putImageData(imgData, 0, 0);
}
}
var hourlyLimit = 150;
$(function() {
if(twitterBackend) {
var hitsInfo = twitterBackend.remainingHitsInfo();
$(".twitter_hits_left").text(hitsInfo[0]);
var dateObj = new Date();
dateObj.setTime(parseInt(hitsInfo[1]) * 1000);
$(".twitter_hits_reset").text(dateObj.toLocaleDateString() + " " + dateObj.toLocaleTimeString());
if(hitsInfo[2]) {
hourlyLimit = parseInt(hitsInfo[2]);
}
}
$(".__hourly_limit").text(hourlyLimit);
for(var key in SHORTENERS_BACKEND) {
var desc = SHORTENERS_BACKEND[key].desc;
$("select[name='url_shortener']").append($("<option>").attr('value', key).text(desc));
}
$("select[name='url_shortener']").change(function() {
if(this.value=='bitly' || this.value=='jmp') {
$("#shortener_opts").show();
}
else {
$("#shortener_opts").hide();
}
});
$('canvas.color_selector').ColorPicker({
onChange: function (hsb, hex, rgb) {
var canvas = this.data('colorpicker').el;
$(canvas).attr('hexColor', '#' + hex);
paintIcon(canvas, rgb);
}
});
options.load();
updatePredictedHitsCount();
var timelines = ['home', 'mentions', 'dms', 'lists', 'favorites'];
for(var i = 0; i < timelines.length; ++i) {
var inputEl = $('input[name="' + timelines[i] + '_refresh_interval"]');
inputEl.keyup(updatePredictedHitsCount);
inputEl.blur(updatePredictedHitsCount);
}
});
function updatePredictedHitsCount() {
var timelines = ['home', 'mentions', 'dms', 'lists', 'favorites'];
var totalHits = 0;
for(var i = 0; i < timelines.length; ++i) {
var inputEl = $('input[name="' + timelines[i] + '_refresh_interval"]');
var intVal = parseInt(inputEl.val());
totalHits += (60 * 60 * 1000) / intVal;
}
totalHits = parseInt(totalHits);
$('#predicted_hits_count').text(totalHits);
if(totalHits >= hourlyLimit) {
$('#predicted_hits_count').css('backgroundColor', 'red');
} else if(totalHits >= hourlyLimit * 0.85) {
$('#predicted_hits_count').css('backgroundColor', 'yellow');
} else {
$('#predicted_hits_count').css('backgroundColor', 'white');
}
return totalHits;
}
</script>
</head>
<body>
<h1>Chromed Bird Options</h1>
<div id="saved_notice">Your configuration has been successfully saved!</div>
<div id="main_area">
<p class="notice">
Please notice that options denoted with asterisk "*" will only take effect if you restart the extension. (Disabling and enabling it again)
</p>
<p>
Remaining Twitter API Hits: <span class="twitter_hits_left"></span><br>
Rate Limit Reset: <span class="twitter_hits_reset"></span>
</p>
<fieldset>
<legend>UI</legend>
<label for="name_attribute">Name in tweets:</label>
<select name="name_attribute">
<option value="screen_name">Screen name (nickname)</option>
<option value="name">Real name</option>
</select><br>
<label for="compose_position">Compose area position:</label>
<select name="compose_position">
<option value="top">Top</option>
<option value="bottom">Bottom</option>
</select><br>
<label for="theme">UI Theme:</label>
<select name="theme">
<option value="css/chromified.css,css/chromified-theme/jquery-ui-1.7.2.custom.css">Chromified</option>
<option value="css/whisper.css,css/whisper-theme/jquery-ui-1.7.2.custom.css">Whispers</option>
</select><br>
<label>*Icon color:</label>
<canvas name="idle_color" width="19" height="19" class="color_selector"></canvas>
</fieldset>
<fieldset>
<legend>Notifications</legend>
<table>
<tr>
<th></th>
<th>Show on Page</th>
<th>Change Icon</th>
<th>Icon Color</th>
<tr>
<td class="label">Home:</td>
<td><input type="checkbox" name="home_on_page"></td>
<td><input type="checkbox" name="home_icon"></td>
<td><canvas name="home_color" width="19" height="19" class="color_selector"></canvas></td>
</tr>
<tr>
<td class="label">Mentions:</td>
<td><input type="checkbox" name="mentions_on_page"></td>
<td><input type="checkbox" name="mentions_icon"></td>
<td><canvas name="mentions_color" width="19" height="19" class="color_selector"></canvas></td>
</tr>
<tr>
<td class="label">DMs:</td>
<td><input type="checkbox" name="dms_on_page"></td>
<td><input type="checkbox" name="dms_icon"></td>
<td><canvas name="dms_color" width="19" height="19" class="color_selector"></canvas></td>
</tr>
<tr>
<td class="label">Lists:</td>
<td><input type="checkbox" name="lists_on_page"></td>
<td><input type="checkbox" name="lists_icon"></td>
<td><canvas name="lists_color" width="19" height="19" class="color_selector"></canvas></td>
</tr>
</table><br>
<label for="notification_fade_timeout">On Page Fade Timeout:</label>
<input type="text" name="notification_fade_timeout" validator="required,number,positive"><br>
</fieldset>
<fieldset>
<legend>Shortener</legend>
<label for="url_shortener">URL Shortener:</label>
<select name="url_shortener"></select><br>
<p id="shortener_opts">
<label for="shortener_acct">Use Personal Account?</label>
<input type="checkbox" name="shortener_acct"><br>
<label for="shortener_login">API Login:</label>
<input type="text" name="shortener_login"><br>
<label for="shortener_key">API Key:</label>
<input type="text" name="shortener_key">
</p>
</fieldset>
<fieldset>
<legend>Refresh Interval (ms)</legend>
<p class="notice" style="text-align: center; color: black;">
You should keep API hits <span style="color: red;">below <span class="__hourly_limit"></span></span>! Otherwise Chromed Bird will stop working properly and timelines won't update anymore.<br>
<span style="color: red;">Remember</span> that if you're using multiple Twitter clients you'll need to keep your API hits even lower.
</p>
<p class="hits_notice">
API hits per hour: <span id="predicted_hits_count"></span> / <span class="__hourly_limit">
</p>
<label for="home_refresh_interval">*Home Timeline:</label>
<input type="text" name="home_refresh_interval" validator="required,number,minRefresh"><br>
<label for="mentions_refresh_interval">*Mentions Timeline:</label>
<input type="text" name="mentions_refresh_interval" validator="required,number,minRefresh"><br>
<label for="dms_refresh_interval">*DM Timeline:</label>
<input type="text" name="dms_refresh_interval" validator="required,number,minRefresh"><br>
<label for="lists_refresh_interval">*Lists Timeline:</label>
<input type="text" name="lists_refresh_interval" validator="required,number,minRefresh"><br>
<label for="favorites_refresh_interval">*Favorites Timeline:</label>
<input type="text" name="favorites_refresh_interval" validator="required,number,minRefresh"><br>
</fieldset>
<fieldset>
<legend>Timelines</legend>
<label for="tweets_per_page">*Tweets per Page:</label>
<input type="text" name="tweets_per_page" validator="required,number,positive"><br>
<label for="max_cached_tweets">*Max Shown Tweets:</label>
<input type="text" name="max_cached_tweets" validator="required,number,positive"><br>
</fieldset>
<fieldset>
<legend>Advanced</legend>
<label for="request_timeout">*Request Timeout (ms):</label>
<input type="text" name="request_timeout" validator="required,number,positive"><br>
<label for="base_url">*Twitter's API URL:</label>
<input type="text" name="base_url" style="width: 300px;" validator="required,url"><br>
<label for="base_signing_url">*OAuth Signature URL:</label>
<input type="text" name="base_signing_url" style="width: 300px;" validator="required,url"><br>
<label for="base_authorize_url">*OAuth Authorize URL:</label>
<input type="text" name="base_authorize_url" style="width: 300px;" validator="required,url"><br>
</fieldset>
<br>
<input type="button" value="Save" onclick="options.save();">
<input type="button" value="Reset" onclick="options.load();">
<input type="button" value="Reset to default" onclick="options.loadDefaults();">
</div>
</body>
</html>