-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
864 lines (733 loc) · 29.7 KB
/
popup.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
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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
window.chrome = (function () {
return window.msBrowser ||
window.browser ||
window.chrome;
})();
var base_url = 'http://jp.inoreader.com/';
var InoReaderUrl = /inoreader\.(com|ru)(.*)\/*$/;
var b_log = chrome.extension.getBackgroundPage();
var base_link = '';
var activeTab = new Array();
chrome.tabs.query({active: true, currentWindow: true}, function(arrayOfTabs) {
activeTab = arrayOfTabs[0];
});
var urls = new Array();
if(localStorage['redirect'] == 3){
urls[0] = '#';
urls[1] = '#';
urls[2] = '#';
urls[3] = '#';
urls[4] = base_url+'simple_api/?get_user_info&AppId=1000001524&AppKey=uxILTlPQilTphfcf4xwBEspL_0EDaUZL';
}else{
urls[0] = base_url+'reader/api/0/subscription/list?AppId=1000001524&AppKey=uxILTlPQilTphfcf4xwBEspL_0EDaUZL';
urls[1] = base_url+'reader/api/0/preference/stream/list?AppId=1000001524&AppKey=uxILTlPQilTphfcf4xwBEspL_0EDaUZL';
urls[2] = base_url+'reader/api/0/tag/list?AppId=1000001524&AppKey=uxILTlPQilTphfcf4xwBEspL_0EDaUZL&';
urls[3] = base_url+'reader/api/0/unread-count?AppId=1000001524&AppKey=uxILTlPQilTphfcf4xwBEspL_0EDaUZL&';
urls[4] = base_url+'simple_api/?AppId=1000001524&AppKey=uxILTlPQilTphfcf4xwBEspL_0EDaUZL&get_user_info';
}
var result = new Array();
var doneCount = 0;
function get_info(folder){
doneCount = 0;
if(localStorage.use_ssl == 0){
base_link += 'http://';
}else{
base_link += 'http://';
}
base_link += 'jp.inoreader.com';
if(localStorage['redirect'] == 2){
find_tab(function(tab){
if(tab === null){
chrome.tabs.create({url: base_link});
}else{
chrome.tabs.update(tab.id, {url: base_link, active: true});
}
window.close();
});
}
html = '<div class="top"><div class="logo_login"><img src=\"icons/logo_r.png\"/ width=\"40px\"></div> <div class="login_text">Loading ...</div><div class="loading_img"><img src=\"icons/load_blue_16x16.gif\"/ ></div></div>';
$("#tree").html(html);
$.each(urls, function (i, url) {
if(url != '#'){
$.ajax({
url: url,
dataType: 'json',
success: function(json){
doneCount++;
result[i]= json;
if (doneCount == urls.length) {
process(folder,false);
}
},
error: function(){
if(window.devicePixelRatio >= 2) {
html = '<div class="top"><div class="logo_login"><img src=\"icons/logo_r.png\"/ width=\"40px\"></div> <div class="login_text">Please sign into your <a href="javascript://" id=\"logo_login\">Inoreader account</a></div></div>';
}else{
html = '<div class="top"><div class="logo_login"><img src=\"icons/logo.png\"/ width=\"40px\"></div> <div class="login_text">Please sign into your <a href="javascript://" id=\"logo_login\">Inoreader account</a></div></div>';
}
$("#tree").html(html);
$(".top").off('click').on('click',function() {
l('Logo','Click');
find_tab(function(tab){
if(tab === null){
chrome.tabs.create({url: base_link});
}else{
chrome.tabs.update(tab.id, {url: base_link, active: true});
}
window.close();
});
});
}
});
}else{
doneCount++;
}
});
}
function urlencode(str) {
str = (str + '').toString();
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}
function get_subscribe_info(url){
if(url == ''){
url = activeTab.url;
}
$.ajax({
url: base_url+'api/browser_extensions.php?AppId=1000001524&AppKey=uxILTlPQilTphfcf4xwBEspL_0EDaUZL&fetch_url='+urlencode(url),
dataType: 'json',
success: function(json){
draw_feed(json);
},
error: function(){
$("#add_button").html("<span class=\"icon-plus plus_button\"></span>");
$("#subscribe_links").html('<div class="info">An error occurred. Try again later.</div>');
}
});
l('Site actions','Subscribe');
}
function book_page(url){
if(url == ''){
url = activeTab.url;
}
$.ajax({
url: base_url+'reader/api/0/save-web-page?AppId=1000001524&AppKey=uxILTlPQilTphfcf4xwBEspL_0EDaUZL&url='+urlencode(url),
success: function(json){
if(json == 'Error'){
$("#save_button").html("<span class=\"icon-bookmark book_button\"></span>");
$("#subscribe_links").html('<div class="info">Sorry, we couldn\'t save this web page.</div>');
}else{
$("#save_button").html("<span class=\"icon-bookmark_full book_button_save\"></span>");
$(".save_web").off('click');
}
},
error: function(){
$("#save_button").html("<span class=\"icon-bookmark book_button\"></span>");
$("#subscribe_links").html('<div class="info">An error occurred. Try again later.</div>');
}
});
// $(".save_web").off('click').on('click',function() {
// $("#save_button").html("<img class=\"loading\" src=\"icons/load_blue_16x16.gif\"/>");
// book_page($('#feed_input').val());
// });
l('Site actions','Save as web page');
}
function add_feed(feed,url){
$('#icon_'+feed).attr("class",'');
$('#icon_'+feed).html("<img src=\"icons/load_blue_16x16.gif\"/>");
$.ajax({
url: base_url+'reader/api/0/subscription/quickadd?AppId=1000001524&AppKey=uxILTlPQilTphfcf4xwBEspL_0EDaUZL&quickadd='+url,
dataType: 'json',
success: function(json){
$('#icon_'+feed).html("");
$('#icon_'+feed).attr("class",'icon-checkmark_big add_icon');
$('#'+feed).attr("class",'added_feed');
},
error: function(){
$("#subscribe_links").html('<div>An error occurred. Try again later.</div>');
}
});
}
function draw_feed(subsc_feeds){
z = 0;
html = "";
add = 0;
if(subsc_feeds.discovered_feeds){
$.each(subsc_feeds.discovered_feeds, function (key, val) {
encoded_link = urlencode(val.link);
guid = $.guid++;
if(val.subscribed == 0){
html += '<div class="add_feed" id="'+guid+'" data="'+encoded_link+'"><div class="title" tabindex="'+guid+'"><div class="name">'+val.title+'</div><div class="link" title="'+val.link+'">'+val.link+'</div></div><div class="center_icon"><span id="icon_'+guid+'" class="icon-plus add_icon" ></span></div><div class="clear-both"></div></div>';
add++;
cur_guid = guid;
cur_link = encoded_link
}else{
html += '<div class="added_feed" id="'+guid+'" data="'+encoded_link+'"><div class="title" tabindex="'+guid+'"><div class="name">'+val.title+'</div><div class="link" title="'+val.link+'">'+val.link+'</div></div><div class="center_icon"><span id="icon_'+guid+'" class="icon-checkmark_big add_icon" ></span></div><div class="clear-both"></div></div>';
}
z++;
});
html += '<div class="clear-both"></div>';
}
if(subsc_feeds && z==0 ){
html = '<div class="info">No feeds found</div>';
}
if(add == 1){
add_feed(cur_guid,cur_link);
}
$(".div_button").html("<span class=\"icon-plus plus_button\"></span>");
$("#subscribe_links").html(html);
$(".add_feed").off('click').on('click',function() {
add_feed($(this).attr('id'),$(this).attr('data'));
});
window.scrollTo(0, 0);
if($(document).height() > 600){
scroll_workaround = false;
}
$('#feed_input').off('click').on('click',function() {
$(this).select();
});
$(".plus_button").off('click').on('click',function() {
$("#add_button").html("<img class=\"loading\" src=\"icons/load_blue_16x16.gif\"/>");
get_subscribe_info($('#feed_input').val());
});
$(".save_web").off('click').on('click',function() {
$("#save_button").html("<img class=\"loading\" src=\"icons/load_blue_16x16.gif\"/>");
book_page($('#feed_input').val());
});
}
function process(folder,subsc_feeds){
start = 0;
guid = $.guid++;
if(window.devicePixelRatio >= 2) {
html = '<div class="top"><div class="logo"><img src=\"icons/logo_r.png\"/ width=\"40px\"></div><input id="feed_searcher" tabindex="'+guid+'" type="text" value="" placeholder="Search my Inoreader"/> <span class="icon-loupe_big icon_search"></span></div>';
}else{
html = '<div class="top"><div class="logo"><img src=\"icons/logo.png\"/ width=\"40px\"></div><input id="feed_searcher" tabindex="'+guid+'" type="text" value="" placeholder="Search my Inoreader"/> <span class="icon-loupe_big icon_search"></span></div>';
}
ss = ' value="'+activeTab.url+'" placeholder="placeholder"';
tab_url = activeTab.url;
if(tab_url == "chrome://extensions/"){
ss = ' value="" placeholder="Enter URL here..."';
}
act_title = activeTab.title;
if(act_title.length > 40 ){
act_title = act_title.substring(0, 35)+'...';
}
if(tab_url.indexOf("https") != -1 || tab_url.indexOf("http") != -1){
html += '<div class="feed_add"><div class="txt">Add feeds</div><input id="feed_input" tabindex="'+$.guid++ +'" type="text" '+ss+' /> <span class="div_button"><span id="add_button"><span class="icon-plus plus_button"></span></span><div class="clear-both"></div><div class="save_web"><div class="txt_1">Save this page</div><div class="title" tabindex="'+ $.guid++ +'">'+act_title+'</div> <span class="div_button"><span id="save_button"><span class="icon-bookmark book_button"></span></span></span><div class="clear-both"></div></div></div>';
}else{
html += '<div class="feed_add"><div class="txt">Add feeds</div><input id="feed_input" tabindex="'+$.guid++ +'" type="text" '+ss+' /> <span class="div_button"><span class="icon-plus plus_button"></span></div>';
}
html += '<div id="subscribe_links"></div>';
// Show only add bar
if(localStorage['redirect'] == 3){
$("#tree").html(html);
$(".logo").off('click').on('click',function() {
l('Logo','Click');
var feed = $(this).attr('data');
find_tab(function(tab){
if(tab === null){
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link});
}else{
chrome.tabs.update(tab.id, {url: base_link, active: true});
}
window.close();
});
});
$(".icon_search").off('click').on('click',function() {
if($('#feed_searcher').val() == ''){
$('#feed_searcher').focus().effect('highlight',{color: 'red'});
return true;
}
l('Search','Executed with mouse click');
find_tab(function(tab){
if(tab === null){
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link+'/search/'+$('#feed_searcher').val()});
}else{
chrome.tabs.update(tab.id, {url: base_link+'/search/'+$('#feed_searcher').val(), active: true});
}
window.close();
});
});
$("#feed_searcher").keyup(function(event){
if(event.keyCode == 13){
if($('#feed_searcher').val() == ''){
$('#feed_searcher').focus().effect('highlight',{color: 'red'});
return true;
}
l('Search','Executed with Return');
find_tab(function(tab){
if(tab === null){
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link+'/search/'+$('#feed_searcher').val()});
}else{
chrome.tabs.update(tab.id, {url: base_link+'/search/'+$('#feed_searcher').val(), active: true});
}
window.close();
});
}
});
$(".but_folder").off('click').on('click',function() {
if(folder == null){
get_info($(this).attr('id'));
}else{
get_info(null);
}
});
$('#feed_input').off('click').on('click',function() {
$(this).select();
});
$(".plus_button").off('click').on('click',function() {
$("#add_button").html("<img class=\"loading\" src=\"icons/load_blue_16x16.gif\"/>");
get_subscribe_info($('#feed_input').val());
});
$(".save_web").off('click').on('click',function() {
$("#save_button").html("<img class=\"loading\" src=\"icons/load_blue_16x16.gif\"/>");
book_page($('#feed_input').val());
});
$(".inoreader_link").off('click').on('click',function() {
find_tab(function(tab){
if(tab === null){
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link});
}else{
chrome.tabs.update(tab.id, {url: base_link, active: true});
}
window.close();
});
});
$(".feed, .folder, #feed_input, .title").focusin(function () {
$(this).addClass('feed_focused');
});
$(".feed, .folder, #feed_input, .title").focusout(function () {
$(this).removeClass('feed_focused');
});
return true;
}
articles = '';
articles += '<div id="new_articles">';
articles += '<div class="new_articles_top">New articles:</div>';
folder_cnt = new Array();
folders = new Array();
sorts = new Array();
subscriptions = result[0]['subscriptions'];
unreadcounts = new Array();
css_folder = '';
total_cnt = 0;
$.each(result[3]['unreadcounts'], function (key, val) {
if(val.count == 0){
unreadcounts[val.id] = 0;
}else
if(val.count > 1000 ){
unreadcounts[val.id] = val.count;
}else{
unreadcounts[val.id] = val.count;
}
});
$.each(result[2]['tags'], function (key, val) {
start++;
if(start > 3){
value=new Object();
value.type = 'folder';
value.id = val.id;
value.sortid = val.sortid;
value.title = val.id.replace('user/'+result[4]['id']+'/label/', '');
value.categories = new Array();
folders.push(value);
}
});
if(result[4]['tree_ordering'] == 0){
subscriptions.sort(function(a, b) {
var x = a.title.toLowerCase(), y = b.title.toLowerCase();
return x < y ? -1 : x > y ? 1 : 0;
});
folders.sort(function(a, b) {
var x = a.title.toLowerCase(), y = b.title.toLowerCase();
return x > y ? -1 : x < y ? 1 : 0;
});
$.each(folders, function (key, val) {
subscriptions.unshift(val);
});
$.each(subscriptions, function (key, val) {
if(val.categories.length == 0){
if(val.type == 'folder'){
guid = $.guid++;
total_cnt++;
child_folders = '';
total_child_folders = 0;
if(val.categories){
$.each(subscriptions, function (_key, _val) {
$.each(_val.categories, function (k, v) {
if(v.id == val.id && unreadcounts[_val.id] > 0){
total_child_folders++;
f_guid = $.guid++;
if((localStorage['original_fav'] == undefined || localStorage['original_fav'] == 1) && _val.iconUrl.indexOf("feed.png") == -1 && _val.iconUrl != ''){
child_folders += '<div class="feed child_feed" data="'+_val.id+'" tabindex="'+f_guid+'" id="all_'+f_guid+'"><span class="icon16 feed_icon" data="'+_val.id+'"><img class="i_icon16" src="'+_val.iconUrl+'" border="0" alt="" title=""/></span><span class="feed_title feed_title_child" data="'+_val.id+'">'+_val.title+'</span><span title="Mark as reed" class="unread" data="'+_val.id+'" id="un_'+f_guid+'" f_data="'+guid+'">'+unreadcounts[_val.id]+'</span></div>';
}else{
child_folders += '<div class="feed child_feed" data="'+_val.id+'" tabindex="'+f_guid+'" id="all_'+f_guid+'"><span class="icon-rss_negative icon16 feed_icon" data="'+_val.id+'"></span><span class="feed_title feed_title_child" data="'+_val.id+'">'+_val.title+'</span><span title="Mark as reed" class="unread" data="'+_val.id+'" id="un_'+f_guid+'" f_data="'+guid+'">'+unreadcounts[_val.id]+'</span></div>';
}
}
});
});
}
if(unreadcounts[val.id]){
folder_cnt[guid] = unreadcounts[val.id];
if(total_child_folders > 0){
articles += '<div class="folder" tabindex="'+guid+'" id="all_'+guid+'"><span id="icon_'+guid+'" data="'+guid+'" class="icon-arrow_right_small icon16 folder_i"></span><span data="'+val.title+'" class="feed_title_1 folder_title">'+val.title+'</span><span class="unread" id="un_'+guid+'" data="'+val.id+'">'+unreadcounts[val.id]+'</span></div>';
}else{
articles += '<div class="folder" tabindex="'+guid+'" id="all_'+guid+'"><span data="'+val.id+'" id="icon_'+guid+'" class="icon-tag_full icon16 folder_title"></span><span data="'+val.title+'" class="feed_title_1 folder_title">'+val.title+'</span><span class="unread" id="un_'+guid+'" data="'+val.id+'">'+unreadcounts[val.id]+'</span></div>';
}
articles += '<div class="child" id="col_'+guid+'">';
articles += child_folders;
articles += '</div>';
}
}else{
if(unreadcounts[val.id] > 0){
total_cnt++;
guid = $.guid++;
if((localStorage['original_fav'] == undefined || localStorage['original_fav'] == 1) && val.iconUrl.indexOf("feed.png") == -1 && val.iconUrl != ''){
articles += '<div class="feed" data="'+val.id+'" tabindex="'+guid+'" id="all_'+guid+'"><span class="icon16 feed_icon" data="'+val.id+'"><img class="i_icon16" src="'+val.iconUrl+'" border="0" alt="" title=""/></span><span class="feed_title" data="'+val.id+'">'+val.title+'</span><span title="Mark as reed" class="unread" data="'+val.id+'" id="un_'+guid+'" f_data="">'+unreadcounts[val.id]+'</span></div>';
}else{
articles += '<div class="feed" data="'+val.id+'" tabindex="'+guid+'" id="all_'+guid+'"><span class="icon-rss_negative icon16 feed_icon" data="'+val.id+'"></span><span class="feed_title" data="'+val.id+'">'+val.title+'</span><span title="Mark as reed" class="unread" data="'+val.id+'" id="un_'+guid+'" f_data="">'+unreadcounts[val.id]+'</span></div>';
}
}
}
}
});
}else{
sort_subscriptions = new Array();
$.each(subscriptions, function (key, val) {
sort_subscriptions[val.sortid] = val;
});
$.each(folders, function (key, val) {
sort_subscriptions[val.sortid] = val;
});
i = 0;
$.each(result[1]['streamprefs'], function (key, val) {
sorts[key] = new Array();
if(i>0){
to = val[1].value.length/8;
f = 0;
for (z=0;z<to;z++){
sorts[key][z] = val[1].value.substring(f,(f+8));
f = f + 8;
}
}else{
to = val[0].value.length/8;
f = 0;
for (z=0;z<to;z++){
sorts[key][z] = val[0].value.substring(f,(f+8));
f = f + 8;
}
}
i++;
});
root = 'user/'+result[4]['id']+'/state/com.google/root';
$.each(sorts[root], function (key, v) {
val = sort_subscriptions[v];
if(val.type == 'folder'){
if(unreadcounts[val.id] > 0){
guid = $.guid++;
total_cnt++;
child_folders = '';
total_child_folders = 0;
if(sorts[val.id]){
$.each(sorts[val.id], function (_key, _v) {
_val = sort_subscriptions[_v];
if(unreadcounts[_val.id] > 0){
total_child_folders++;
f_guid = $.guid++;
if((localStorage['original_fav'] == undefined || localStorage['original_fav'] == 1) && _val.iconUrl.indexOf("feed.png") == -1 && _val.iconUrl != ''){
child_folders += '<div class="feed child_feed" data="'+_val.id+'" tabindex="'+f_guid+'" id="all_'+f_guid+'"><span class="icon16 feed_icon" data="'+_val.id+'"><img class="i_icon16" src="'+_val.iconUrl+'" border="0" alt="" title=""/></span><span class="feed_title feed_title_child" data="'+_val.id+'">'+_val.title+'</span><span title="Mark as reed" class="unread" data="'+_val.id+'" id="un_'+f_guid+'" f_data="'+guid+'">'+unreadcounts[_val.id]+'</span></div>';
}else{
child_folders += '<div class="feed child_feed" data="'+_val.id+'" tabindex="'+f_guid+'" id="all_'+f_guid+'"><span class="icon-rss_negative icon16 feed_icon" data="'+_val.id+'"></span><span class="feed_title feed_title_child" data="'+_val.id+'">'+_val.title+'</span><span title="Mark as reed" class="unread" data="'+_val.id+'" id="un_'+f_guid+'" f_data="'+guid+'">'+unreadcounts[_val.id]+'</span></div>';
}
}
});
}
if(unreadcounts[val.id]){
folder_cnt[guid] = unreadcounts[val.id];
if(total_child_folders > 0){
articles += '<div class="folder" tabindex="'+guid+'" id="all_'+guid+'"><span id="icon_'+guid+'" data="'+guid+'" class="icon-arrow_right_small icon16 folder_i"></span><span data="'+val.title+'" class="feed_title_1 folder_title">'+val.title+'</span><span class="unread" id="un_'+guid+'" data="'+val.id+'">'+unreadcounts[val.id]+'</span></div>';
}else{
articles += '<div class="folder" tabindex="'+guid+'" id="all_'+guid+'"><span data="'+val.id+'" id="icon_'+guid+'" class="icon-tag_full icon16 folder_title"></span><span data="'+val.title+'" class="feed_title_1 folder_title">'+val.title+'</span><span class="unread" id="un_'+guid+'" data="'+val.id+'">'+unreadcounts[val.id]+'</span></div>';
}
articles += '<div class="child" id="col_'+guid+'">';
articles += child_folders;
articles += '</div>';
}
}
}else{
if(unreadcounts[val.id] > 0){
total_cnt++;
guid = $.guid++;
if((localStorage['original_fav'] == undefined || localStorage['original_fav'] == 1) && val.iconUrl.indexOf("feed.png") == -1 && val.iconUrl != ''){
articles += '<div class="feed" tabindex="'+guid+'" data="'+val.id+'" id="all_'+guid+'"><span class="icon16 feed_icon" data="'+val.id+'"><img src="'+val.iconUrl+'" class="i_icon16" border="0" alt="" title=""/></span><span class="feed_title" data="'+val.id+'">'+val.title+'</span><span title="Mark as reed" class="unread" data="'+val.id+'" id="un_'+guid+'" f_data="">'+unreadcounts[val.id]+'</span></div>';
}else{
articles += '<div class="feed" tabindex="'+guid+'" data="'+val.id+'" id="all_'+guid+'"><span class="icon-rss_negative icon16 feed_icon" data="'+val.id+'"></span><span class="feed_title" data="'+val.id+'">'+val.title+'</span><span title="Mark as reed" class="unread" data="'+val.id+'" id="un_'+guid+'" f_data="">'+unreadcounts[val.id]+'</span></div>';
}
}
}
});
}
if(total_cnt == 0){
articles = '<div id="new_articles">';
articles = '<div class="new_articles_top">No new articles</div>';
}
articles += '</div>';
html += articles;
$("#tree").html(html);
$(".feed_icon").off('click').on('click',function() {
l('Tree actions','Open feed');
var feed = $(this).attr('data');
feed = feed.replace(/^feed\//,'');
find_tab(function(tab){
if(tab === null){
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link+'/feed/'+encodeURIComponent(feed)});
}else{
chrome.tabs.update(tab.id, {url: base_link+'/feed/'+encodeURIComponent(feed), active: true});
}
window.close();
});
});
$(".feed_title").off('click').on('click',function() {
l('Tree actions','Open feed');
var feed = $(this).attr('data');
feed = feed.replace(/^feed\//,'');
find_tab(function(tab){
if(tab === null){
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link+'/feed/'+encodeURIComponent(feed)});
}else{
chrome.tabs.update(tab.id, {url: base_link+'/feed/'+encodeURIComponent(feed), active: true});
}
window.close();
});
});
var scroll_workaround = true;
if($(document).height() > 600){
scroll_workaround = false;
}
$(".unread").off('click').on('click',function(){
id = $(this).attr('id');
cnt = unread_tab[id];
all_id = id.replace('un_', '');
data = $(this).attr('data');
f_data=$(this).attr('f_data');
$.ajax({
url: base_url+'reader/api/0/mark-all-as-read?AppId=1000001524&AppKey=uxILTlPQilTphfcf4xwBEspL_0EDaUZL&s='+urlencode(data),
success: function(){
if(folder_cnt[f_data]){
folder_cnt[f_data] = folder_cnt[f_data] - cnt;
if(folder_cnt[f_data] < 1){
$('#all_'+f_data).remove();
}else{
$('#un_'+f_data).html(folder_cnt[f_data]);
}
}
chrome.browserAction.getBadgeText({}, function(cur_text) {
var n = parseInt(cur_text) - parseInt(cnt);
chrome.browserAction.setBadgeText({text: n+''});
chrome.browserAction.setTitle({title: 'You have ' + n + ' unread articles in Inoreader'});
});
$('#all_'+all_id).remove();
$('#col_'+all_id).remove();
h = $('#tree').height();
if(h < 600 && !scroll_workaround){
b = 600 - $(document).height();
$('#bootom').height(b);
$('#bootom').show(b);
scroll_workaround = true;
}
},
error: function(){
}
});
l('Tree actions','Mark as read');
});
var unread_tab = new Array();
$(".unread").mouseover(function(){
feed = $(this).attr('id');
unread_tab[feed] = $('#'+feed).html();
$('#'+feed).html('');
$('#'+feed).attr("class",'unread icon-checkmark_big checked_icon');
});
$(".unread").mouseout(function() {
feed = $(this).attr('id');
$('#'+feed).attr("class",'unread');
$('#'+feed).html(unread_tab[feed]);
});
$(".folder_i").off('click').on('click',function() {
folder_id = $(this).attr('data');
if($('#icon_'+folder_id).attr('class') == 'icon-arrow_right_small icon16 folder_i'){
$('#icon_'+folder_id).attr('class','icon-arrow_down_small icon16 folder_i');
$('#col_'+folder_id).show();
}else{
$('#icon_'+folder_id).attr('class','icon-arrow_right_small icon16 folder_i');
$('#col_'+folder_id).hide();
}
if($(document).height() > 600){
scroll_workaround = false;
}
l('Tree actions','Expand/Collapse folder');
});
$(".folder_title").off('click').on('click',function() {
l('Tree actions','Open folder');
var feed = $(this).attr('data');
find_tab(function(tab){
if(tab === null){
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link+'/folder/'+encodeURIComponent(feed)});
}else{
chrome.tabs.update(tab.id, {url: base_link+'/folder/'+encodeURIComponent(feed), active: true});
}
window.close();
});
});
$(".logo").off('click').on('click',function() {
l('Logo','Click');
var feed = $(this).attr('data');
find_tab(function(tab){
if(tab === null){
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link});
}else{
chrome.tabs.update(tab.id, {url: base_link, active: true});
}
window.close();
});
});
$(".icon_search").off('click').on('click',function() {
if($('#feed_searcher').val() == ''){
$('#feed_searcher').focus().effect('highlight',{color: 'red'});
return true;
}
l('Search','Executed with mouse click');
find_tab(function(tab){
if(tab === null){
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link+'/search/'+$('#feed_searcher').val()});
}else{
chrome.tabs.update(tab.id, {url: base_link+'/search/'+$('#feed_searcher').val(), active: true});
}
window.close();
});
});
$("#feed_searcher").keyup(function(event){
if(event.keyCode == 13){
if($('#feed_searcher').val() == ''){
$('#feed_searcher').focus().effect('highlight',{color: 'red'});
return true;
}
l('Search','Executed with Return');
find_tab(function(tab){
if(tab === null){
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link+'/search/'+$('#feed_searcher').val()});
}else{
chrome.tabs.update(tab.id, {url: base_link+'/search/'+$('#feed_searcher').val(), active: true});
}
window.close();
});
}
});
$(".but_folder").off('click').on('click',function() {
if(folder == null){
get_info($(this).attr('id'));
}else{
get_info(null);
}
});
$('#feed_input').off('click').on('click',function() {
$(this).select();
});
$(".plus_button").off('click').on('click',function() {
$("#add_button").html("<img class=\"loading\" src=\"icons/load_blue_16x16.gif\"/>");
get_subscribe_info($('#feed_input').val());
});
$(".save_web").off('click').on('click',function() {
$("#save_button").html("<img class=\"loading\" src=\"icons/load_blue_16x16.gif\"/>");
book_page($('#feed_input').val());
});
$(".inoreader_link").off('click').on('click',function() {
l('Inoreader Link (Unauthorized)','Click');
find_tab(function(tab){
if(tab === null){
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link});
}else{
chrome.tabs.update(tab.id, {url: base_link, active: true});
}
window.close();
});
});
$(".feed").keydown(function(event){
if(event.keyCode == 13) {
l('Tree actions','Open feed with keyboard');
var feed = $(this).attr('data');
feed = feed.replace(/^feed\//, '');
find_tab(function (tab) {
if (tab === null) {
chrome.extension.getBackgroundPage().console.log('create');
chrome.tabs.create({url: base_link + '/feed/' + encodeURIComponent(feed)});
} else {
chrome.tabs.update(tab.id, {url: base_link + '/feed/' + encodeURIComponent(feed), active: true});
}
window.close();
});
}
});
$(".feed, .folder, #feed_input, .title").focusin(function () {
$(this).addClass('feed_focused');
});
$(".feed, .folder, #feed_input, .title").focusout(function () {
$(this).removeClass('feed_focused');
});
$(".folder").keydown(function(event) {
l('Tree actions','Expand/Collapse folder with keyboard');
if(event.keyCode == 39) { // right arrow - expand
folder_id = $(this).find('span.folder_i').attr('data');
if($('#icon_' + folder_id).attr('class') == 'icon-arrow_right_small icon16 folder_i') {
$('#icon_' + folder_id).attr('class', 'icon-arrow_down_small icon16 folder_i');
$('#col_' + folder_id).show();
}
if($(document).height() > 600){
scroll_workaround = false;
}
}else if(event.keyCode == 37){ // left arrow - collapse
folder_id = $(this).find('span.folder_i').attr('data');
if($('#icon_' + folder_id).attr('class') == 'icon-arrow_down_small icon16 folder_i'){
$('#icon_' + folder_id).attr('class', 'icon-arrow_right_small icon16 folder_i');
$('#col_' + folder_id).hide();
}
if($(document).height() > 600){
scroll_workaround = false;
}
}
});
}
function find_tab(callback_fn){
var current_id = null;
chrome.windows.getCurrent(function(win){
current_id = win.id;
});
chrome.windows.getAll({populate: true}, function(w){
for(var i in w){
var TabsCount = w[i].tabs.length;
while(TabsCount){
if(InoReaderUrl.exec(w[i].tabs[TabsCount-1].url) && w[i].tabs[TabsCount-1].url.indexOf('forum') === -1 && w[i].tabs[TabsCount-1].url.indexOf('wiki') === -1 && w[i].id == current_id){
chrome.extension.getBackgroundPage().console.log(w[i].tabs[TabsCount-1]);
callback_fn(w[i].tabs[TabsCount-1]);
return;
}
--TabsCount
}
}
callback_fn(null);
});
}
get_info(null);
function l(category,action,label,value){
return;
}