-
Notifications
You must be signed in to change notification settings - Fork 123
/
DragNgoModoki_Fx40.uc.js
1855 lines (1706 loc) · 72.1 KB
/
DragNgoModoki_Fx40.uc.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
// ==UserScript==
// @name DragNgoModoki_Fx40.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description ファイル名をD&D
// @include main
// @compatibility Firefox 40 (not e10s)
// @author Alice0775
// @version 2017/11/18 Bug 1334975 removed nsIFilePicker.show(), nsILocalFile. use nsIFilePicker.open(), nsIFile
// @version 2017/11/18 nsIPrefBranch2 to nsIPrefBranch
// @version 2016/06/12 22:00 Fix regression from Update form history
// @version 2016/04/21 22:00 Update form history
// @version 2015/08/18 00:50 Fixed 受
// @version 2015/08/12 18:00 Fixed due to Bug 1134769
// @version 2014/11/26 21:00 Bug 1103280, Bug 704320
// @version 2014/11/10 10:00 get rid document.commandDispatcher
// @version 2014/10/30 10:00 working with addHistoryFindbarFx3.0.uc.js
// @version 2014/10/07 20:00 adjusts tolerance due to backed out Bug 378775
// @version 2014/10/07 19:00 Modified to use capturing phase for drop and event.defaultprevent
// ==/UserScript==
// @version 2014/07/05 12:00 adjusts tolerance due to Bug 378775
// @version 2014/05/01 12:00 Fix unnecessary toolbaritem creation
// @version 2013/10/31 00:00 Bug 821687 Status panel should be attached to the content area
// @version 2013/09/13 00:00 Bug 856437 Remove Components.lookupMethod
// @version 2013/08/26 14:00 use FormHistory.update and fixed typo
// @version 2013/05/30 01:00 text drag fails on http://blog.livedoor.jp/doku1108/archives/52130085.html
// @version 2013/05/02 01:00 Bug 789546
// @version 2013/04/22 14:00 typo, "use strict" mode
// @version 2013/04/19 20:00 treat HTMLCanvasElement as image
// @version 2013/04/14 23:40 remove all temp file on exit browser
// @version 2013/04/14 23:00 text open with externalEditor, char code
// @version 2013/04/14 22:00 text open with externalEditor (sloppy)
// @version 2013/04/14 21:00 checking element using Ci.nsIImageLoadingContent instead of HTMLImageElement
// @version 2013/03/05 00:00 input type=file change event が発火しないのを修正 Fx7+
// @version 2013/01/29 00:00 draggable="true"もう一度有効
// @version 2013/01/08 02:00 Bug 827546
// @version 2013/01/01 15:00 Avoid to overwrite data on dragstart. And Bug 789546
// @version 2012/10/24 23:00 href=javascript://のリンクテキストの処理変更
// @version 2012/10/06 23:00 Bug 795065 Add privacy status to nsDownload
// @version 2012/10/06 07:00 Bug 722872 call .init(null) for nsITransferable instance
// @version 2012/07/10 12:00 'テキストをConQueryで検索'にlink追加
// @version 2012/06/01 23:00 regression 04/19
// @version 2012/05/04 13:00 Bug 741216 対策
// @version 2012/04/19 00:05 debugなし
// @version 2012/04/19 00:00 designModeはなにもしないようにした
// @version 2012/03/01 12:00 isTabEmpty使うように
// @version 2012/02/12 16:00 fixed Bug 703514
// @version 2012/01/31 11:00 by Alice0775 12.0a1 about:newtab
// @version 2012/01/30 01:00 tavClose, this.sourcenode = null;
// @version 2011/07/22 21:00 Bug 50660 [FILE]Drag and drop for file upload form control (Fx7 and later)
// @version 2011/06/23 16:00 browser.tabs.loadInBackgroundに関わらずtabおよびtabshiftedはそれぞれ強制的に前面および背面に開く
// @version 2011/06/23 16:00 openLinkInにした
// @version 2011/06/22 00:00 getElementsByXPath 配列で返すのを忘れていた
// @version 2011/06/19 21:00 Google modified getElementsByXPath
// @version 2011/04/14 21:00 Google doc などでdrag drop uploadができないので外部ファイルのドロップは止め
// @version 2011/03/30 10:20 プロンプト
// @version 2011/03/29 14:20 copyToSearchBar, appendToSearchBar, searchWithEngine 追加変更
// @version 2011/03/11 10:30 Bug641090
// @version 2010/12/10 08:30 close button非表示 Bug 616014 - Add close button to the add-on bar
// @version 2010/11/13 20:30 status 4-evar
// @version 2010/09/24 20:30 Bug 574688 adon bar
// @version 2010/09/14 19:30 textのドラッグの判定時, テキストノードの制限を外してみた
// @version 2010/08/30 17:30 no more available InstallTrigger method in window since Firefox4.0b5pre
// @version 2010/08/15 17:00 パスの記入ができなくなっていた。regression from 07/15
// @version 2010/07/22 07:00 xxx Bug 580710 - Drag&Drop onto sidebar loads page into sidebar
// @version 2010/07/21 16:00 text
// @version 2010/07/15 16:00 window.getSelection()のままとした
// @version 2010/07/15 15:00 editable要素ではなにもしないようにした
// @version 2010/07/07 07:00 アドオンタブではなにもしないようにした
// @version 2010/07/06 01:05 外部テキストのドロップバグ
// @version 2010/07/06 01:00 外部テキストのドロップバグ
// @version 2010/07/06 00:55 frameへのドロップバグ, textはRESTRICT_SELECTED_TEXTにした
// @version 2010/07/05 20:55 rgression 2010/07/05 19:00 textlink
// @version 2010/07/05 20:30 検索エンジン
// @version 2010/07/05 19:00 textlink, modifier
// @version 2010/07/03 00:00 saveAs
// @version 2010/05/06 00:00 Bug 545119 - Remove browser dependency on nsDragAndDrop.js
// @version 2010/05/05 00:00 Bug 545119 - Remove browser dependency on nsDragAndDrop.js
// @version 2010/04/24 20:00 urlのjavascriptとdataは無条件にカレントタブに開くように
// @version 2010/04/22 23:00 urlの空白は削除しておく
// @version 2010/04/22 16:00 画像のドロップではリンクされている場合リンク先の画像, 保存pathのパス区切り
// @version 2010/04/21 21:35 infoない???
// @version 2010/04/21 17:50 xulエレメントは何もしないように
// @version 2010/04/21 17:50 インプットテキストエリアへのドロップができなくなっていた
// @version 2010/04/21 12:50 unload処理
// @version 2010/04/21 01:04 テキスト...が壊れていた
// @version 2010/04/21 01:03 複数の外部ファイルのtype=file へのドロップ動供くように
// @version 2010/04/21 01:02 複数の外部ファイルのドロップ動供くように
// @version 2010/04/21 01:00 saveFolderModoki.uc.xul連携
// @version 2010/04/21 01:00 Firefox3.7a5pre
// @version 2009/12/15 17:00 Fx3.6 and more
// @version 2007/08/04 20:00
// @LICENSE MPL 1.1/GPL 2.0/LGPL 2.1
"use strict";
if (typeof Cc != 'object' ) { var Cc = Components.classes;}
if (typeof Ci != 'object' ) { var Ci = Components.interfaces;}
if (typeof Cr != 'object' ) { var Cr = Components.results;}
//////////// Drag and Dorp bserver: replace contentAreaDNDObserver with it. ///////////////////
var DragNGo = {
// dir :'UDLR',
// modifier:'shift,ctrl,alt', //altは文字列の選択になるので実質使えない
// name :'hoge'
// obj :'link, textlink, text, image, file' ドロップの対象
// cmd :function(self, event, info) {} /* info:{urls:[], texts:[], nodes:[], files:[], fname:[]}*/
// urls:link,image,fileおよびtextlinkのurlを格納
// texts:linkのリンクテキストやalt文字, imageのtitle,alt文字, textはRESTRICT_SELECTED_TEXTによる
// nodes:ドロップしたDOMノード
// fname:linkやimageのファイル名の候補, textはRESTRICT_SELECTED_TEXTによる
//
RESTRICT_SELECTED_TEXT: true, //textは選択文字列のみ:true, ドロップした文字列(リンク等はurl):false
GESTURES: [
/*=== From Foreign data ===*/
{dir:'', modifier:'',name:'Fireパス記入',obj:'file'},
{dir:'', modifier:'',name:'xpi/jarインストール',obj:'file'},
/*{dir:'', modifier:'',name:'新しいタブ前面に開く',obj:'file',cmd:function(self,event,info){self.openUrls(info.urls, 'tab', null);}},//Google doc などでdrag drop uploadができなくなる*/
{dir:'', modifier:'',name:'新しいタブ前面に開く',obj:'link, textlink',cmd:function(self,event,info){self.openUrls(info.urls, 'tab', null);}},
{dir:'', modifier:'',name:'新しいタブでGoogle検索',obj:'text',cmd:function(self,event,info){self.searchWithEngine(info.texts, ['Google'], 'tab');}},
/*=== リンク ===*/
{dir:'U', modifier:'',name:'xpi/jarインストール',obj:'xpi,jar',cmd:function(self,event,info){self.installXpi(info.urls);}},
{dir:'U', modifier:'',name:'リンクを新しいタブ前面に開く',obj:'link, textlink',cmd:function(self,event,info){self.openUrls(info.urls, 'tab', null);}},
//{dir:'D', modifier:'',name:'リンクを新しいタブ後面に開く',obj:'link, textlink',cmd:function(self,event,info){self.openUrls(info.urls, 'tabshifted', null);}},
{dir:'D', modifier:'',name:'リンクを新しいタブでaguse.jp検索',obj:'link, textlink',cmd:function(self,event,info){self.searchWithEngine(info.urls, ['aguse.jp'], 'tab');}},
{dir:'L', modifier:'',name:'リンクを現在のタブ開く',obj:'link, textlink',cmd:function(self,event,info){self.openUrls(info.urls, 'current', null);}},
/*=== 画像 ===*/
{dir:'U', modifier:'',name:'画像を新しいタブ前面に開く',obj:'image',cmd:function(self,event,info){self.openUrls(info.urls, 'tab', null);}},
{dir:'D', modifier:'',name:'画像を新しいタブ後面に開く',obj:'image',cmd:function(self,event,info){self.openUrls(info.urls, 'tabshifted', null);}},
{dir:'L', modifier:'',name:'画像を現在のタブに開く',obj:'image',cmd:function(self,event,info){self.openUrls(info.urls, 'current', null);}},
{dir:'LD', modifier:'',name:'Google 類似画像検索',obj:'image',cmd:function(self,event,info){var TargetImage=info.urls[0];var URL="http://www.google.com/searchbyimage?image_url="+TargetImage;if(TargetImage)gBrowser.loadOneTab(URL,null,null,null,false,false);}},
/*=== Web Search ===*/
{dir:'R', modifier:'',name:'テキストをConQueryで検索',obj:'text',cmd:function(self,event,info){self.openConQueryPopup(event);}},
{dir:'UL', modifier:'',name:'テキストを現在のタブでgooウェブ検索(Green Label)',obj:'link, text',cmd:function(self,event,info){self.searchWithEngine(info.texts, ['gooウェブ検索(Green Label)'], 'current');}},
{dir:'U', modifier:'',name:'テキストを新しいタブでGoogle検索',obj:'text',cmd:function(self,event,info){self.searchWithEngine(info.texts, ['Google'], 'tab');}},
{dir:'D', modifier:'',name:'テキストを現在のタブでGoogle検索',obj:'text',cmd:function(self,event,info){self.searchWithEngine(info.texts, ['Google'], 'current');}},
{dir:'DL', modifier:'',name:'リンクテキストを新しいタブでGoogle検索',obj:'link',cmd:function(self,event,info){self.searchWithEngine(info.texts, ['Google'], 'tab');}},
{dir:'UL', modifier:'',name:'テキストを新しいタブでAmazon.com検索',obj:'link, text',cmd:function(self,event,info){self.searchWithEngine(info.texts, ['Amazon.com'], 'tab');}},
{dir:'UR', modifier:'',name:'テキストを新しいタブでYahoo! JAPAN検索',obj:'link, text',cmd:function(self,event,info){self.searchWithEngine(info.texts, ['Yahoo! JAPAN'], 'tab');}},
/*=== ページ内検索 ===*/
{dir:'L', modifier:'',name:'テキストをページ内検索',obj:'link, text',cmd:function(self,event,info){self.findWord(info.texts[0]);}},
/*=== クリップボード ===*/
{dir:'UD', modifier:'',name:'リンクurl/テキストをクリップボードにコピー',obj:'text',cmd:function(self,event,info){Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper).copyString(info.texts[0]);}},
{dir:'LR', modifier:'',name:'リンクテキスト/テキストをクリップボードにコピー',obj:'link, text',cmd:function(self,event,info){Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper).copyString(info.texts[0]);}},
{dir:'UDU', modifier:'',name:'URLをクリップボードにコピー',obj:'link',cmd:function(self,event,info){Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper).copyString(info.urls[0]);}},
{dir:'DR', modifier:'',name:'テキストを検索バーにコピー',obj:'link, text',cmd:function(self,event,info){self.copyToSearchBar(info.texts[0].replace(/\n/mg,' '));}},
{dir:'DR', modifier:'ctrl',name:'テキストを検索バーに追加コピー',obj:'link, text',cmd:function(self,event,info){self.appendToSearchBar(info.texts[0].replace(/\n/mg,' '));}},
/*=== 保存 ===*/
{dir:'RU', modifier:'',name:'リンク/画像をSaveFileModoki(SF)で保存',obj:'image, link',cmd:function(self,event){self.openSaveFileModokiPopup(event);}},
/*
{dir:'RD', modifier:'',name:'画像をD:/hogeに保存(SF)',obj:'image',cmd:function(self,event,info){if('saveFolderModoki' in window){saveFolderModoki.saveLink(info.urls[0], info.texts[0], 'D:\\hoge');}else{ self.saveLinkToLocal(info.urls[0],info.fname[0],'D:/hoge', true);}}},
{dir:'RD', modifier:'',name:'リンクをD:/に保存(SF)',obj:'link',cmd:function(self,event,info){if('saveFolderModoki' in window){saveFolderModoki.saveLink(info.urls[0], info.texts[0], 'D:\\');}else{ self.saveLinkToLocal(info.urls[0],info.fname[0],'D:/', false);}}},
*/
{dir:'RD', modifier:'',name:'画像を名前を付けて保存' ,obj:'image',cmd:function(self,event,info){self.saveAs(info.urls[0], info.fname[0], info.nodes[0].ownerDocument, info.nodes[0].ownerDocument);}},
{dir:'RD', modifier:'',name:'リンクを名前を付けて保存',obj:'link' ,cmd:function(self,event,info){self.saveAs(info.urls[0], info.fname[0], info.nodes[0].ownerDocument, info.nodes[0].ownerDocument);}},
/*=== テキストをえでぃたーで開く ===*/
{dir:'DL', modifier:'',name:'テキストをエディターで開く',obj:'text',cmd:function(self,event,info){self.editText(null, info.texts[0]);}}, // 引数 null: view_source.editor.pathのエディターを使う
/*=== appPathをparamsで開く, paramsはtxtで置き換えcharsetに変換される ===*/
{dir:'U', modifier:'shift,ctrl',name:'リンクをInternet Explorerで開く',obj:'link',cmd:function(self,event,info){self.launch(info.urls[0], "C:\\Program Files\\Internet Explorer\\iexplore.exe",["%%URL%%"],"Shift_JIS");}},
{dir:'R', modifier:'shift,ctrl',name:'テキストをDDwinで開く',obj:'text',cmd:function(self,event,info){self.launch(info.texts[0], "c:\\Program Files\\DDwin\\ddwin.exe", [",2,,G1,%%SEL%%"], "Shift_JIS");}},
/*=== Utility ===*/
{dir:'RDR', modifier:'',name:'Eijiro',obj:'text',cmd:function(){var TERM=getBrowserSelection().toString();var URL="http://eow.alc.co.jp/"+TERM+"/UTF-8/";if(TERM)gBrowser.loadOneTab(URL,null,null,null,false,false);}},
{dir:'RDRD', modifier:'',name:'Excite で英和',obj:'text', /*要popupTranslate.uc.xul*/
cmd:function(self,event,info){
var UI = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Ci.nsIScriptableUnicodeConverter);
UI.charset = "UTF-8";
var text = info.texts[0];
var engine = popupTranslate.selectEngineByDescription(UI.ConvertToUnicode("Excite 英日"));
if (engine)
popupTranslate.getTranslateResult(text, engine, null);
}
},
{dir:'RLU', modifier:'',name:'選択テキスト(プロンプト)を指定ドメイン内で検索',obj:'link, text',
cmd:function(self,event,info){
var win = document.commandDispatcher.focusedWindow;
var _document = win.document;
var p = prompt('Input word to search under the domain('+_document.location.hostname+'):', info.texts[0]);
if(p)
_document.location.href = 'http://www.google.com/search?as_qdr=y15&q=site:' +
_document.location.href.split('/')[2] +
' '+encodeURIComponent(p);
}
},
{dir:'UDUD', modifier:'',name:'選択範囲をテキストファイルとして保存',obj:'text',
cmd:function(self){
// 選択範囲をテキストファイルとして保存する。
var win = document.commandDispatcher.focusedWindow;
var sel = win.getSelection();
if (sel && !sel.isCollapsed) {
var fname = win.location.href.match(/[^\/]+$/) + '.txt';
fname = decodeURIComponent(fname);
fname = fname.replace(/[\*\:\?\"\|\/\\<>]/g, '_');
self.saveTextToLocal(sel.toString(), fname, false);
} else {
alert('No Selection!');
}
}
},
], // ~GESTURES
RESET_GESTURE: "RDLU",
dataRegExp : /^\s*(.*)\s*$/m,
mdataRegExp : /(^\s*(.*)\s*\n?)*$/m,
linkRegExp : /(((h?t)?tps?|h..ps?|ftp|((\uff48)?\uff54)?\uff54\uff50(\uff53)?|\uff48..\uff50(\uff53)?|\uff46\uff54\uff50)(:\/\/|\uff1a\/\/|:\uff0f\uff0f|\uff1a\uff0f\uff0f)[-_.!~*'()|a-zA-Z0-9;:\/?,@&=+$%#\[\]\uff0d\uff3f\u301c\uffe3\uff0e\uff01\uff5e\uff0a\u2019\uff08\uff09\uff5c\uff41-\uff5a\uff21-\uff3a\uff10-\uff19\uff1b\uff1a\uff0f\uff1f\uff1a\uff20\uff06\uff1d\uff0b\uff04\uff0c\uff05\uff03\uff5c\uff3b\uff3d]*[-_.!~*)|a-zA-Z0-9;:\/?@&=+$%#\[\]\uff0d\uff3f\u301c\uffe3\uff0e\uff01\uff5e\uff0a\u2019\uff5c\uff41-\uff5a\uff21-\uff3a\uff10-\uff19\uff1b\uff1a\uff0f\uff1f\uff20\uff06\uff1d\uff0b\uff04\uff0c\uff05\uff03\uff5c\uff3b\uff3d]+)/i,
localLinkRegExp: /(file|localhost):\/\/.+/i,
currentRegExp : /^\s*(data:|\(?javascript:)/i,
xpiLinkRegExp : /(.+)\.(xpi|jar)$/i,
imageLinkRegExp: /(.+)\.(png|jpg|jpeg|gif|bmp)$/i,
get ioService() {
delete this.ioService;
return this.ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
},
get fileHandler() {
delete this.fileHandler;
return this.fileHandler = this.ioService.getProtocolHandler("file")
.QueryInterface(Ci.nsIFileProtocolHandler);
},
//appPathをparamsで開く, paramsはtxtで置き換えcharsetに変換される
launch: function launch(txt, appPath, params, charset){
var UI = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Ci.nsIScriptableUnicodeConverter);
UI.charset = charset;
var appfile = Cc['@mozilla.org/file/local;1']
.createInstance(Ci.nsIFile);
appfile.initWithPath(decodeURIComponent(escape(appPath)));
if (!appfile.exists()){
alert("Executable does not exist.");
return;
}
var process = Cc['@mozilla.org/process/util;1']
.createInstance(Ci.nsIProcess);
var args = new Array();
for(var i=0,len=params.length;i<len;i++){
if(params[i]){
args.push(UI.ConvertFromUnicode(params[i].replace(/%%URL%%/i,txt).replace(/%%SEL%%/i,txt)));
}
}
process.init(appfile);
process.run(false, args, args.length, {});
},
//選択文字列を得る
get selection() {
var targetWindow = this.focusedWindow;
var sel = targetWindow.getSelection();
if (sel && !sel.toString()) {
var node = document.commandDispatcher.focusedElement;
if (node &&
((typeof node.mozIsTextField == 'function' && node.mozIsTextField(true)) ||
node.type == "search" ||
node.type == "text" || node.type == "textarea") &&
'selectionStart' in node &&
node.selectionStart != node.selectionEnd) {
var offsetStart = Math.min(node.selectionStart, node.selectionEnd);
var offsetEnd = Math.max(node.selectionStart, node.selectionEnd);
return node.value.substr(offsetStart, offsetEnd-offsetStart);
}
}
return sel ?
sel.toString() : "";
},
//現在のウインドウを得る
get focusedWindow() {
var win = document.commandDispatcher.focusedWindow;
if (!win || win == window)
win = window.content;
return win;
},
//検索バーを得る
get searchbar() {
return document.getElementById('searchbar');
},
//検索エンジン名から検索エンジンを得る
getEngineByName: function getEngineByName(aEngineName){
const UI = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Ci.nsIScriptableUnicodeConverter);
UI.charset = "UTF-8";
const nsIBSS = Ci.nsIBrowserSearchService;
const searchService = Cc["@mozilla.org/browser/search-service;1"].getService(nsIBSS);
if (aEngineName.toUpperCase() == "CURRENT"){
var searchbar = this.searchbar;
if (searchbar) return searchbar.currentEngine;
} else {
try {aEngineName = UI.ConvertToUnicode(aEngineName)}catch(e){}
var engine = searchService.getEngineByName(aEngineName);
if (engine) return engine;
}
//Default
return searchService.defaultEngine;
},
searchWithEngine: function searchWithEngine(texts, engines, where, addHistoryEntry){
var text = texts[0];
for (var i = 0; i < engines.length; i++) {
var engine = this.getEngineByName(engines[i]);
var submission = engine.getSubmission(text, null);
if (!submission)
return false;
var url = submission.uri.spec;
if (/tab|window/.test(where) && (
isTabEmpty(gBrowser.selectedTab) ||
this.currentRegExp.test(url)))
where = 'current';
switch (where) {
case 'tab':
case 'tabshifted':
var loadInBackground = getBoolPref("browser.tabs.loadInBackground");
if (loadInBackground) {
if (where == 'tabshifted')
where = 'tab';
else if (where == 'tab')
where = 'tabshifted'
}
if ("TreeStyleTabService" in window)
TreeStyleTabService.readyToOpenChildTab(gBrowser.selectedTab, false);
case 'current':
case 'window':
openLinkIn(submission.uri.spec,
where,
{
fromChrome:false,
allowThirdPartyFixup:false,
postData:submission.postData,
charset:null,
referrerURI:null,
relatedToCurrent:true
}
);
break;
}
where = 'tabshifted';
}
// 検索履歴に残す
if (typeof addHistoryEntry == "undefined" || addHistoryEntry)
this.updateSearchbarHistory(text);
return true;
},
//検索バーにテキストをコピー
copyToSearchBar: function copyToSearchBar(searchText){
var searchbar = this.searchbar;
if (!searchbar)
return;
searchbar.value = searchText;
},
//検索バーにテキストを追加コピー
appendToSearchBar: function appendToSearchBar(searchText){
var searchbar = this.searchbar;
if (!searchbar)
return;
searchbar.value += (searchbar.value ? " " : "") + searchText;
},
//検索バーにテキストをコピー, 疑似イベント発行
updateSearchbarHistory: function updateSearchbarHistory(searchText){
this.copyToSearchBar(searchText);
//var event = document.createEvent("UIEvents");
//event.initUIEvent("input", true, true, window, 0);
var searchbar = this.searchbar;
//searchbar.dispatchEvent(event);
if (typeof searchbar.FormHistory == "object") {
if (searchText && !PrivateBrowsingUtils.isWindowPrivate(window)) {
searchbar.FormHistory.update(
{ op : "bump",
fieldname : searchbar._textbox.getAttribute("autocompletesearchparam"),
value : searchText },
{ handleError : function(aError) {
Components.utils.reportError("Saving search to form history failed: " + aError.message);
}});
}
} else {
if (searchText) {
searchbar._textbox._formHistSvc
.addEntry(searchbar._textbox.getAttribute("autocompletesearchparam"),
searchText);
}
}
},
openUrls: function openUrls(urls, where, referrer) {
var self = this;
var doc = null;
if (referrer)
doc = content.document;
urls.forEach(function(url){
if (/tab|window/.test(where) && (
isTabEmpty(gBrowser.selectedTab) ||
self.currentRegExp.test(url)))
where = 'current';
switch (where) {
case 'tab':
case 'tabshifted':
var loadInBackground = getBoolPref("browser.tabs.loadInBackground");
if (loadInBackground) {
if (where == 'tabshifted')
where = 'tab';
else if (where == 'tab')
where = 'tabshifted'
}
if ("TreeStyleTabService" in window)
TreeStyleTabService.readyToOpenChildTab(gBrowser.selectedTab, false);
case 'current':
case 'window':
openLinkIn(url,
where,
{
fromChrome:false,
allowThirdPartyFixup:false,
postData:null,
charset:null,
referrerURI:referrer,
relatedToCurrent:true
}
);
break;
}
where = 'tabshifted';
});
return true;
},
openSaveFileModokiPopup : function openSaveFileModokiPopup(event) {
if (typeof saveFolderModoki !='undefined')
saveFolderModoki.showHotMenu(event.screenX, event.screenY);
},
openConQueryPopup: function openConQueryPopup(event) {
if (typeof cqrShowHotmenu !='undefined')
if (!this.selection) {
var dragService = Cc["@mozilla.org/widget/dragservice;1"]
.getService(Ci.nsIDragService);
var dragSession = dragService.getCurrentSession();
var sourceNode = dragSession.sourceNode;
if (sourceNode instanceof HTMLAnchorElement) {
var range = this.focusedWindow.document.createRange()
range.selectNodeContents(sourceNode)
var sel = this.focusedWindow.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
}
cqrShowHotmenu(null, event.screenX, event.screenY);
},
//ページ内検索
findWord: function findWords(word){
var findbar = (typeof gFindBar != 'undefied')
? gFindBar
:document.getElementById('FindToolbar')
if ('onFindAgainCommand' in findbar){ //fx3
if(findbar.hidden)
findbar.onFindCommand();
if("historyFindbar" in window)
historyFindbar._findField2.value = word;
findbar._findField.value = word;
var event = document.createEvent("UIEvents");
event.initUIEvent("input", true, false, window, 0);
findbar._findField.dispatchEvent(event);
}
},
browser_download_useDownloadDir : true,
browser_download_folderList : 0,
browser_download_dir : "",
setDownloadFolderPath: function(path, skipPrompt) {
this.browser_download_useDownloadDir = this.getPref('browser.download.useDownloadDir', 'bool', true);
this.browser_download_folderList = this.getPref('browser.download.folderList', 'int', 0);
this.browser_download_dir = this.getPref('browser.download.dir', 'str', '');
this.setPref('browser.download.useDownloadDir', 'bool', !skipPrompt);
this.setPref('browser.download.folderList', 'int', 2);
if(window.navigator.platform.toLowerCase().indexOf('win')>-1)
path = path.replace(/\//g, '\\');
this.setPref('browser.download.dir', 'str', path);
},
restoreDownloadFolderPath: function() {
this.setPref('browser.download.useDownloadDir', 'bool', this.browser_download_useDownloadDir);
this.setPref('browser.download.folderList', 'int', this.browser_download_folderList);
this.setPref('browser.download.dir', 'str', this.browser_download_dir);
},
saveLinkToLocal: function saveLinkToLocal(url, fname, fpath, skipPrompt) {
var dir = null;
if (!!fpath) {
this.setDownloadFolderPath(fpath, skipPrompt);
var dnldMgr = Cc["@mozilla.org/download-manager;1"]
.getService(Ci.nsIDownloadManager);
dir = dnldMgr.userDownloadsDirectory;
this.restoreDownloadFolderPath();
}
var file = null;
if (!skipPrompt) {
var nsIFilePicker = Ci.nsIFilePicker;
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(this.focusedWindow, "Select a File", nsIFilePicker.modeSave);
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterImages);
fp.appendFilters(nsIFilePicker.filterText | nsIFilePicker.filterHTML);
if (dir)
fp.displayDirectory = dir;
fp.defaultString = fname;
switch (fp.open()) {
case (nsIFilePicker.returnOK):
case (nsIFilePicker.returnReplace):
file = fp.file;
break;
case (nsIFilePicker.returnCancel):
default:
return null;
}
} else {
file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
fpath = (/\/$/.test(fpath)) ? fpath+fname :fpath+'/'+fname;
if(window.navigator.platform.toLowerCase().indexOf('win')>-1)
fpath = fpath.replace(/\//g, '\\');
file.initWithPath(fpath);
}
var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
.createInstance(Ci.nsIWebBrowserPersist);
var nsIWBPersist = Ci.nsIWebBrowserPersist;
persist.persistFlags = nsIWBPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES
| nsIWBPersist.PERSIST_FLAGS_FROM_CACHE;
var uri = Cc['@mozilla.org/network/io-service;1']
.getService(Ci.nsIIOService).newURI(url, null, null);
try {
//saveURL(url, fpath, null, false, skipPrompt, null);
let privacyContext = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsILoadContext);
if (parseInt(Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).version) < 36) {
persist.saveURI( uri, null, null, null, "", file, privacyContext);
} else {
persist.saveURI( uri, null, null, Ci.nsIHttpChannel.REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE,
null, "", file, privacyContext);
}
} catch (ex) {
alert('failed:\n' + ex);
file = null;
}
return file; // nsIFileObject or null
},
saveTextToLocal: function saveTextToLocal(text, fpath, skipPrompt) {
var dir = null;
if (!!fpath) {
this.setDownloadFolderPath(fpath, skipPrompt);
var dnldMgr = Cc["@mozilla.org/download-manager;1"]
.getService(Ci.nsIDownloadManager);
dir = dnldMgr.userDownloadsDirectory;
this.restoreDownloadFolderPath();
}
var file = null;
if (!skipPrompt) {
var nsIFilePicker = Ci.nsIFilePicker;
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(this.focusedWindow, "Select a File", nsIFilePicker.modeSave);
fp.appendFilters(nsIFilePicker.filterText | nsIFilePicker.filterImages);
fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterAll);
if (dir)
fp.displayDirectory = dir;
fp.defaultString = fpath;
switch (fp.open()) {
case (nsIFilePicker.returnOK):
case (nsIFilePicker.returnReplace):
file = fp.file;
break;
case (nsIFilePicker.returnCancel):
default:
return null;
}
} else {
file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
fpath = (/\/$/.test(fpath)) ? fpath+fname :fpath+'/'+fname;
if(window.navigator.platform.toLowerCase().indexOf('win')>-1)
fpath = fpath.replace(/\//g, '\\');
file.initWithPath(fpath);
}
var strm = Cc["@mozilla.org/network/file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
var convert = Cc['@mozilla.org/intl/scriptableunicodeconverter']
.getService(Ci.nsIScriptableUnicodeConverter);
convert.charset = "UTF-8";
text = convert.ConvertFromUnicode(text);
try {
strm.init(file, 0x02 | 0x08 | 0x20, parseInt(664, 8), 0); // write, create, truncate
strm.write(text, text.length);
strm.flush();
} catch (ex) {
alert('failed:\n' + ex);
file = null;
}
strm.close();
return file; // nsIFileObject or null
},
saveAs: function(aURL, aFileName, aReferrer, aSourceDocument){
if (aReferrer instanceof HTMLDocument) {
aReferrer = aReferrer.documentURIObject;
}
var contentType = this.getContentType(aURL, aSourceDocument);
if (this.imageLinkRegExp.test(aURL) || /^image\//i.test(contentType)) {
if (/^data:/.test(aURL)) {
saveImageURL(aURL, "index.png", null, true, false, aReferrer, aSourceDocument);
} else {
saveImageURL(aURL, null, null, false, false, aReferrer, aSourceDocument);
}
}else{
this.saveURL(aURL, aFileName, null, true, false, aReferrer, aSourceDocument);
}
},
//urlを名前を付けて保存
saveURL: function saveURL(aURL, aFileName, aFilePickerTitleKey, aShouldBypassCache,
aSkipPrompt, aReferrer, aSourceDocument) {
window.saveURL(aURL, aFileName, aFilePickerTitleKey, aShouldBypassCache,
aSkipPrompt, aReferrer, aSourceDocument)
},
editText: function editText(editor, text) {
// Get filename.
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
file.append("DnD.tmp");
file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, parseInt("664", 8));
// Write the data to the file.
var ostr = Components.classes['@mozilla.org/network/file-output-stream;1'].
createInstance(Components.interfaces.nsIFileOutputStream);
ostr.init(file, 2, 0x200, false);
if(navigator.platform == "Win32") {
// Convert Unix newlines to standard network newlines.
text = text.replace(/\n/g, "\r\n");
}
var conv = Components.classes['@mozilla.org/intl/saveascharset;1'].
createInstance(Components.interfaces.nsISaveAsCharset);
try{
conv.Init('UTF-8', 0, 0);
text = conv.Convert(text);
}catch(e){
}
ostr.write(text, text.length);
ostr.flush();
ostr.close();
// Edit the file.
editfile(editor, file.path);
// the external view source editor or null
function getExternalViewSourceEditorPath() {
try {
return Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch)
.getComplexValue("view_source.editor.path",
Components.interfaces.nsIFile).path;
}
catch (ex) {
Components.utils.reportError(ex);
}
return null;
}
function editfile(editor, filename) {
// Figure out what editor to use.
editor = editor || getExternalViewSourceEditorPath();
if (!editor) {
alert("Error_No_Editor");
return false;
}
var file = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsIFile);
file.initWithPath(editor);
if(!file.exists()){
alert("Error_invalid_Editor_file");
return false;
}
if(!file.isExecutable()){
alert("Error_Editor_not_executable");
return false;
}
// Run the editor.
var process = Components.classes["@mozilla.org/process/util;1"].
createInstance(Components.interfaces.nsIProcess);
process.init(file);
var args = [filename];
process.run(false, args, args.length); // don't block
return true;
}
},
//aURLのcontentTypeをキャッシュから得る
getContentType: function(aURL, aDoc){
var contentType = null;
var contentDisposition = null;
try {
var imageCache = Components.classes["@mozilla.org/image/tools;1"]
.getService(Components.interfaces.imgITools)
.getImgCacheForDocument(aDoc);
var props =
imageCache.findEntryProperties(makeURI(aURL, getCharsetforSave(null)));
if (props) {
contentType = props.get("type", nsISupportsCString);
contentDisposition = props.get("content-disposition",
nsISupportsCString);
}
} catch (e) {
// Failure to get type and content-disposition off the image is non-fatal
}
return contentType;
},
//ファイルのパスをインプットフィールドに記入
putMultipleFilePath: function putMultipleFilePath(inputElement, URLs) {
var self = this;
var multiFile = [];
URLs.forEach(function(url) {
var path = self.fileHandler.getFileFromURLSpec(url).path;
// 重複チェック
var flg = false;
for (var j = 0; j < multiFile.length; j++) {
if (multiFile[j] == path)
flg = true;
}
if (!flg)
multiFile.push(path);
});
inputElement.mozSetFileNameArray(multiFile, multiFile.length);
},
putFilePath: function putFilePath(inputElement, url){
var aFile = this.fileHandler.getFileFromURLSpec(url);
if ("mozSetFileNameArray" in inputElement)
inputElement.mozSetFileNameArray([aFile.path], 1);
else
inputElement.value = aFile.path;
},
//Xpiのインストール
installXpi: function installXpi(URLs){
function buildNextInstall() {
if (pos == URLs.length) {
if (installs.length > 0) {
AddonManager.installAddonsFromWebpage("application/x-xpinstall", window, null, installs);
}
return;
}
AddonManager.getInstallForURL(URLs[pos++], function (aInstall) {installs.push(aInstall);buildNextInstall();}, "application/x-xpinstall");
}
var self = this;
if (typeof InstallTrigger != 'undefined') {
var xpinstallObj = {};
URLs.forEach(function(url){
url = self.getDroppedURL_Fixup(url);
if (url && self.xpiLinkRegExp.test(url)){
var name =url.match(self.xpiLinkRegExp)[1] || url;
xpinstallObj[name] = url;
}
});
InstallTrigger.install(xpinstallObj);
} else {
// xxx Firefox4.0b5pre
var pos = 0;
var installs = [];
buildNextInstall();
}
},
//URLのfixUP
getDroppedURL_Fixup: function getDroppedURL_Fixup(url) {
if(!url) return null;
if (/^h?.?.p(s?):(.+)$/i.test(url)){
url = "http" + RegExp.$1 + ':' + RegExp.$2;
if(!RegExp.$2) return null;
}
var URIFixup = Components.classes['@mozilla.org/docshell/urifixup;1']
.getService(Components.interfaces.nsIURIFixup);
try{
url = URIFixup.createFixupURI(url, URIFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP ).spec;
// valid urls don't contain spaces ' '; if we have a space it
// isn't a valid url, or if it's a javascript: or data: url,
// bail out
if (!url ||
!url.length ||
url.indexOf(" ", 0) != -1 ||
/^\s*javascript:/.test(url) ||
/^\s*data:/.test(url) && !/^\s*data:image\//.test(url))
return null;
return url;
}catch(e){
return null;
}
},
//ステータスバーに文字列を表示, timeToClearミリ秒後自動クリア
setStatusMessage: function setStatusMessage(msg, timeToClear, hideDirectionChain) {
const UI = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Ci.nsIScriptableUnicodeConverter);
UI.charset = "UTF-8";
var status4ever = document.getElementById("status4evar-status-text");
if (status4ever) {
try{
try {msg = UI.ConvertToUnicode(msg)}catch(e){}
if(msg!=''){
status4ever.value = ((!hideDirectionChain)?(this.directionChain + ' : '):'')
+ msg;
}else{
status4ever.value = '';
}
}catch(e){
status4ever.value = '';
}
if(this._timer)
clearTimeout(this._timer);
this._timer = setTimeout(function(){
status4ever.value = UI.ConvertToUnicode('');
}, !timeToClear ? 1500 : timeToClear);
} else {
var statusbar = XULBrowserWindow.statusTextField || document.getElementById("statusbar-display");
try{
try {msg = UI.ConvertToUnicode(msg)}catch(e){}
if(msg!=''){
statusbar.label = ((!hideDirectionChain)?(this.directionChain + ' : '):'')
+ msg;
}else{
statusbar.label = '';
}
}catch(e){
statusbar.label = '';
}
if(this._timer)
clearTimeout(this._timer);
this._timer = setTimeout(function(){
statusbar.label = UI.ConvertToUnicode('');
}, !timeToClear ? 1500 : timeToClear);
}
},
//prefを読み込み
getPref: function(aPrefString, aPrefType, aDefault){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch);
try{
switch (aPrefType){
case 'complex':
return xpPref.getComplexValue(aPrefString, Components.interfaces.nsIFile); break;
case 'str':
return xpPref.getCharPref(aPrefString).toString(); break;
case 'int':
return xpPref.getIntPref(aPrefString); break;
case 'bool':
default:
return xpPref.getBoolPref(aPrefString); break;
}
}catch(e){
}
return aDefault;
},
//prefを書き込み
setPref: function(aPrefString, aPrefType, aValue){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch);
try{
switch (aPrefType){
case 'complex':
return xpPref.setComplexValue(aPrefString, Components.interfaces.nsIFile, aValue); break;
case 'str':
return xpPref.setCharPref(aPrefString, aValue); break;
case 'int':
aValue = parseInt(aValue);
return xpPref.setIntPref(aPrefString, aValue); break;
case 'bool':
default:
return xpPref.setBoolPref(aPrefString, aValue); break;
}
}catch(e){
}
return null;
},
// Gather all descendent text under given document node.
gatherTextUnderButNotAlt: function( root ) {
var text = "";
var node = root.firstChild;
var depth = 1;
while ( node && depth > 0 ) {
// See if this node is text.
if ( node.nodeType == Node.TEXT_NODE ) {
// Add this text to our collection.
text += " " + node.data;
}
// Find next node to test.
// First, see if this node has children.
if ( node.hasChildNodes() ) {
// Go to first child.
node = node.firstChild;
depth++;
} else {
// No children, try next sibling.
if ( node.nextSibling ) {
node = node.nextSibling;
} else {
// Last resort is our next oldest uncle/aunt.
node = node.parentNode.nextSibling;
depth--;
}
}
}
// Strip leading whitespace.
text = text.replace( /^\s+/, "" );
// Strip trailing whitespace.
text = text.replace( /\s+$/, "" );
// Compress remaining whitespace.
text = text.replace( /\s+/g, " " );
return text;
},
getVer: function(){
var info = Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIXULAppInfo);
var ver = parseInt(info.version.substr(0,3) * 10,10) / 10;
return ver;
},
getElementsByXPath: function getNodesFromXPath(aXPath, aContextNode) {
const XULNS = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
const XHTMLNS = 'http://www.w3.org/1999/xhtml';
const XLinkNS = 'http://www.w3.org/1999/xlink';
// 引数の型チェック。
if (aXPath) {
aXPath = String(aXPath);
}
else {
throw 'ERROR: blank XPath expression';
}
if (aContextNode) {
try {
if (!(aContextNode instanceof Node))
throw '';
}
catch(e) {
throw 'ERROR: invalid context node';
}
}
const xmlDoc = aContextNode ? aContextNode.ownerDocument : document ;
const context = aContextNode || xmlDoc.documentElement;
const type = XPathResult.ORDERED_NODE_SNAPSHOT_TYPE;
const resolver = {
lookupNamespaceURI : function(aPrefix)
{
switch (aPrefix)
{
case 'xul':
return XULNS;
case 'html':
case 'xhtml':