forked from vimpr/vimperator-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google-plus-commando.js
1777 lines (1594 loc) · 58.1 KB
/
google-plus-commando.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
/* NEW BSD LICENSE {{{
Copyright (c) 2011-2012, anekos.
Copyright (c) 2011, teramako.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
###################################################################################
# http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license #
# に参考になる日本語訳がありますが、有効なのは上記英文となります。 #
###################################################################################
}}} */
// INFO {{{
let INFO =
<>
<plugin name="GooglePlusCommando" version="2.4.7"
href="https://github.com/vimpr/vimperator-plugins/blob/master/google-plus-commando.js"
summary="The handy commands for Google+"
lang="en-US"
xmlns="http://vimperator.org/namespaces/liberator">
<author email="[email protected]">anekos</author>
<author email="[email protected]" homepage="http://d.hatena.ne.jp/teramako/">teramako</author>
<license>New BSD License</license>
<project name="Vimperator" minVersion="3.0"/>
<p>Many Mappings and Post command for Google+</p>
<p>require: feedSomeKeys_3.js and x-hint.js and _libly.js</p>
<item>
<tags>:googleplus-setup</tags>
<spec>:googleplus -setup</spec>
<spec>:gp -setup</spec>
<description>
<p>Should setup at first</p>
<ol>
<li>Login to <a href="htts://plus.google.com/">Google+</a></li>
<li>Execute <ex>:googleplus -setup</ex></li>
</ol>
</description>
</item>
<item>
<tags>:googleplus-nonargs</tags>
<spec>:googleplus</spec>
<spec>:gp</spec>
<description>
<p>when argument is none, select the Google+ tab or open in new tab</p>
</description>
</item>
<item>
<tags>:googleplus :gp</tags>
<spec>:googleplus <oa>-l[link]</oa> <oa>-i[mage] <a>imageURL</a></oa> <oa>-t[o] <a>to</a></oa> <a>message</a></spec>
<spec>:gp <oa>-l[ink]</oa> <oa>-i[mage] <a>imageURL</a></oa> <oa>-t[o]> <a>to</a></oa> <a>message</a></spec>
<description>
<p>Post <a>message</a></p>
<dl>
<dt>-link</dt>
<dd>
Add the current URL. If the selections are available, add the selections as relataed page.
And when <a>-image</a> option is not specified and image elements is contained in the selections,
add the URL of the largest image.
</dd>
<dt>-image</dt>
<dd>
Specify image URL
</dd>
<dt>-to</dt>
<dd>
Specify the circles. Can set multiple. (Default: Anyone)
</dd>
</dl>
</description>
</item>
<item>
<tags>g:gplus_commando_map_</tags>
<spec>let g:gplus_commando_map_<a>command</a> = <a>map-keys</a></spec>
<description>
<p>
Map <a>map-keys</a> for <a>command</a>.
The possible <a>command</a>s.
<dl>
<dt>next</dt> <dd>Go to next entry.</dd>
<dt>prev</dt> <dd>Back to previous entry.</dd>
<dt>share</dt> <dd>Shate current entry.</dd>
<dt>plusone</dt> <dd>+1</dd>
<dt>comment</dt> <dd>Comment to current entry.</dd>
<dt>post</dt> <dd>Post new entry.</dd>
<dt>yank</dt> <dd>Copy the permlink of current entry to clipboard.</dd>
<dt>notification</dt> <dd>Open notification box.</dd>
<dt>cancel</dt> <dd>Cancel current something.</dd>
<dt>submit</dt> <dd>Submit current editing post.</dd>
<dt>unfold</dt> <dd>Unfold something on current entry.</dd>
<dt>menu</dt> <dd>Open the menu of current entry.</dd>
<dt>mute</dt> <dd>Mute current entry.</dd>
<dt>open</dt> <dd>Open something on current entry.</dd>
</dl>
</p>
<p>rc file example</p>
<code>
let g:gplus_commando_map_next = "j"
let g:gplus_commando_map_prev = "k"
let g:gplus_commando_map_share = "s"
let g:gplus_commando_map_plusone = "p"
let g:gplus_commando_map_comment = "c"
let g:gplus_commando_map_post = "C"
let g:gplus_commando_map_yank = "y"
let g:gplus_commando_map_notification = "n"
let g:gplus_commando_map_submit = "<C-CR>"
let g:gplus_commando_map_cancel = "<Esc>"
let g:gplus_commando_map_unfold = "e"
let g:gplus_commando_map_menu = "m"
</code>
</description>
</item>
</plugin>
<plugin name="GooglePlusCommando" version="2.4.7"
href="https://github.com/vimpr/vimperator-plugins/blob/master/google-plus-commando.js"
summary="The handy commands for Google+"
lang="ja-JP"
xmlns="http://vimperator.org/namespaces/liberator">
<author email="[email protected]">anekos</author>
<author email="[email protected]" homepage="http://d.hatena.ne.jp/teramako/">teramako</author>
<license>New BSD License</license>
<project name="Vimperator" minVersion="3.0"/>
<p>Many Mappings and Post command for Google+</p>
<p>require: feedSomeKeys_3.js and x-hint.js and _libly.js</p>
<item>
<tags>:googleplus-setup</tags>
<spec>:googleplus -setup</spec>
<spec>:gp -setup</spec>
<description>
<p>Should setup at first</p>
<ol>
<li>Login to <a href="htts://plus.google.com/">Google+</a></li>
<li>Execute <ex>:googleplus -setup</ex></li>
</ol>
</description>
</item>
<item>
<tags>:googleplus-nonargs</tags>
<spec>:googleplus</spec>
<spec>:gp</spec>
<description>
<p>when argument is none, select the Google+ tab or open in new tab</p>
</description>
</item>
<item>
<tags>:googleplus :gp</tags>
<spec>:googleplus <oa>-l[link]</oa> <oa>-i[mage] <a>imageURL</a></oa> <oa>-t[o] <a>to</a></oa> <a>message</a></spec>
<spec>:gp <oa>-l[ink]</oa> <oa>-i[mage] <a>imageURL</a></oa> <oa>-t[o]> <a>to</a></oa> <a>message</a></spec>
<description>
<p>Post <a>message</a></p>
<dl>
<dt>-link</dt>
<dd>
Add the current URL. If the selections are available, add the selections as relataed page.
And when <a>-image</a> option is not specified and image elements is contained in the selections,
add the URL of the largest image.
</dd>
<dt>-image</dt>
<dd>
Specify image URL
</dd>
<dt>-to</dt>
<dd>
Specify the circles. Can set multiple. (Default: Anyone)
</dd>
</dl>
</description>
</item>
<item>
<tags>g:gplus_commando_map_</tags>
<spec>let g:gplus_commando_map_<a>command</a> = <a>map-keys</a></spec>
<description>
<p>
<a>map-keys</a> に <a>command</a> をマップします。
使える <a>command</a> は以下の通りです。
<dl>
<dt>next</dt> <dd>次のエントリに移動</dd>
<dt>prev</dt> <dd>前のエントリに移動</dd>
<dt>share</dt> <dd>現在のエントリを共有</dd>
<dt>plusone</dt> <dd>+1</dd>
<dt>comment</dt> <dd>現在のエントリにコメントする</dd>
<dt>post</dt> <dd>新しく投稿(共有)する</dd>
<dt>yank</dt> <dd>現在のエントリの Permlink をクリップボードにコピーする</dd>
<dt>notification</dt> <dd>通知欄を開く</dd>
<dt>cancel</dt> <dd>編集中のフォームをキャンセルして閉じる</dd>
<dt>submit</dt> <dd>編集中のフォームから投稿する</dd>
<dt>unfold</dt> <dd>現在のエントリ内の折りたたみを解除する</dd>
<dt>menu</dt> <dd>現在のエントリのメニューを開く</dd>
<dt>mute</dt> <dd>現在のエントリをミュートする</dd>
<dt>open</dt> <dd>現在のエントリの画像やリンクなどを開く</dd>
</dl>
</p>
<p>rc file example</p>
<code>
let g:gplus_commando_map_next = "j"
let g:gplus_commando_map_prev = "k"
let g:gplus_commando_map_share = "s"
let g:gplus_commando_map_plusone = "p"
let g:gplus_commando_map_comment = "c"
let g:gplus_commando_map_post = "C"
let g:gplus_commando_map_yank = "y"
let g:gplus_commando_map_notification = "n"
let g:gplus_commando_map_submit = "<C-CR>"
let g:gplus_commando_map_cancel = "<Esc>"
let g:gplus_commando_map_unfold = "e"
let g:gplus_commando_map_menu = "m"
</code>
</description>
</item>
</plugin>
</>;
// }}}
(function () {
// Utils {{{
function A (list)
Array.slice(list);
function I (list)
Iterator(list);
function IA (list)
Iterator(A(list));
function click (elem, after) {
click
if (!elem)
throw GPCError('elem is undefined');
setTimeout(
function () {
buffer.followLink(elem, liberator.CURRENT_TAB);
setTimeout(after, 1);
},
1
);
}
function clicks (elems, after) {
if (!(elems && elems.length))
return;
setTimeout(
function () {
click(elems[0], elems.length === 1 && after);
clicks(elems.slice(1));
},
1
);
}
function isDisplayed (elem)
(elem && !/none/.test(util.computedStyle(elem).display));
function withCount (command) {
return function (count) {
if (count < 1)
count = 1;
for (let i = 0; i < count; i++)
command();
};
}
function GPCError (msg) {
if (this instanceof GPCError) {
liberator.log('GPCError: ' + msg);
this.toString = function () String(msg);
} else {
return new GPCError(msg);
}
}
function selectFind (doc, selector, func) {
if (!doc)
return;
if (!func)
func = function () true;
for (let [n, v] in IA(doc.querySelectorAll(selector))) {
let res = func(v, n);
if (res)
return v;
}
}
function getSelector (elem) {
if (!elem)
return;
let cs = elem.getAttribute('class').trim().split(/\s+/);
cs.sort(function (a, b) a.localeCompare(b));
return '.' + cs.join('.');
}
function getSelectorFind (doc, sel, func) {
return getSelector(selectFind(doc, sel, func));
}
// }}}
// Selector {{{
const [S, X, R] = (function () {
function role (name, prefix)
((prefix || '') + '[role="' + name + '"]');
function once (obj, name, fail) {
let func = obj[name];
Object.defineProperty(
obj,
name,
{
get: let (result) function () (result || (result = func()) || fail)
}
);
}
function onceAll (obj, fail) {
for (let [n, v] in I(obj)) {
if (n === 'role')
continue;
if (typeof v === 'function')
once(obj, n, fail);
if (typeof v === 'object') {
onceAll(v, fail);
}
}
}
let cssRules = {
__iterator__: function (nameOnly) {
if (content.location.host != 'plus.google.com')
return;
let result = [];
for (let [, sheet] in IA(content.document.styleSheets)) {
for (let [n, rule] in IA(sheet.cssRules)) {
yield nameOnly ? n : [n, rule];
}
}
},
find: function (re, notre) {
let result = [];
for (let [, rule] in I(this)) {
if (re.test(rule.cssText)) {
if (notre && notre.test(rule.cssText))
continue;
result.push(rule);
}
}
if (result.length < 1)
throw GPCError('Not fount css rule: ' + re);
if (result.length == 1)
return result[0].selectorText;
for (let [, rule] in I(result)) {
liberator.log(rule.cssText);
}
throw GPCError('Two and more rules are found');
},
finder: function (re, notre) {
let self = this;
return function () self.find(re, notre);
},
get: function (klass, returnCssText) {
let reKlass = new RegExp('(^|,)\s*.' + klass + '\s*(,|$)');
let result = [];
for (let [, rule] in I(this)) {
if (reKlass.test(rule.selectorText))
result.push(rule);
}
if (returnCssText) {
return result.map(function (it) it.cssText);
} else {
return result;
}
}
};
let selector = {
role: role,
typePlusone: '[g\\:entity^="buzz:"]',
editable: '.editable',
plusone: 'button[id^="po-"]',
currentEntry: {
root: cssRules.finder(/border-left: 1px solid rgb\(77, 144, 240\);\s*\}/),
unfold: {
comment: cssRules.finder(/url\("\/\/ssl\.gstatic\.com\/s2\/oz\/images\/stream\/expand\.png"\);\s*background-repeat/),
content: function () {
/*
* FIXME UghhhhhHHhaaa
let content = cssRules.find(/\{ overflow: hidden; padding-bottom: \d+px; padding-top: \d+px; text-overflow: ellipsis ellipsis; \}/);
let buttons = cssRules.find(/^[^,]+\,[^,]+\{\s*color:\s*rgb\(51, 102, 204\);\s*cursor:\s*pointer;\s*\}$/);
return buttons.split(/,/).map(function (b) (content + ' > div > ' + b)).join(', ');
*/
return '.SS0Hfe';
}
},
menu: {
mute: '----'
},
menuButton: cssRules.finder(/url\("\/\/ssl\.gstatic\.com\/s2\/oz\/images\/stream\/options_default\.png"\).*pointer.*13.*margin-right: -44/, /\.\w{3,}\s\{/),
cancel: role('button', '[id$=".cancel"]'),
submit: role('button', '[id$=".post"]'),
},
post: {
root: function () {
let div = cssRules.find(/\{ margin-left: \d+px; margin-right: \d+px; margin-top: \d+px; width: \d+px; \}/);
return '#contentPane ' + 'div[decorated="true"]' + div;
// onclick の this.className += ' f-Sa' は初めは存在しないっぽい
},
open: cssRules.finder(/opacity 0.125s ease 0.125s/),
cancel: 'div[id$=".c"]', // :6w.c
},
notification: '#gbi1',
viewer: {
root: function () {
let n = Elements.doc.querySelector(S.viewer.next);
return n && getSelector(n.parentNode.parentNode);
},
prev: cssRules.finder(/url\("\/\/ssl\.gstatic\.com\/s2\/oz\/images\/left-arrow2\.png"\)/),
next: cssRules.finder(/url\("\/\/ssl\.gstatic\.com\/s2\/oz\/images\/right-arrow2\.png"\)/)
},
dialog: {
root: role('dialog', 'body > '),
//cssRules.find(/0pt 4px 16px rgba\(0, 0, 0, 0.2\).*-moz-border-right-color.*z-index: 1101/));
submit: 'td[valign="top"] > div[role="button"]:nth-child(1)',
cancel: 'td[valign="top"] > div[role="button"]:nth-child(2)'
},
frames: {
notifications: {
root: 'iframe[src*="/_/notifications/"]',
summary: {
root: '#summary-view',
prev: '#summary-view + div > div > div > span',
next: '#summary-view + div > div > div > span:last-child',
back: '#summary-view + div > div > span',
},
entry: {
entries: 'div[id^=":"][style*="max-height"]', // :2.diz13l....
comment: cssRules.finder(/rgb\(221, 221, 221\).*rgb\(153, 153, 153\)/),
mute: 'div[id^=":"][style*="max-height"] > div > div:nth-child(2) > div > div > ' + role('button', 'span') // FIXME
},
}
},
closeButton: cssRules.finder(/url\("\/\/ssl\.gstatic\.com\/s2\/oz\/images\/lightbox-sprite2.gif"\).*0%.*0%.*z-index/)
};
let xpath = {
hints: [
'span[@role="button"]',
'div[@role="button"]',
'div[@data-content-type]',
'img[contains(@class,"O-g-Sd-la")]', // /photos の写真
//FIXME 'div[contains(@class,"a-z-nb-A")]'
]
};
onceAll(selector, '.MEOW_MEOW_MEOW');
return [selector, xpath, cssRules];
})();
// }}}
// Elements {{{
const Elements = (function () {
return {
get doc() content.document,
get currentEntry () MakeElement(Entry, Elements.doc.querySelector(S.currentEntry.root)),
post: {
get root () Elements.doc.querySelector(S.post.root),
get cancel () Elements.doc.querySelector(S.post.cancel),
get open () Elements.doc.querySelector(S.post.open)
},
get notification () Elements.doc.querySelector(S.notification),
get viewer () MakeElement(Viewer, Elements.doc.querySelector(S.viewer.root)),
get dialog () MakeElement(Dialog, Elements.doc.querySelector(S.dialog.root)),
frames: {
get notifications () MakeElement(Notifications, Elements.doc.querySelector(S.frames.notifications.root))
},
get focusedEditor () {
function hasIFrame (elem) {
let iframe = elem.querySelector('iframe');
return iframe && iframe.contentWindow === win;
}
// エントリにコメント
function get1 (root) {
function button (editor, name)
editor.parentNode.querySelector(S.role('button', <>[id$=".{name}"]</>));
if (!root)
return;
let editors = A(root.querySelectorAll('div[id$=".editor"]')).filter(hasIFrame);
if (editors.length === 0)
return;
if (editors.length > 1)
throw 'Two and more editors were found.';
let peditor = editors[0];
return {
editor: peditor,
button: {
submit: button(peditor, 'post'),
cancel: button(peditor, 'cancel')
}
};
}
// 新しく投稿
function get2 () {
function button (editor, index) {
let result = editor.querySelectorAll('td > ' + S.role('button'))[index];
if (result)
return result;
if (index === 1)
return editor.querySelector(S.post.cancel);
}
const indexes = {submit: 0, cancel: 1};
let editors = A(doc.querySelectorAll(S.post.root)).filter(hasIFrame);
if (editors.length === 0)
return;
if (editors.length > 1)
throw 'Two and more editors were found.';
let peditor = editors[0];
return {
editor: peditor,
button: {
submit: button(peditor, 0),
cancel: button(peditor, 1)
}
};
}
// ダイアログ
function get3 (root) {
function button (editor, name)
editor.parentNode.querySelector(S.role('button', <>[id$=".{name}"]</>));
if (!root)
return;
let editors = A(root.querySelectorAll('div.editable')).filter(hasIFrame);
if (editors.length === 0)
return;
if (editors.length > 1)
throw 'Two and more editors were found.';
return {
editor: editors[0],
button: {
submit: root.querySelector(S.dialog.submit),
cancel: root.querySelector(S.dialog.cancel),
}
};
}
let doc = content.document;
let win = document.commandDispatcher.focusedWindow;
return (
get1(doc) ||
get2() ||
get1(Elements.frames.notifications.root.contentDocument) ||
(Elements.dialog && Elements.dialog.root && get3(Elements.dialog.root))
);
},
/**
* ノードをHTMLテキストに変換
* @param {Node} aNode
* @param {String} [aParentTag] 親ノードのタグ名
* @param {String} [aIndent] インデント文字列
* @param {Number} [aIndex] ノード番号(ol>li 時のみ使用)
* @return {String}
*/
node2txt: function (aNode, aParentTag, aIndent, aIndex) {
var txt = "";
switch (aNode.nodeType) {
case Node.DOCUMENT_NODE: // 9
case Node.DOCUMENT_FRAGMENT_NODE: // 11
switch (aParentTag) {
case "ol":
case "ul":
case "dl":
aIndent = " ";
break;
default:
aIndent = "";
}
txt = nodelist2txt(aNode.childNodes, aParentTag, aIndent).join("");
break;
case Node.TEXT_NODE: // 3
txt = aNode.nodeValue.replace(/\s+/g, " ");
break;
case Node.ELEMENT_NODE: // 1
let localName = aNode.localName,
children = aNode.childNodes;
switch (localName) {
case "ul":
case "ol":
case "dl":
txt = "<br/>\n" + nodelist2txt(children, localName, aIndent + " ").join("") + "<br/>\n";
break;
case "li":
txt = aIndent + (aParentTag == "ol" ? (" " + (aIndex+1)).slice(-2) + ". " : " * ").replace(" ", " ", "g") +
nodelist2txt(children, "li", aIndent).join("") +
"<br/>\n";
break;
case "dt":
txt = aIndent + "<b>" + nodelist2txt(children, localName, aIndent) + "</b>:<br/>\n";
break;
case "dd":
txt = aIndent + " " + nodelist2txt(children, localName, aIndent) + "<br/>\n";
break;
case "br":
txt = "<br/>\n";
break;
case "img":
txt = "<img src=" + aNode.src.quote() + " width=\"" + aNode.width + "\" height=\"" + aNode.height + "\"/>";
break;
case "p":
txt = nodelist2txt(children, "p", "").join("") + "<br/>\n";
break;
case "a":
if (aNode.hasAttribute("href") && aNode.href.indexOf("http") == 0) {
txt = "<a href=" + aNode.href.quote() + (aNode.title ? " title=" + aNode.title.quote() : "") + ">" +
nodelist2txt(children, "a", "").join("") +
"</a>";
break;
}
default:
txt = '<' + localName + '>' +
nodelist2txt(children, localName, aIndent).join("") +
'</' + localName + '>';
}
break;
}
return txt;
},
};
function MakeElement (constructor, root) {
if (root && isDisplayed(root))
return constructor(root);
}
function Entry (root) {
let self = {
get root () root,
get permlink () [
e
for ([, e] in Iterator(A(root.querySelectorAll('a'))))
if (!e.getAttribute('oid'))
][0],
unfold: {
get comment () root.querySelector(S.currentEntry.unfold.comment),
get content () root.querySelector(S.currentEntry.unfold.content)
},
get buttons () A(self.plusone.parentNode.querySelectorAll(S.role('button'))),
get commentButton () self.buttons[0],
get commentEditor () let (e = root.querySelector(S.editable)) (e && e.parentNode),
get comment() (self.commentEditor || self.commentButton),
get plusone () root.querySelector(S.typePlusone),
get share () self.buttons[2],
menu: {
// FIXME この三つは、一度メニューを出さないと、現われないかもしれない
get root () root.querySelector(S.role('menu')),
get items () A(self.menu.root.querySelectorAll(S.role('menuitem'))),
get mute () self.menu.items.slice(-2)[0]
},
get menuButton () root.querySelector(S.currentEntry.menuButton),
get cancel () root.querySelector(S.currentEntry.cancel),
get submit () root.querySelector(S.currentEntry.submit)
};
return self;
}
function Dialog (root) {
function nButton (n) {
let bs = self.buttons;
if (bs.length === 2)
return bs[n];
}
let self = {
get root () root,
get buttons () A(root.querySelectorAll(S.role('button'))),
get submit () nButton(0),
get cancel () nButton(1)
};
return self;
}
function Viewer (root) {
let self = {
get cancel () root.querySelector(S.closeButton),
get prev () root.querySelector(S.viewer.prev),
get next () root.querySelector(S.viewer.next)
};
return self;
}
function Notifications (root) {
let self = {
get root () root,
get visible () {
let h = parseInt(root.style.height, 10) > 0;
if (!h)
return false;
let nwc = plugins.googlePlusCommando.element.frames.notifications.root.contentDocument.querySelector('#nw-content');
return parseInt(util.computedStyle(nwc).height, 10) > 100;
},
summary: {
get root () root.contentDocument.querySelector(S.frames.notifications.summary.root),
get visible () isDisplayed(self.summary.root),
},
entry: {
get root () self.summary.root.nextSibling,
get entries () A(root.contentDocument.querySelectorAll(S.frames.notifications.entry.entries)),
get current () self.entry.entries.filter(isDisplayed)[0],
get visible () isDisplayed(self.entry.root),
get prev () root.contentDocument.querySelector(S.frames.notifications.summary.prev),
get next () root.contentDocument.querySelector(S.frames.notifications.summary.next),
get back () root.contentDocument.querySelector(S.frames.notifications.summary.back),
get comment () self.entry.current.querySelector(S.frames.notifications.entry.comment),
get mute () self.entry.current.querySelector(S.frames.notifications.entry.mute),
get unfold () root.contentDocument.querySelector(S.currentEntry.unfold.comment)
}
};
return self;
}
/**
* NodeListの子をテキストにして配列で返す
* @param {NodeList} aChildNoes
* @param {String} aParentTag
* @param {String} aIndent
* @return {String[]}
*/
function nodelist2txt (aChildNodes, aParentTag, aIndent) {
var a = [], index = 0;
for (let i = 0, len = aChildNodes.length, child; child = aChildNodes[i]; ++i) {
let txt = Elements.node2txt(child, aParentTag, aIndent, index);
if (txt) {
a.push(txt);
++index;
}
}
return a;
}
return Elements;
})();
// }}}
// Post Help {{{
const PostHelp = {
PanelID: 'google-plus-commando-help-panel',
get panel () Elements.doc.querySelector('#' + PostHelp.PanelID),
show: function () {
function move (panel) {
let contentHeight = document.getElementById('content').boxObject.height;
let rect = Elements.focusedEditor.editor.getClientRects()[0];
if (rect.top < (contentHeight / 2)) {
panel.style.top = '';
panel.style.bottom = '10px';
} else {
panel.style.top = '10px';
panel.style.bottom = '';
}
}
let doc = Elements.doc;
let parent = doc.body;
let exists = PostHelp.panel;
if (exists) {
move(exists);
exists.style.display = 'block';
return;
}
let panel = doc.createElement('div');
panel.setAttribute('id', PostHelp.PanelID);
let (ps = panel.style) {
ps.position = 'fixed';
ps.left = '10px';
ps.zIndex = 1000;
ps.backgroundColor = 'white';
ps.border = 'solid 1px grey';
}
panel.innerHTML = <>
<table>
<tr><th>入力</th> <th>効果</th> <th>解説</th> </tr>
<tr><td>*TEXT*</td> <td><b>TEXT</b></td> <td>太字</td> </tr>
<tr><td>_TEXT_</td> <td><i>TEXT</i></td> <td>斜体</td> </tr>
<tr><td>-TEXT-</td> <td><s>TEXT</s></td> <td>打ち消し線</td> </tr>
<tr><td>*-TEXT-*</td> <td><b><s>TEXT</s></b></td> <td>太字/打消。打消(-)は内側に書く</td> </tr>
<tr><td>-ねこ-</td> <td>☓</td> <td>日本語の打消はダメ</td> </tr>
<tr><td>-ね こ-</td> <td><s>ね こ</s></td> <td>英数字や半角スペースを入れたらOK</td> </tr>
<tr><td>-Aねこす-</td> <td><s>Aねこす</s></td> <td>英数字を前後に入れても良い</td> </tr>
</table>
</>;
move(panel);
parent.appendChild(panel);
return;
},
hide: function () {
let exists = PostHelp.panel;
if (exists)
exists.style.display = 'none';
}
};
// }}}
// Commands {{{
const Commands = {
moveEntry: function (next) {
let [arrow, vim, dir] = next ? ['<Down>', 'j', 'next'] : ['<Up>', 'k', 'prev'];
if (Elements.viewer)
return click(Elements.viewer[dir]);
let notifications = Elements.frames.notifications;
if (notifications && notifications.visible && notifications.entry.visible)
return click(Elements.frames.notifications.entry[dir]);
let arrowTarget = (function () {
if (notifications && notifications.visible)
return notifications.root.contentDocument.body;
let menus = A(Elements.doc.querySelectorAll(S.role('menu', '[tabindex="0"]')));
if (menus.length === 1)
return menus[0];
})();
plugins.feedSomeKeys_3.API.feed.apply(
null,
arrowTarget ? [arrow, ['keypress'], arrowTarget] : [vim, ['vkeypress'], Elements.doc]
);
},
next: withCount(function () Commands.moveEntry(true)),
prev: withCount(function () Commands.moveEntry(false)),
comment: function () {
let after = PostHelp.show;
let notifications = Elements.frames.notifications;
if (notifications && notifications.visible && notifications.entry.visible) {
let e = notifications.entry.current;
e.scrollTop = e.scrollHeight;
click(notifications.entry.comment, after);
} else {
let entry = Elements.currentEntry;
click(entry.comment, after);
}
},
plusone: function () click(Elements.currentEntry.plusone),
share: function () click(Elements.currentEntry.share),
post: function () {
buffer.scrollTop();
click(Elements.post.open, PostHelp.show);
},
yank: function () {
let e = Elements.currentEntry.permlink;
if (!e)
liberator.echoerr('Not found permlink');
util.copyToClipboard(e.href);
liberator.echo('Copy the permlink to clipboard: ' + e.href);
},
notification: function () {
click(Elements.notification);
},
cancel: function () {
let notifications = Elements.frames.notifications;
if (notifications && notifications.visible && notifications.entry.visible)
return click(notifications.entry.back);
for (let [, n] in Iterator(['dialog', 'viewer'])) {
let e = Elements[n];
if (e && e.cancel)
return click(e.cancel);
}
if (Elements.frames.notifications.visible)
return click(Elements.notification);
click(Elements.doc.body);
},
submit: function () {
if (liberator.focus)
return;
PostHelp.hide();
click(Elements.focusedEditor.button.submit);
},
unfold: function () {
let notifications = Elements.frames.notifications;
if (notifications && notifications.visible && notifications.entry.visible)
return click(notifications.entry.unfold);
click(Elements.currentEntry.unfold.comment);
click(Elements.currentEntry.unfold.content);
},
menu: function () {
click(Elements.currentEntry.menuButton);
},
mute: function () {
let notifications = Elements.frames.notifications;
if (notifications && notifications.visible && notifications.entry.visible)
return click(notifications.entry.mute);
click(Elements.currentEntry.menu.mute);
},
open: function () {
function clicks (links) {
if (links.length < 1)
throw GPCError('No link.');
if (links.length === 1)
return click(links[0]);
let t = {};
A(links).forEach(function (link) (t[link.textContent] = link));
commandline.input(
'Select a link',
function (url) {
let link = t[url];
if (link) {
click(link);
} else {
liberator.open(url, liberator.NEW_TAB);
}
},
{
completer: function (context) {
context.completions = [
[link.href, link.textContent]
for ([, link] in IA(links))
];
}
}
);
}
let ce = Elements.currentEntry;
if (!ce)
return;
let dct = ce.root.querySelector('div[data-content-type]');
if (dct) {
if (!/application\/x-shockwave-flash/.test(dct.getAttribute('data-content-type')))
return click(dct);