/
twicli.js
1567 lines (1546 loc) · 62.6 KB
/
twicli.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
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// common
function $(id) { return document.getElementById(id); }
// 文字参照をデコード
function charRef(s) {
var ele = document.createElement("div");
ele.innerHTML = s;
return ele.firstChild.nodeValue;
}
// フォームをシリアライズ
function serializeForm(f) {
var url = '';
for (var e = 0; e < f.elements.length; e++) {
var input = f.elements[e];
if (input.name && input.value)
url += (url == '' ? '?' : '&') + input.name + "=" + encodeURIComponent(input.value);
}
return url;
}
// OAuth用formに引数を設定(Twitter APIのみ)
function setupOAuthArgs(args) {
var api_args = $("api_args");
api_args.innerHTML = "";
if (args) {
args = args.split("&");
for (var i = 0; i < args.length; i++) {
var v = args[i].split("=");
var el = document.createElement("input");
el.type = "hidden";
el.name = v[0];
el.value = decodeURIComponent(v[1]);
api_args.appendChild(el);
}
}
}
function setupOAuthURL(url, post) {
if (url.indexOf(twitterAPI) != 0) return url;
if (!post && ratelimit_reset_time && new Date < ratelimit_reset_time) return false;
url = url.split("?");
setupOAuthArgs(url[1]);
document.request.method = post ? 'POST' : 'GET';
document.etc.URL.value = url[0];
consumer.signForm(document.request, document.etc);
return document.etc.URL.value + (!post ? serializeForm(document.request) : '');
}
// クロスドメインJavaScript呼び出し(Twitter APIはOAuth認証)
function loadXDomainScript(url, ele) {
url = setupOAuthURL(url);
if (!url) return ele;
if (ele && ele.parentNode)
ele.parentNode.removeChild(ele);
ele = document.createElement("script");
ele.src = url;
ele.type = "text/javascript";
document.body.appendChild(ele);
return ele;
}
// クロスドメインJavaScript呼び出し(エラー処理+リトライ付き, Twitter APIはOAuth認証)
var xds = {
load: function(url, callback, onerror, retry, callback_key) {
var url2 = setupOAuthURL(url + (url.indexOf('?')<0?'?':'&') +
(callback_key?callback_key:'callback') + '=cb');
if (!url2) return null;
loading(true);
var ifr = document.createElement("iframe");
ifr.style.display = "none";
document.body.appendChild(ifr);
var d = ifr.contentWindow.document;
var cnt = 0; // 二重onload防止
ifr[ifr.readyState/*IE*/ ? "onreadystatechange" : "onload"] = function() {
if (this.readyState && this.readyState != 'complete' || cnt++) return;
if (d.x) {
if (callback) callback.apply(this, d.x);
} else if (retry && retry > 1) {
loading(true); // retry待ち表示
setTimeout(function(){ xds.load(url, callback, onerror, retry-1);
loading(false);
}, 1000);
} else if (onerror)
onerror();
loading(false);
setTimeout(function(){ try { ifr.parentNode.removeChild(ifr); } catch(e) {} }, 0);
};
d.write('<scr'+'ipt src="array.js"></scr'+'ipt>' +
'<scr'+'ipt src="'+url2+'"></scr'+'ipt>');
d.close();
return ifr;
},
abort: function(ifr) {
if (ifr && ifr.parentNode) {
ifr.parentNode.removeChild(ifr);
loading(false);
}
},
load_default: function(url, callback, old, callback_key) {
this.abort(old);
return this.load(url, callback, twFail, 3, callback_key);
},
load_for_tab: function(url, callback, callback_key) { // タブ切替時に自動abort
var ifr_tab = this.ifr_tab;
var fr = [this.load(url,
function() { callback.apply(this,arguments); try { ifr_tab.remove(fr[0]); } catch(e) {} },
function() { twFail(); try { ifr_tab.remove(fr[0]); } catch(e) {} },
3, callback_key)];
this.ifr_tab.push(fr[0]);
},
abort_tab: function() {
for (var i = 0; i < this.ifr_tab.length; i++)
this.abort(this.ifr_tab[i])
this.ifr_tab = [];
},
ifr_tab: []
};
// 動的にフレームを生成してPOSTを投げる(Twitter APIはOAuth認証)
var postQueue = [];
function enqueuePost(url, done, err, retry) {
postQueue.push(arguments);
if (postQueue.length > 1) // 複数リクエストを同時に投げないようキューイング
return;
postNext();
}
function postNext() {
if (postQueue.length)
postInIFrame.apply(this, postQueue[0]);
}
var postSeq = 0;
var postTimeout = 2000;
function postInIFrame(url, done, err, retry) {
loading(true);
var frm = url.indexOf(twitterAPI) == 0 ? document.request : document.post;
frm.action = setupOAuthURL(url, true);
frm.target = "pfr" + (++postSeq);
var pfr = document.createElement("iframe"); // formのtargetとなるiframeを生成
pfr.name = "pfr" + postSeq;
pfr.src = "about:blank";
pfr.style.display = "none";
var errTimer = false;
// 5秒(エラー処理指定時はデフォルト2秒→10秒)で正常終了しなければエラーとみなす
errTimer = setTimeout(function(){
loading(false);
if (err) err(); else done();
setTimeout(function(){
pfr.parentNode && pfr.parentNode.removeChild(pfr);
postQueue.shift();
postNext();
}, 0);
}, retry?10000:err?postTimeout:5000);
var cnt = 0;
var onload = pfr.onload = function(){
if (cnt++ == 0) {
setTimeout(function(){frm.submit();}, 0);
} else {
loading(false);
clearTimeout(errTimer);
done();
setTimeout(function(){
pfr.parentNode && pfr.parentNode.removeChild(pfr);
postQueue.shift();
postNext();
}, 0);
}
};
if ('\v'=='v') pfr.onreadystatechange = function(){ /* for IE */
if (this.readyState == "complete") {
pfr.contentWindow.name = pfr.name;
onload();
}
};
document.body.appendChild(pfr);
}
// 要素の位置を取得
function cumulativeOffset(ele) {
var top = 0, left = 0;
do {
top += ele.offsetTop || 0;
left += ele.offsetLeft || 0;
ele = ele.offsetParent;
} while (ele);
return [left, top];
}
// スクロール
if (navigator.userAgent.indexOf('iPhone') >= 0)
window.scrollBy = function(x,y) { scrollTo(x+window.pageXOffset,y+window.pageYOffset) };
var scroll_adjust = 0;
var scroll_duration;
var scroll_timer = null;
function getScrollY() { return window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop; }
function scrollToY(y, total, start) {
if (scroll_timer) clearTimeout(scroll_timer);
scroll_timer = null;
var t = (new Date).getTime();
start = start || t;
total = total || y - getScrollY();
if (start == t) scroll_adjust = 0;
if (start == t) scroll_duration = Math.min(500, Math.abs(total));
y += scroll_adjust;
scroll_adjust = 0;
if (start+scroll_duration <= t)
return scrollTo(0, y);
var pix = Math.ceil(total*(1-Math.cos((t-start)/scroll_duration*Math.PI))/2);
scrollTo(0, y-total+pix);
scroll_timer = setTimeout(function(){scrollToY(y, total, start)}, 20);
}
function scrollToDiv(d, top_margin) {
top_margin = top_margin || 0;
var top = cumulativeOffset(d)[1];
var h = d.offsetHeight;
var sc_top = document.body.scrollTop || document.documentElement.scrollTop;
var win_h = window.innerHeight || document.documentElement.clientHeight;
if (top < sc_top+top_margin) scrollToY(top-top_margin);
if (sc_top+win_h < top+h) scrollToY(top+h-win_h);
}
// DOM Storage (or Cookie)
var use_local_storage = true;
try {
window.sessionStorage; /* check DOM storage is accessible */
if (!window.localStorage) window.localStorage = window.globalStorage && window.globalStorage[location.hostname];
} catch(e) { use_local_storage = false; }
if (location.search.indexOf("cookie=1") >= 0) use_local_storage = false;
function readCookie(key) {
try {
if (use_local_storage && window.localStorage && window.localStorage["twicli_"+key])
return String(window.localStorage["twicli_"+key]);
} catch(e) { return null; }
key += "=";
var scookie = document.cookie + ";";
start = scookie.indexOf(key);
if (start >= 0) {
var end = scookie.indexOf(";", start);
return unescape(scookie.substring(start + key.length, end));
}
return null;
}
function writeCookie(key, val, days) {
if (use_local_storage && window.localStorage)
try {
deleteCookie(key); // to avoid exception on iPad
window.localStorage["twicli_"+key] = val;
} catch(e) {
alert("DOM storage write error!\n" + e);
}
else {
var sday = new Date();
sday.setTime(sday.getTime() + (days * 1000 * 60 * 60 * 24));
document.cookie = key + "=" + escape(val) + ";expires=" + sday.toGMTString();
}
}
function deleteCookie(key) {
try { delete window.localStorage["twicli_"+key]; } catch(e) {}
var sday = new Date();
sday.setTime(sday.getTime() - 1);
document.cookie = key + "=;expires=" + sday.toGMTString();
}
// 言語リソースをルックアップ
var browser_lang = navigator.browserLanguage || navigator.language || navigator.userLanguage || 'en';
var browser_lang0 = browser_lang.split('-')[0];
if (!langNames[browser_lang] && langNames[browser_lang0]) browser_lang = browser_lang0;
var user_lang = readCookie('user_lang') || browser_lang;
var lang;
for (lang = 0; lang < langList.length; lang++)
if (langList[lang] == user_lang) break;
function _(key) {
if (!langResources[key])
alert("no langResource\n\n"+key);
else
key = langResources[key][lang] || key;
var args = arguments;
return key.replace(/\$(\d+)/, function(x,n){ return args[parseInt(n)] });
}
// version check
document.twicli_js_ver = 3;
if (!document.twicli_html_ver || document.twicli_html_ver < document.twicli_js_ver) {
if (location.href.indexOf('?') < 0) {
location.href = location.href + '?' + document.twicli_js_ver;
} else {
alert(_('An old HTML file is loaded. Please reload it. If the problem is not fixed, please try erasing caches.'));
}
}
// user-defined CSS
var user_style = readCookie('user_style') || "";
document.write('<style>' + user_style + '</style>');
// twicli用変数
var twitterURL = 'http://twitter.com/';
var twitterAPI = 'http://api.twitter.com/1/';
var myname = null; // 自ユーザ名
var myid = null; // 自ユーザID
var last_user = null; // user TLに表示するユーザ名
var last_user_info = null; // user TLに表示するユーザ情報(TLから切替時のキャッシュ)
// 設定値
var currentCookieVer = 16;
var cookieVer = parseInt(readCookie('ver')) || 0;
var updateInterval = (cookieVer>3) && parseInt(readCookie('update_interval')) || 60;
var pluginstr = (cookieVer>6) && readCookie('tw_plugins') || ' regexp.js\nlists.js\noutputz.js\nsearch.js\nfavotter.js\nfollowers.js\nshorten_url.js\nresolve_url.js';
if (cookieVer<8) pluginstr+="\ntranslate.js\nscroll.js";
if (cookieVer<9) pluginstr+="\nthumbnail.js";
//if (cookieVer<10) pluginstr=" worldcup-2010.js\n" + pluginstr.substr(1);
if (cookieVer<11) pluginstr = pluginstr.replace(/worldcup-2010\.js[\r\n]+/,'');
if (cookieVer<11) pluginstr+="\ngeomap.js";
if (cookieVer<12 && pluginstr.indexOf('tweet_url_reply.js')<0) pluginstr+="\ntweet_url_reply.js";
if (cookieVer<13) pluginstr+="\nrelated_results.js";
if (cookieVer<14) pluginstr+="\nembedsrc.js";
if (cookieVer<15) pluginstr = pluginstr.replace(/search2\.js[\r\n]+/,'');
if (cookieVer<16) pluginstr+="\nmute.js";
pluginstr = pluginstr.substr(1);
var plugins = new Array;
var max_count = Math.min((cookieVer>3) && parseInt(readCookie('max_count')) || 50, 200);
var max_count_u = Math.min(parseInt(readCookie('max_count_u')) || 50, 200);;
var nr_limit = Math.max(max_count*2.5, parseInt(readCookie('limit')) || 500); // 表示する発言数の上限
var auto_update = parseInt(readCookie('auto_update') || "1"); // POST後に自動アップデート
var no_since_id = parseInt(readCookie('no_since_id') || "0"); // since_idを使用しない
var no_counter = parseInt(readCookie('no_counter') || "0"); // 発言文字数カウンタを無効化
var no_resize_fst = parseInt(readCookie('no_resize_fst') || "0"); // フィールドの自動リサイズを無効化
var replies_in_tl = parseInt(readCookie('replies_in_tl') || "1"); // フォロー外からのReplyをTLに表示
var display_as_rt = parseInt(readCookie('display_as_rt') || "0"); // Retweetを"RT @〜: …"形式で表示
var footer = readCookie('footer') || ""; // フッタ文字列
var decr_enter = parseInt(readCookie('decr_enter') || "0"); // Shift/Ctrl+Enterで投稿
var no_geotag = parseInt(readCookie('no_geotag') || "0"); // GeoTaggingを無効化
var use_ssl = parseInt(readCookie('use_ssl') || "0"); // SSLを使用
// TL管理用
var cur_page = 1; // 現在表示中のページ
var nr_page = 0; // 次に取得するページ
var nr_page_re = 0; // 次に取得するページ(reply用)
var max_id;
var get_next_func = getOldTL; // 次ページ取得関数
var since_id = null; // TLの最終since_id
var since_id_reply = null; // Replyの最終since_id
var in_reply_to_user = null; // 発言の返信先ユーザ
var in_reply_to_status_id = null;// 発言の返信先id
// クロスドメイン通信関連
var seq = (new Date).getTime();
var users_log = [];
var update_ele = null;
var update_ele2 = null;
var reply_ele = null;
var reply_ele2 = null;
var direct_ele = null;
var direct1 = null;
var direct2 = null;
// UI関連
var user_pick1 = null; // [⇔]で表示するユーザ名1
var user_pick2 = null; // [⇔]で表示するユーザ名2
var popup_user = null; // ポップアップメニューが選択されたユーザ名
var popup_id = null; // ポップアップメニューが選択された発言ID
var popup_ele = null; // ポップアップメニューが選択された発言ノード
var fav_mode = 0; // Userタブで 1: fav表示中 2: following表示中 3: followers表示中
var rep_top = 0; // replyのオーバーレイ位置
var rep_trace_id = null; // replyのオーバーレイに追加する発言ID
var popup_top = 0; // ポップアップメニューの表示位置
var min_fst_height = 30; // 発言欄の最小の高さ
var selected_menu; // 選択中のタブ
var update_timer = null;
var update_reply_counter = 0;
var update_direct_counter = 0;
var key_press_detected = false;
var last_post = null;
var last_in_reply_to_user = null;
var last_in_reply_to_status_id = null;
var last_direct_id = null;
var geo = null;
var geowatch = null;
var ratelimit_reset_time = null;
var loading_cnt = 0;
var err_timeout = null;
var update_post_check = false;
var tw_config;
var t_co_maxstr = "http://t.co/*******";
// loading表示のコントロール
function loading(start) {
loading_cnt += start ? 1 : loading_cnt > 0 ? -1 : 0;
$('loading').style.display = loading_cnt > 0 ? "block" : "none";
}
//ログイン・自ユーザ名受信
var access_token = readCookie('access_token');
var access_secret = readCookie('access_secret');
if (!access_token || !access_secret) location.href = 'oauth/index.html';
//URL(?status=〜)から発言入力
if (location.search.match(/[?&]status=(.*?)(?:&|$)/)) {
writeCookie('twicli_onload', decodeURIComponent(RegExp.$1));
location.href = "twicli.html";
} else {
setTimeout(function(){
if ($("fst") && ($("fst").value = readCookie('twicli_onload') || '')) {
deleteCookie('twicli_onload');
}
}, 0);
}
var re_auth = false;
function twAuth(a) {
if (a.error) {
if (!use_ssl) {
use_ssl = 1;
return auth();
}
alert(a.error);
if (a.error == "Incorrect signature" || a.error.indexOf("Could not authenticate") >= 0)
logout();
return;
}
if (!myname || !myid || myname != a.screen_name || re_auth) {
re_auth = false;
myname = last_user = a.screen_name;
last_user_info = a;
myid = a.id;
writeCookie('access_user', myname+'|'+myid, 3652);
$("user").innerHTML = last_user;
update();
}
if (!no_geotag && a.geo_enabled && navigator.geolocation) {
$("option").innerHTML += '<div id="geotag"><a href="javascript:toggleGeoTag()"><img align="left" id="geotag-img" src="images/earth_off.png">'+_('GeoTagging')+' <span id="geotag-st">OFF</span></a><small id="geotag-info"></small></div>';
setFstHeight(min_fst_height, true);
}
callPlugins('auth');
}
function twAuthFallback() {
// verify_credentials API is unavailable?
re_auth = true;
xds.load_default(twitterAPI + "users/show.json?suppress_response_codes=true&screen_name="+myname, twAuth);
}
function auth() {
if (use_ssl)
twitterAPI = twitterAPI.replace('http', 'https');
var name = readCookie('access_user');
if (name) {
name = name.split('|');
myname = last_user = name[0];
myid = name[1];
$("user").innerHTML = last_user;
update();
}
xds.load(twitterAPI + "account/verify_credentials.json?suppress_response_codes=true", twAuth, twAuthFallback, 3);
}
function logout(force) {
if (!force && !confirm(_('Are you sure to logout? You need to re-authenticate twicli at next launch.')))
return;
callPlugins('logout');
deleteCookie('access_token');
deleteCookie('access_secret');
deleteCookie('access_user');
location.href = 'oauth/index.html';
}
function error(str, err) {
if (err && err[0] && err[0].code == 93) {
if (confirm(_('Cannot access to direct messages. Please re-auth twicli for DM access.')))
logout(true);
return;
}
if (str.indexOf('Rate limit exceeded.') == 0) {
if (ratelimit_reset_time && new Date < ratelimit_reset_time)
return;
else
xds.load_for_tab(twitterAPI + 'account/rate_limit_status.json?id=' + myname, twLimit2);
}
$("errorc").innerHTML = str;
$("error").style.display = "block";
if (err_timeout) clearTimeout(err_timeout);
err_timeout = error_animate(true);
}
function error_animate(show, t) {
t = t || new Date();
var dur = new Date() - t;
var opacity = Math.min(0.7, dur/300.0);
if (!show) opacity = Math.max(0, 0.7-opacity);
$("error").style.opacity = opacity;
if (show && opacity == 0.7)
err_timeout = setTimeout(function(){ error_animate(false); }, 5000);
else if (!show && opacity == 0)
$("error").style.display = "none";
else
err_timeout = setTimeout(function(){ error_animate(show, t); }, 30);
}
function clear_error() {
if ($("error").style.opacity == 0.7) {
clearTimeout(err_timeout);
err_timeout = setTimeout(function(){ error_animate(false); }, 0);
}
}
function twFail() {
error('<img style="vertical-align:middle" src="images/whale.png"> '+_('API error (Twitter may be over capacity?)'));
}
// enterキーで発言, "r"入力で再投稿, 空欄でTL更新
function press(e) {
if (e != 1) key_press_detected = true;
if (e != 1 && (e.keyCode != 13 && e.keyCode != 10 ||
!decr_enter && (e.ctrlKey || e.shiftKey) || decr_enter && !(e.ctrlKey || e.shiftKey)) )
return true;
var st = document.frm.status;
if (!key_press_detected) st.value = st.value.replace(/\n/g, "");
if (st.value == '') {
update();
return false;
}
if (parseInt($("counter").innerHTML,10) < 0) {
alert(_("This tweet is too long."));
return false;
}
var retry = 0;
if (st.value == "r" && last_post) {
retry = 1;
st.value = last_post;
in_reply_to_user = last_in_reply_to_user;
setReplyId(last_in_reply_to_status_id);
}
last_post = st.value;
last_in_reply_to_user = in_reply_to_user;
last_in_reply_to_status_id = in_reply_to_status_id;
if (st.value.substr(0,1) == "." || st.value.indexOf("@"+in_reply_to_user) < 0)
setReplyId(false); // "."で始まるか"@ユーザ名"が含まれていない時はin_reply_to指定無し
callPlugins("post", st.value);
st.value += footer;
st.select();
var text = st.value;
enqueuePost(twitterAPI + 'statuses/update.xml?status=' + encodeURIComponent(st.value) +
(geo && geo.coords ? "&display_coordinates=true&lat=" + geo.coords.latitude +
"&long=" + geo.coords.longitude : "") +
(in_reply_to_status_id ? "&in_reply_to_status_id=" + in_reply_to_status_id : ""),
function(){ resetFrm(); if (auto_update) { update_post_check = [2,text]; setTimeout(update, postTimeout); }},
function(){ if (auto_update) { update_post_check = [retry,text]; update() }}, retry);
in_reply_to_user = in_reply_to_status_id = null;
return false;
}
// GeoTag
function toggleGeoTag() {
if (!geowatch) {
geowatch = navigator.geolocation.watchPosition(function(g){
geo = g;
var maplink = typeof(display_map) == 'function';
$("geotag-info").innerHTML = " : " + (maplink ? '<a href="javascript:display_map([geo.coords.latitude, geo.coords.longitude, geo.coords.accuracy], $(\'geotag-info\'))">' : '') + g.coords.latitude + ", " + g.coords.longitude + " (" + g.coords.accuracy + "m)" + (maplink ? '</a>' : '');
setFstHeight(null, true);
});
$("geotag-img").src = "images/earth.png";
$("geotag-st").innerHTML = "ON";
$("geotag-info").innerHTML = " : -";
} else {
navigator.geolocation.clearWatch(geowatch);
geo = geowatch = null;
$("geotag-img").src = "images/earth_off.png";
$("geotag-st").innerHTML = "OFF";
$("geotag-info").innerHTML = "";
setFstHeight(null, true);
}
}
// フォームリサイズ
function setFstHeight(h, force) {
if (!h)
h = $("fst").value.length ? Math.max($("fst").scrollHeight+2,min_fst_height) : min_fst_height;
if (no_resize_fst && !force) return;
var exh = (navigator.userAgent.indexOf("MSIE 8") >= 0 ? 1 : navigator.userAgent.indexOf("MSIE 9") >= 0 ? 1 : 0), opt = $("option").clientHeight;
$("fst").style.height = h + 'px';
$("option").style.top = h + 2 + exh*5 + 'px';
$("menu").style.top = $("counter-div").style.top = h+3+exh*5 + opt + 'px';
var mh = Math.max($("menu").clientHeight, $("menu2").clientHeight);
$("control").style.height = h+mh+2+exh*5 + opt + 'px';
$("tw").style.top = $("tw2").style.top = $("re").style.top = h+mh+3+exh*4 + opt + 'px';
}
if (navigator.userAgent.indexOf('iPhone') < 0)
window.onresize = function(){ setFstHeight(null, true); }
// 発言文字数カウンタ表示・更新
function updateCount() {
setFstHeight();
if (!no_counter) $("counter-div").style.display = "block";
// for calculate length with shorten URL.
var s = $("fst").value.replace(
/https?:\/\/[^\/\s]*[\w!#$%&'()*+,.\/:;=?@~-]+(?=&\w+;)|https?:\/\/[^\/\s]*[\w!#$%&'()*+,.\/:;=?@~-]+/g,
function(t) {return t_co_maxstr + (t.substr(t.length-1) == ')' ? ')' : '');});
$("counter").innerHTML = 140 - footer.length - s.length;
}
// フォームの初期化
function resetFrm() {
document.frm.reset();
setReplyId(false);
if ($("counter-div").style.display == "block") updateCount();
setFstHeight(min_fst_height);
}
// reply先の設定/解除
function setReplyId(id) {
in_reply_to_status_id = id;
}
// reply先を設定
function replyTo(user, id) {
in_reply_to_user = user;
var head = (selected_menu.id == "direct" ? "d " : "@") + user + " ";
if (document.frm.status.value.indexOf(head) !== 0) // 連続押しガード
document.frm.status.value = head + document.frm.status.value;
setReplyId(id);
document.frm.status.select();
}
// reply先を表示
function dispReply(user, id, ele, cascade) {
user_pick1 = user;
var e = !cascade && (window.event || arguments.callee.caller.arguments[0]);
var shiftkey = e && (e.shiftKey || e.modifiers & 4);
var td = $((selected_menu.id == "TL" ? "tw" : selected_menu.id == "reply" ? "re" : "tw2c") + "-" + id);
if (td && td.style.display == "none") td = null;
var rd = $('reps-' + id);
// 通常 → 反転表示 (rdあり) or オーバーレイ表示
// shiftキー → 反転表示 (td優先) or オーバーレイ表示(td/rdなし)
var d = shiftkey ? td || rd : rd || td;
if (!shiftkey && !rd || shiftkey && !d || cascade) {
// オーバーレイ表示
var ele_top = cumulativeOffset(ele)[1] + 20;
if (ele.parentNode.parentNode.id == "reps" || ele.parentNode.parentNode.parentNode.id == "reps" || cascade)
rep_trace_id = id;
else
rep_top = ele_top;
d = d || $("tw-" + id) || $("re-" + id) || $("tw2c-" + id);
if (d && d.tw) {
dispReply2(d.tw);
return;
}
if (cascade) return;
reply_ele = xds.load_default(twitterAPI + 'statuses/show/'+id+'.json?include_entities=true&suppress_response_codes=true', dispReply2, reply_ele);
return;
}
// 反転表示
if (d.parentNode.id != 'reps')
closeRep();
scrollToDiv(d);
d.className += ' emp';
setTimeout(function(){d.className = d.className.replace(' emp','')}, 2000);
}
// reply先をoverlay表示 (Timelineに無い場合)
function dispReply2(tw) {
if (tw.error) return error(tw.error);
var id = tw.id_str || tw.id;
if ($('rep').style.display == 'block' && $('reps-'+id)) // already displayed
return;
var el = document.createElement("div");
el.id = 'reps-'+id;
el.innerHTML = makeHTML(tw, false, 'reps');
el.tw = tw;
callPlugins("newMessageElement", el, tw, 'reps');
if (!rep_trace_id || id != rep_trace_id) {
$('reps').innerHTML = '';
$('rep').style.top = rep_top + 'px';
} else
$('reps').appendChild(document.createElement('hr'));
$('reps').appendChild(el);
$('rep').style.display = "block";
scrollToDiv($('rep'));
user_pick2 = tw.user.screen_name;
var in_reply_to = tw.in_reply_to_status_id_str || tw.in_reply_to_status_id;
if (in_reply_to) {
var d = $("tw-" + in_reply_to) || $("re-" + in_reply_to) || $("tw2c-" + in_reply_to);
if (d)
dispReply(tw.user.screen_name, in_reply_to, $('reps') /* この引数は使われない */, true);
}
}
// replyのoverlay表示を閉じる
function closeRep() {
callPlugins('closeRep');
$('rep').style.display = 'none';
$('reps').innerHTML = '';
rep_trace_id = null;
}
// replyからユーザ間のタイムラインを取得
function pickup2() {
if (user_pick1 && user_pick2)
switchUser(user_pick1 + "," + user_pick2);
}
// ポップアップメニューの初期化
function popup_init() {
var popup_id_list = ['popup_link_user', 'popup_link_status', 'popup_status_delete',
'popup_status_retweet', 'popup_status_quote',
'upopup_user_block', 'upopup_user_unblock', 'upopup_user_spam'];
for (var x = 0; x < popup_id_list.length; x++)
$(popup_id_list[x]).innerHTML = _($(popup_id_list[x]).innerHTML);
}
// ポップアップメニューを表示
function popup_menu(user, id, ele) {
popup_user = user;
popup_id = id;
popup_ele = ele.parentNode.parentNode;
callPlugins("popup", $('popup'), user, id, ele);
$('popup_link_user').href = twitterURL + user;
$('popup_link_status').href = twitterURL + user + '/statuses/' + id;
$('popup_status_delete').style.display = (selected_menu.id == "direct" || popup_ele.tw.user.screen_name == myname ? "block" : "none");
$('popup_status_retweet').style.display = (selected_menu.id != "direct" ? "block" : "none");
$('popup_status_quote').style.display = (selected_menu.id != "direct" ? "block" : "none");
$('popup').style.display = "block";
var pos = cumulativeOffset(ele);
$('popup').style.left = pos[0] < $('popup').offsetWidth - ele.offsetWidth ? 0 : pos[0] - $('popup').offsetWidth + ele.offsetWidth + 'px';
popup_top = pos[1] + 20;
$('popup').style.top = popup_top + 'px';
$('popup_hide').style.height = Math.max(document.body.scrollHeight, $("tw").offsetHeight+$("control").offsetHeight) + 'px';
$('popup_hide').style.display = "block";
}
// ポップアップメニューを非表示
function popup_hide() {
callPlugins("popup_hide");
$('popup').style.display = 'none';
$('userinfo_popup').style.display = 'none';
$('popup_hide').style.display = 'none';
popup_user = popup_id = popup_ele = null;
}
// ユーザ情報のポップアップメニューを表示
function userinfo_popup_menu(user, id, ele) {
popup_user = user;
popup_id = id;
callPlugins("userinfo_popup", $('userinfo_popup'), user, id, ele);
$('userinfo_popup').style.display = "block";
var pos = cumulativeOffset(ele);
$('userinfo_popup').style.left = pos[0] < $('userinfo_popup').offsetWidth - ele.offsetWidth ? 0 : pos[0] - $('userinfo_popup').offsetWidth + ele.offsetWidth + 'px';
$('userinfo_popup').style.top = pos[1] + 20 + 'px';
$('popup_hide').style.height = Math.max(document.body.scrollHeight, $("tw").offsetHeight+$("control").offsetHeight) + 'px';
$('popup_hide').style.display = "block";
}
// 発言のReTweet
function retweetStatus(id, ele) {
id = id || popup_id;
ele = ele || popup_ele;
if (!id) return false;
if ($('lock-' + ele.id)) {
error(_("This tweet is protected."));
return false;
}
if (!confirm(_("Retweet to your followers?"))) return false;
var target_ele = ele;
enqueuePost(twitterAPI + 'statuses/retweet/' + id + '.xml',
function(){
var img = document.createElement("img");
img.src = "images/rt.png";
target_ele.insertBefore(img, target_ele.childNodes[target_ele.childNodes.length-1]);
});
return false;
}
// 発言をRT付きで引用
function quoteStatus(id, user, ele) {
id = id || popup_id;
user = user || popup_user;
ele = ele || popup_ele;
if (!id) return false;
if ($('lock-' + ele.id) && !confirm(_("This tweet is protected; Are you sure to retweet?"))) return false;
var tw = !display_as_rt && ele.tw.retweeted_status || ele.tw;
$('fst').value = "RT @"+user+": " + charRef(tw.text);
$('fst').focus(); $('fst').select();
return false;
}
// 発言の削除
function deleteStatus(id) {
id = id || popup_ele.tw.id_str || popup_ele.tw.id;
if (!id) return false;
if (!confirm(_('Are you sure to delete this tweet?'))) return false;
for (var i = 0; i < 3; i++) {
var target = $(['tw-','re-','tw2c-'][i]+id);
if (target) target.className += " deleted";
}
enqueuePost(twitterAPI + (selected_menu.id == 'direct'?'direct_messages':'statuses') + '/destroy/' + id + '.xml',
function(){}, function(){});
return false;
}
// 最新タイムラインを取得
function update() {
if (!myname) return auth();
callPlugins("update");
update_ele = xds.load_default(twitterAPI + 'statuses/home_timeline.json' +
'?count=' + (since_id ? 200 : max_count) +
'&include_entities=true&suppress_response_codes=true'
+ (!no_since_id && since_id ? '&since_id='+since_id : ''), twShow, update_ele);
resetUpdateTimer();
}
function resetUpdateTimer() {
if (update_timer) clearInterval(update_timer);
update_timer = setInterval(update, Math.max(parseInt(updateInterval||5)*1000, 5000));
}
// 外部リンクを開く際のフック
function link(a) { return true; }
// tweetのHTML表現を生成
function dateFmt(d) {
d = new Date(typeof(d)=='string' && document.all ? d.replace('+','GMT+') : d);
function d2(dig) { return (dig>9?"":"0") + dig }
return (d.getMonth()+1) + "/" + d.getDate() + " " + d.getHours() + ":" + d2(d.getMinutes()) + ":" + d2(d.getSeconds());
}
function insertPDF(str) {
var k = 0;
for (var i = 0; i < str.length; i++) {
if (str[i] == "\u202A" || str[i] == "\u202B" || str[i] == "\u202D" || str[i] == "\u202E")
k++;
else if (str[i] == "\u202C" && i > 0)
k--;
}
while (k--)
str += "\u202C"
return str;
}
function makeHTML(tw, no_name, pid, userdesc) {
var rt = tw.retweeted_status;
var rs = tw.retweeted_status || tw;
var rt_mode = !!(display_as_rt || userdesc);
var t = rt_mode ? tw : rs;
var text = t.text;
var un = t.user.screen_name;
if (display_as_rt)
text = rt && rt.user ? "RT @" + rt.user.screen_name + ":" + rt.text : tw.text;
if (userdesc)
text = tw.user.description || '';
var id = tw.id_str || tw.id;
var id2 = t.id_str || t.id;
var eid = pid+'-'+id;
var in_reply_to = t.in_reply_to_status_id_str || t.in_reply_to_status_id;
var expanded_urls = {};
if (tw.entities && tw.entities.urls)
tw.entities.urls.concat(tw.entities.media || []).map(function(_){
if (_.url && _.expanded_url) expanded_urls[_.url] = _.expanded_url;
});
return /*fav*/ (t.d_dir ? '' : '<img alt="☆" class="fav" src="http://assets3.twitter.com/images/icon_star_'+(!rt&&rs.favorited?'full':'empty')+'.gif" ' +
'onClick="fav(this,\'' + id + '\')"' + (pid ? ' id="fav-'+eid+'"' : '') + '>')+
(!no_name || (!display_as_rt && rt) ?
//ユーザアイコン
(t.user.url ? '<a target="_blank" href="'+t.user.url+'" onclick="return link(this);">' : '') +
'<img class="uicon" src="' + t.user.profile_image_url + '" title="' + (t.user.description ? t.user.description.replace(/"/g,'"') :'') + '">' + (t.user.url ? '</a>' : '') +
//名前
'<a href="' + twitterURL + un + '" onClick="switchUserTL(this.parentNode,'+rt_mode+');return false"><span class="uid">' + un + '</span>' +
/*プロフィールの名前*/ (t.user.name!=un ? '<span class="uname">('+insertPDF(t.user.name)+')</span>' : '') + '</a>'
: '') +
/* verified? */ (!no_name && t.user.verified ? '<img alt="verified" id="verified-' + eid + '" class="verified" src="images/verified.png">' : '') +
/* protected? */ (t.user.protected ? '<img alt="lock" id="lock-' + eid + '" class="lock" src="http://assets0.twitter.com/images/icon_lock.gif">' : '') +
/*ダイレクトメッセージの方向*/ (t.d_dir == 1 ? '<span class="dir">→</span> ' : t.d_dir == 2 ? '<span class="dir">←</span> ' : '') +
//本文 (https〜をリンクに置換 + @を本家リンク+JavaScriptに置換)
" <span id=\"text-" + eid + "\" class=\"status\">" +
text.replace(/https?:\/\/[^\/\s]*[\w!#$%&'()*+,.\/:;=?@~-]+(?=&\w+;)|https?:\/\/[^\/\s]*[\w!#$%&'()*+,.\/:;=?@~-]+|[@@](\w+(?:\/[\w-]+)?)|([,.!? 、。!?「」]|\s|^)([##])([\w々ぁ-ゖァ-ヺーㄱ-ㆅ㐀-\u4DBF一-\u9FFF가-\uD7FF\uF900-\uFAFF0-9A-Za-zヲ-゚]+)(?=[^\w々ぁ-ゖァ-ヺーㄱ-ㆅ㐀-\u4DBF一-\u9FFF가-\uD7FF\uF900-\uFAFF0-9A-Za-zヲ-゚]|$)/g, function(_,u,x,h,s){
if (!u && !h) {
var paren = '';
if (_.substr(_.length-1) == ')') { // 末尾の")"はURLに含めない
_ = _.substr(0, _.length-1);
paren = ')';
}
if (expanded_urls[_]) {
t.text_replaced = (t.text_replaced || t.text).replace(_, expanded_urls[_]);
_ = expanded_urls[_];
}
return "<a class=\"link\" target=\"_blank\" href=\""+_.replace(/\"/g, '%22')+"\" onclick=\"return link(this);\">"+_+"</a>"+paren;
}
if (h == "#" || h == "#") {
if (s.match(/^\d+$/)) return _;
return x+"<a target=\"_blank\" class=\"hashtag\" title=\"#"+s+"\" href=\"http://search.twitter.com/search?q="+encodeURIComponent("#"+s)+"\">"+h+s+"</a>";
}
if (u.indexOf('/') > 0) return "<a target=\"_blank\" href=\""+twitterURL+u+"\" onclick=\"return link(this);\">"+_+"</a>";
return "<a href=\""+twitterURL+u+"\" class=\"mention\" onClick=\"switchUser('"+u+"'); return false;\" >"+_+"</a>";
}).replace(/\r?\n|\r/g, "<br>") + '</span>' +
//Retweet情報
' <span id="rtinfo-'+eid+'" class="rtinfo">' +
(!display_as_rt && rt ? "<img src=\"images/rt.png\" alt=\"RT\">by <img src=\""+tw.user.profile_image_url+"\" alt=\""+tw.user.screen_name+"\" class=\"rtuicon\"><a href=\""+twitterURL+tw.user.screen_name+"\" onclick=\"switchUserTL(this.parentNode.parentNode, true);return false\">" + tw.user.screen_name + "</a> " + (parseInt(tw.retweet_count) > 1 ? '<small>& ' + (typeof(tw.retweet_count) == 'string' ? tw.retweet_count : tw.retweet_count-1) + '</small>' : '') :'') + '</span>' +
//日付
' <span id="utils-'+eid+'" class="utils">' +
'<span class="prop"><a class="date" target="twitter" href="'+twitterURL+(t.d_dir ? '#!/messages' : un+'/statuses/'+id2)+'">' + dateFmt(t.created_at) + '</a>' +
//クライアント
(t.source ? '<span class="separator"> / </span><span class="source">' + t.source.replace(/<a /,'<a target="twitter"') + '</span>' : '') + '</span>' +
//Geolocation
(rs.geo && rs.geo.type == 'Point' ? '<a class="button geomap" id="geomap-' + eid + '" target="_blank" href="http://maps.google.com?q=' + rs.geo.coordinates.join(',') + '" onclick="return link(this);"><img src="images/marker.png" alt="geolocation" title="' + rs.geo.coordinates.join(',') + '"></a>' : '') +
(!rs.geo && rs.place ? '<a class="button geomap" id="geomap-' + eid + '" target="_blank" href="http://maps.google.com?q=' + encodeURIComponent(rs.place.full_name) + '" onclick="return link(this);"><img src="images/marker.png" alt="geolocation" title="' + rs.place.full_name.replace(/'/g,"'") + '"></a>' : '') +
//返信先を設定
' <a class="button reply" href="javascript:replyTo(\'' + un + "','" + id2 + '\')"><img src="images/reply.png" alt="↩" width="14" height="14"></a>' +
//返信元へのリンク
(in_reply_to ? ' <a class="button inrep" href="#" onClick="dispReply(\'' + un + '\',\'' + in_reply_to + '\',this); return false;"><img src="images/inrep.png" alt="☞" width="14" height="14"></a>' : '') +
//popupメニュー表示
' <a class="button popup" href="#" onClick="popup_menu(\'' + un + "','" + id2 + '\', this); return false;"><small><small>▼</small></small></a>' +
'</span><div class="dummy"></div>';
}
// ユーザ情報のHTML表現を生成
function makeUserInfoHTML(user) {
return '<table><tr><td><a target="twitter" href="' + twitterURL + 'account/profile_image/'+
user.screen_name+'"><img class="uicon2" src="' + user.profile_image_url + '"></a></td><td id="profile"><div>' +
(user.verified ? '<img class="verified" alt="verified" src="images/verified.png">' : '') +
(user.protected ? '<img class="lock" alt="lock" src="http://assets0.twitter.com/images/icon_lock.gif">' : '') +
'<b>' + user.screen_name + '</b> / <b>' + user.name + '</b></div>' +
(user.location ? '<div><b>'+_('Location')+'</b>: ' + user.location + '</div>' : '') +
(user.url ? '<div><b>'+_('URL')+'</b>: <a target="_blank" href="' + user.url + '" onclick="return link(this);">' + user.url + '</a></div>' : '') +
'<div>' + (user.description ? user.description : '<br>') +
'</div><b><a href="' + twitterURL + user.screen_name + '/following" onclick="switchFollowing();return false;">' + user.friends_count + '<small>'+_('following')+'</small></a> / ' +
'<a href="' + twitterURL + user.screen_name + '/followers" onclick="switchFollower();return false;">' + user.followers_count + '<small>'+_('followers')+'</small></a>' +
'<br><a href="' + twitterURL + user.screen_name + '" onclick="switchStatus();return false;">' + user.statuses_count + '<small>'+_('tweets')+'</small></a> / ' +
'<a href="' + twitterURL + user.screen_name + '/favorites" onclick="switchFav();return false;">' + user.favourites_count + '<small>'+_('favs')+'</small></a></b>' +
'</td></tr></table>'+
(user.screen_name != myname ? '<a class="button upopup" href="#" onClick="userinfo_popup_menu(\'' + user.screen_name + '\',' + user.id + ', this); return false;"><small><small>▼</small></small></a>' : '')+
'<a target="twitter" href="' + twitterURL + user.screen_name + '">[Twitter]</a>' +
'<a href="' + twitterURL + user.screen_name + '/following/tweets" onclick="switchFollowingTL();return false;">[TL]</a> ';
}
// 過去の発言取得ボタン(DOM)生成
function nextButton(id, p) {
var ret = document.createElement('div');
ret.id = id;
ret.className = 'get-next';
ret.onclick = function() { getNext(this); };
ret.innerHTML = '▽' + (p ? '(' + p + ')' : '');
return ret;
}
// favoriteの追加/削除
function fav(img, id) {
if (img.src.indexOf('throbber') >= 0) return;
var f = img.src.indexOf('empty') >= 0;
setFavIcon(img, id, -1);
enqueuePost(twitterAPI + 'favorites/' + (f ? 'create' : 'destroy') + '/' + id + '.xml',
function(){ setFavIcon(img, id, f) }/*, function(){ setFavIcon(img, id, !f) }*/);
}
// favアイコンの設定(f=0: 未fav, f=1:fav済, f=-1:通信中)
function setFavIcon(img, id, f) {
var img_tl = $('fav-tw-' + id);
var img_re = $('fav-re-' + id);
var img_tw2c = $('fav-tw2c-' + id);
var img_url = (f==-1) ? twitterURL + 'images/icon_throbber.gif' :
'http://assets3.twitter.com/images/icon_star_' + (f ? 'full' : 'empty') + '.gif';
img.src = img_url;
if (img_tl) img_tl.src = img_url;
if (img_re) img_re.src = img_url;
if (img_tw2c) img_tw2c.src = img_url;
callPlugins("fav", id, f, img, img_tl, img_re, img_tw2c);
}
// followとremove
function follow(f) {
if (!f && !confirm(_("Are you sure to remove $1?", last_user))) return false;
enqueuePost(twitterAPI + 'friendships/' + (f ? 'create' : 'destroy') + '/' + last_user + '.xml', switchUser);
return false;
}
// blockとunblock
function blockUser(f) {
if (f && !confirm(_("Are you sure to block $1?", last_user))) return false;
enqueuePost(twitterAPI + 'blocks/' + (f ? 'create' : 'destroy') + '/' + last_user + '.xml', switchUser);
return false;
}
function reportSpam(f) {
if (f && !confirm(_("Are you sure to report $1 as spam?", last_user))) return false;
enqueuePost(twitterAPI + 'report_spam.xml?screen_name=' + last_user, switchUser);
return false;
}
// ユーザ情報を表示
function twUserInfo(user) {
if (user.error) return error(user.error);
var elem = $('user_info');
elem.innerHTML = makeUserInfoHTML(user);
callPlugins("newUserInfoElement", elem, user);
if (myname != user.screen_name) {
xds.load_for_tab(twitterAPI + 'friendships/show.json' +
'?source_screen_name=' + myname + '&target_id=' + user.id +
'&suppress_response_codes=true', twRelation);
}
}
// ユーザ情報にフォロー関係を表示
function twRelation(rel) {
var source = rel.relationship.source;
var elem = $("user_info");
elem.innerHTML += '<input type="button" value="' + _(source.following ? 'Remove $1' : 'Follow $1', last_user) +
'" onClick="follow('+!source.following+')">';
if (source.followed_by)
$("profile").innerHTML += "<br><span class=\"following_you\">" + _('$1 is following you!', rel.relationship.target.screen_name)+'</span>';
callPlugins("newUserRelationship", elem, rel);
}
// ダイレクトメッセージ一覧の受信
function twDirect1(tw) {
if (tw.error) return error(tw.error);
if (tw.errors) return error(tw.errors[0].message, tw.errors);
direct1 = tw;
if (direct2)
twDirectShow();
}
function twDirect2(tw) {
if (tw.error) return error(tw.error);
if (tw.errors) return error(tw.errors[0].message, tw.errors);
direct2 = tw;
if (direct1)
twDirectShow();
}
function twDirectShow() {
var direct = direct1.concat(direct2).sort(function(a,b){return b.id - a.id});
direct = direct.map(function(d){
if (d.recipient_screen_name == myname) {
d.user = d.sender;
d.d_dir = 1;
} else {
d.user = d.recipient;
d.d_dir = 2;
}
return d;
});
twShow2(direct);
direct1 = direct2 = false;
}
function checkDirect() {
direct_ele = xds.load_default(twitterAPI + 'direct_messages.json' +
'?suppress_response_codes=true', twDirectCheck, direct_ele);
update_direct_counter = 20;
}
function twDirectCheck(tw) {
if (tw.error) return error(tw.error);
if (tw.errors) return error(tw.errors[0].message, tw.errors);