forked from cezarsa/silver_bird
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.html
executable file
·540 lines (502 loc) · 21.6 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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
<!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/math_utils.js"></script>
<script type="text/javascript" src="lib/shortener_lib.js"></script>
<script type="text/javascript" src="lib/options/options.js"></script>
<title>Chromed Bird Options</title>
<script type="text/javascript">
var IconCreator = chrome.extension.getBackgroundPage().IconCreator;
var tweetManager = chrome.extension.getBackgroundPage().TweetManager.instance;
var twitterBackend = tweetManager.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() {
var resetDateObj = new Date();
if(twitterBackend) {
var hitsInfo = twitterBackend.remainingHitsInfo();
$(".twitter_hits_left").text(hitsInfo[0]);
resetDateObj.setTime(parseInt(hitsInfo[1]) * 1000);
$(".twitter_hits_reset").text(resetDateObj.toLocaleDateString() + " " + resetDateObj.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));
}
var onShortenerChange = function() {
var shortenerSelect = $("select[name='url_shortener']")[0]
if(shortenerSelect.value=='bitly' || shortenerSelect.value=='jmp') {
$("#shortener_opts").show();
} else {
$("#shortener_opts").hide();
}
};
var onShortenerAcctClick = function() {
if($("input[name='shortener_acct']").attr('checked')) {
$("input[name='shortener_login']").removeAttr('disabled');
$("input[name='shortener_key']").removeAttr('disabled');
} else {
$("input[name='shortener_login']").val('').attr('disabled', 'disabled');
$("input[name='shortener_key']").val('').attr('disabled', 'disabled');
}
};
$("select[name='url_shortener']").change(onShortenerChange);
$("input[name='shortener_acct']").click(onShortenerAcctClick);
var onSigningUrlCheck = function() {
var $check = $("input[name='same_signing_urls']");
if($check.attr('checked')) {
$("input[name='base_signing_url'], input[name='base_oauth_signing_url']").attr('disabled', 'disabled');
$("input[name='base_signing_url']").val($("input[name='base_url']").val());
$("input[name='base_oauth_signing_url']").val($("input[name='base_oauth_url']").val());
$("input[name='base_url']").bind('keyup blur', function() {
$("input[name='base_signing_url']").val($(this).val());
});
$("input[name='base_oauth_url']").bind('keyup blur', function() {
$("input[name='base_oauth_signing_url']").val($(this).val());
});
} else {
$("input[name='base_signing_url'], input[name='base_oauth_signing_url']").removeAttr('disabled');
$("input[name='base_url']").unbind('keyup blur');
$("input[name='base_oauth_url']").unbind('keyup blur');
}
};
$("input[name='same_signing_urls']").click(onSigningUrlCheck);
$('canvas.color_selector').ColorPicker({
onChange: function (hsb, hex, rgb, rgbaStr) {
var canvas = this.data('colorpicker').el;
$(canvas).attr('strColor', rgbaStr);
paintIcon(canvas, rgb);
}
});
$('div.color_selector').ColorPicker({
onChange: function (hsb, hex, rgb, rgbaStr) {
var div = this.data('colorpicker').el;
$(div).attr('strColor', rgbaStr);
$(div).css('backgroundColor', rgbaStr);
}
});
options.onload(function() {
onShortenerChange();
onShortenerAcctClick();
onSigningUrlCheck();
});
options.onsaveChangedOption(function(optionName, oldValue, newValue) {
var idx;
if((idx = optionName.indexOf('_visible')) != -1) {
var templateId = optionName.substring(0, idx);
if(newValue) {
tweetManager.showTimelineTemplate(templateId, true);
} else {
tweetManager.hideTimelineTemplate(templateId);
}
} else if((idx = optionName.indexOf('_include_unified')) != -1) {
var templateId = optionName.substring(0, idx);
tweetManager.toggleUnified(templateId, newValue);
}
});
options.onsave(function() {
if($("#noti_desktop").is(":checked")) {
try {
var notificationCenter = window.notifications || window.webkitNotifications;
if(!notificationCenter) {
throw 'out';
}
var authStatus = notificationCenter.checkPermission();
if(authStatus == 1 || authStatus == 2) { // Not allowed or Denied
notificationCenter.requestPermission(function() {
var authStatus = notificationCenter.checkPermission();
if(authStatus != 0) { // Permission denied
$("#noti_on_page").click();
options.save();
}
});
}
} catch(boom) {
$("#noti_on_page").click();
options.save();
}
}
});
options.load();
updatePredictedHitsCount();
$('table.timelines input, table.timelines select')
.keyup(updatePredictedHitsCount)
.blur(updatePredictedHitsCount)
.click(updatePredictedHitsCount)
.change(updatePredictedHitsCount);
$("input[name='microblogging_service'],label[for='service_twitter'],label[for='service_identica']").mousedown(function(e) {
var el = $(e.target);
if(el.is('label')) {
el = $('#' + el.attr('for'));
}
if(!el.is(':checked')) {
var proceed = confirm("This will reset any custom API URL configuration. Proceed?");
if(proceed) {
el.click();
var sameSigningEl = $("input[name='same_signing_urls']");
var baseUrlEl = $("input[name='base_url']");
var baseOauthUrlEl = $("input[name='base_oauth_url']");
if(el.val() == 'twitter') {
baseUrlEl.val('http://api.twitter.com/1/');
baseOauthUrlEl.val('https://twitter.com/oauth/');
} else if(el.val() == 'identica') {
baseUrlEl.val('http://identi.ca/api/');
baseOauthUrlEl.val('https://identi.ca/api/oauth/');
}
baseUrlEl.blur();
baseOauthUrlEl.blur();
if(!sameSigningEl.is(':checked')) {
sameSigningEl.attr('checked', true).click().attr('checked', true);
}
}
}
return true;
});
$("#nerds_link").click(function() {
var $canvas = $("#nerds");
$canvas.toggle();
if($canvas.is(":visible")) {
var points = chrome.extension.getBackgroundPage().TweetManager.instance.apiHitsStates;
Math.generateTendencyGraph($canvas[0], points, resetDateObj.getTime());
}
});
});
function updatePredictedHitsCount() {
var totalHits = 0;
var unifiedVisible = $('input[name="unified_visible"]').is(':checked');
TimelineTemplate.eachTimelineTemplate(function(template) {
if(template.id == TimelineTemplate.UNIFIED) {
return true;
}
var inputUnifiedEl = $('input[name="' + template.id + '_include_unified"]');
if(!unifiedVisible) {
inputUnifiedEl.attr('disabled', 'disabled');
} else {
inputUnifiedEl.removeAttr('disabled');
}
if(template.id == TimelineTemplate.SEARCH) {
return true;
}
var inputVisibleEl = $('input[name="' + template.id + '_visible"]');
if(!inputVisibleEl.is(':checked') && !(unifiedVisible && inputUnifiedEl.is(':checked'))) {
return true;
}
var inputRefreshEl = $('input[name="' + template.id + '_refresh_interval"]');
var intVal = parseInt(inputRefreshEl.val());
var timelineHits = (60 * 60) / intVal;
var timelineCount = 1;
var userData = template.getUserData();
if(userData && userData.length > 0) {
timelineCount = userData.length;
}
totalHits += timelineHits * timelineCount;
});
totalHits += (60 * 60) / parseInt($('input[name="blockedusers_refresh_interval"]').val());
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 id="restart_notice">
However, some of your changes require the extension to be restarted. Would you like to do it now?<br>
(This will reset your unread tweets count.)
<br>
<input type="button" onclick="options.confirmRestart();" value="Yes">
<input type="button" onclick="options.denyRestart();" value="No">
</div>
</div>
<div id="main_area">
<p>
Remaining Twitter API Hits: <span class="twitter_hits_left"></span><br>
Rate Limit Reset: <span class="twitter_hits_reset"></span>
<a id="nerds_link" href="#">API Hits stats (for nerds)</a>
<canvas id="nerds" width="650" height="500" style="display: none;"></canvas>
</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>
<option value="both">Both names</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>
<option value="css/darkness-theme/jquery-ui-1.7.2.custom.css,css/darkness.css">Darkness</option>
</select><br>
<label for="font_size">Font Size:</label>
<select name="font_size">
<option value="0.8em">Small</option>
<option value="1.0em">Normal</option>
<option value="1.2em">Large</option>
<option value="1.4em">Extra Large</option>
</select><br>
<label for="font_family">Font Family:</label>
<input type="text" style="width: 20em"; name="font_family" validator="required"><br>
<label for="hover_timeout">Hover to read time (ms):</label>
<input type="text" name="hover_timeout" validator="required,number,positive"><br>
<label for="show_expanded_urls">Expand shortened URLs:</label>
<input type="checkbox" id="show_expanded_urls" name="show_expanded_urls" /><br>
<label for="reply_all">Reply to all mentioned:</label>
<input type="checkbox" style="margin-bottom: 7px;" id="reply_all" name="reply_all" />
<br />
<label>Icon color:</label>
<canvas name="idle_color" width="19" height="19" class="color_selector" must_restart></canvas><br/>
<label for="tweets_color_only_unified">Colors only in unified:</label>
<input type="checkbox" name="tweets_color_only_unified" /><br/>
<table class="tweet_color">
<tr>
<th></th>
<th>Home</th>
<th>Mentions</th>
<th>DMs</th>
<th>Lists</th>
<th>Favorites</th>
<th>Search</th>
<tr>
<td class="label">Tweet color:</td>
<td>
<div class="color_selector checkerboard"></div>
<div name="home_tweets_color" class="color_selector"></div>
</td>
<td>
<div class="color_selector checkerboard"></div>
<div name="mentions_tweets_color" class="color_selector"></div>
</td>
<td>
<div class="color_selector checkerboard"></div>
<div name="dms_tweets_color" class="color_selector"></div>
</td>
<td>
<div class="color_selector checkerboard"></div>
<div name="lists_tweets_color" class="color_selector"></div>
</td>
<td>
<div class="color_selector checkerboard"></div>
<div name="favorites_tweets_color" class="color_selector"></div>
</td>
<td>
<div class="color_selector checkerboard"></div>
<div name="search_tweets_color" class="color_selector"></div>
</td>
</tr>
</table><br>
<input type="button" value="Reset Popup Size" onclick="Persistence.popupSize().remove();">
</fieldset>
<fieldset>
<legend>Notifications</legend>
<table class="notifications">
<tr>
<th></th>
<th>Tweet Notification</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>
<tr>
<td class="label">Search:</td>
<td><input type="checkbox" name="search_on_page"></td>
<td><input type="checkbox" name="search_icon"></td>
<td><canvas name="search_color" width="19" height="19" class="color_selector"></canvas></td>
</tr>
</table><br>
<label for="tweets_notification_style">Notification Style:</label>
<input type="radio" name="tweets_notification_style" value="on_page" id="noti_on_page"> <label for="noti_on_page" class="radio_opt">Notify on Page</label>
<input type="radio" name="tweets_notification_style" value="desktop" id="noti_desktop"> <label for="noti_desktop" class="radio_opt">Desktop Notifications</label><br>
<label for="notification_fade_timeout">Notification Timeout (s):</label>
<input type="text" name="notification_fade_timeout" validator="required,number,positive" converter="RefreshInterval"><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>
<label for="share_include_title">Include page title (sharing):</label>
<input type="checkbox" name="share_include_title"><br>
</fieldset>
<fieldset>
<legend>Timelines</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>
<table class="timelines">
<tr>
<th></th>
<th>Visible</th>
<th>Refresh Interval (s)</th>
<th>Include in unified timeline</th>
<th>Tabs Count</th>
<tr>
<td class="label">Unified Timeline:</td>
<td><input type="checkbox" name="unified_visible" validator="unifiedValidator"></td>
<td>-</td>
<td>-</td>
<td>1</td>
</tr>
<tr>
<td class="label">Home:</td>
<td><input type="checkbox" name="home_visible"></td>
<td><input type="text" name="home_refresh_interval" validator="required,number,minRefresh" converter="RefreshInterval"></td>
<td><input type="checkbox" name="home_include_unified"></td>
<td>1</td>
</tr>
<tr>
<td class="label">Mentions:</td>
<td><input type="checkbox" name="mentions_visible"></td>
<td><input type="text" name="mentions_refresh_interval" validator="required,number,minRefresh" converter="RefreshInterval"></td>
<td><input type="checkbox" name="mentions_include_unified"></td>
<td>1</td>
</tr>
<tr>
<td class="label">DM:</td>
<td><input type="checkbox" name="dms_visible"></td>
<td><input type="text" name="dms_refresh_interval" validator="required,number,minRefresh" converter="RefreshInterval"></td>
<td><input type="checkbox" name="dms_include_unified"></td>
<td>1</td>
</tr>
<tr>
<td class="label">Lists:</td>
<td><input type="checkbox" name="lists_visible"></td>
<td><input type="text" name="lists_refresh_interval" validator="required,number,minRefresh" converter="RefreshInterval"></td>
<td><input type="checkbox" name="lists_include_unified"></td>
<td><script>document.write(TimelineTemplate.getTemplate(TimelineTemplate.LISTS).getUserData().length);</script></td>
</tr>
<tr>
<td class="label">Search:</td>
<td><input type="checkbox" name="search_visible"></td>
<td><input type="text" name="search_refresh_interval" validator="required,number,minRefresh" converter="RefreshInterval"></td>
<td><input type="checkbox" name="search_include_unified"></td>
<td><script>document.write(TimelineTemplate.getTemplate(TimelineTemplate.SEARCH).getUserData().length);</script></td>
</tr>
<tr>
<td class="label">Favorites:</td>
<td><input type="checkbox" name="favorites_visible"></td>
<td><input type="text" name="favorites_refresh_interval" validator="required,number,minRefresh" converter="RefreshInterval"></td>
<td><input type="checkbox" name="favorites_include_unified"></td>
<td>1</td>
</tr>
<tr>
<td class="label">Blocked Users:</td>
<td>-</td>
<td><input type="text" name="blockedusers_refresh_interval" validator="required,number,minRefresh" converter="RefreshInterval"></td>
<td>-</td>
<td>-</td>
</tr>
</table>
<p class="notice" style="color: black;">
* Hey, now you can use the right-click context menu to change most of this settings directly into the popup window. Just get
out of here! :)
</p>
</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" must_restart><br>
<label for="max_cached_tweets">Max Shown Tweets:</label>
<input type="text" name="max_cached_tweets" validator="required,number,positive" must_restart><br>
</fieldset>
<fieldset>
<legend>Microblogging Service</legend>
<input type="radio" name="microblogging_service" value="twitter" id="service_twitter" must_restart> <label for="service_twitter" class="radio_opt">Twitter</label>
<input type="radio" name="microblogging_service" value="identica" id="service_identica" must_restart> <label for="service_identica" class="radio_opt">identi.ca</label>
</fieldset>
<fieldset>
<legend>Advanced</legend>
<label for="request_timeout">Request Timeout (ms):</label>
<input type="text" name="request_timeout" validator="required,number,positive" must_restart><br>
<label for="base_url">Twitter's API URL:</label>
<input type="text" name="base_url" style="width: 300px;" validator="required,url" must_restart><br>
<label for="base_oauth_url">OAuth URL:</label>
<input type="text" name="base_oauth_url" style="width: 300px;" validator="required,url" must_restart><br>
<label for="same_signing_urls">Same signing URLs:</label>
<input type="checkbox" name="same_signing_urls"><br>
<label for="base_signing_url">API Signing URL:</label>
<input type="text" name="base_signing_url" style="width: 300px;" validator="required,url" must_restart><br>
<label for="base_oauth_signing_url">OAuth Signing URL:</label>
<input type="text" name="base_oauth_signing_url" style="width: 300px;" validator="required,url" must_restart><br>
<label for="base_search_url">Search API URL:</label>
<input type="text" name="base_search_url" style="width: 300px;" validator="required,url" must_restart><br>
</fieldset>
<br>
<div id="buttons_area">
<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>
</div>
</body>
</html>