This repository has been archived by the owner on Mar 5, 2019. It is now read-only.
forked from ithinc/tabutils
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtabutils.js
3548 lines (3091 loc) · 139 KB
/
tabutils.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
var tabutils = {
init: function() {
this._tabEventListeners.init();
this._PlacesUtilsExt();
this._openUILinkInTab();
this._openLinkInTab();
this._singleWindowMode();
this._tabOpeningOptions();
this._tabClosingOptions();
this._tabClickingOptions();
this._unreadTab();
this._protectAndLockTab();
this._faviconizeTab();
this._pinTab();
this._phantomTabs();
this._renameTab();
this._restartTab();
this._reloadEvery();
this._bookmarkTabs();
this._tabView();
this._multiTabHandler();
this._stackTabs();
this._multirowTabs();
this._verticalTabs();
window.addEventListener("load", this, false);
window.addEventListener("unload", this, false);
if (typeof gBrowser._tabListeners === "object") { // Bug 1238685 [Fx46]
let tabFilters = gBrowser._tabFilters.values().next().value;
let tabListener = gBrowser._tabListeners.values().next().value;
gBrowser.browsers[0].webProgress.removeProgressListener(tabFilters);
tabFilters.removeProgressListener(tabListener);
tabListener = gBrowser.mTabProgressListener(tabListener.mTab, tabListener.mBrowser, tabListener.mBlank);
tabFilters.addProgressListener(tabListener, Ci.nsIWebProgress.NOTIFY_ALL);
gBrowser.browsers[0].webProgress.addProgressListener(tabFilters, Ci.nsIWebProgress.NOTIFY_ALL);
}
else if (gBrowser.mTabListeners.length > 0) { // Bug 463384 [Fx5]
let tabFilters = gBrowser.mTabFilters[0];
let tabListener = gBrowser.mTabListeners[0];
gBrowser.browsers[0].webProgress.removeProgressListener(tabFilters);
tabFilters.removeProgressListener(tabListener);
tabListener = gBrowser.mTabProgressListener(tabListener.mTab, tabListener.mBrowser, tabListener.mBlank);
tabFilters.addProgressListener(tabListener, Ci.nsIWebProgress.NOTIFY_ALL);
gBrowser.browsers[0].webProgress.addProgressListener(tabFilters, Ci.nsIWebProgress.NOTIFY_ALL);
}
if (!("privateBrowsingEnabled" in gPrivateBrowsingUI)) { // Bug 799001 [Fx20]
XPCOMUtils.defineLazyGetter(gPrivateBrowsingUI, "privateBrowsingEnabled", function() {
return PrivateBrowsingUtils.isWindowPrivate(window);
});
}
this.fxOnOS = Services.appinfo.OS; //WINNT, Linux or Darwin
this.fxVersion = parseFloat(Services.appinfo.version);
document.documentElement.setAttribute("OS", this.FxOnOS);
document.documentElement.setAttribute("v4", true);
document.documentElement.setAttribute("v6", true);
document.documentElement.setAttribute("v14", true);
document.documentElement.setAttribute("v17", true);
document.documentElement.setAttribute("v29", this.fxVersion >= 29.0);
document.documentElement.setAttribute("v31", this.fxVersion >= 31.0);
document.documentElement.setAttribute("v45", this.fxVersion >= 45.0);
gBrowser.mTabContainer._originalAdjustTabstripFunc = gBrowser.mTabContainer.adjustTabstrip;
gBrowser.mTabContainer.adjustTabstrip = function adjustTabstrip() {
this._originalAdjustTabstripFunc();
}
// Function.prototype.__defineGetter__("stack", function() {
// var stack = [];
// for (let caller = this; caller && stack.length < 15; caller = caller.caller) {
// stack.push(caller.name);
// }
// return stack;
// });
//
// TU_hookCode("gBrowser.addTab", "{", "Cu.reportError([arguments.callee.stack, aURI]);");
// TU_hookCode("gBrowser.moveTabTo", "{", "Cu.reportError([arguments.callee.stack, aTab._tPos, aIndex]);");
// TU_hookCode("gBrowser._beginRemoveTab", "{", "Cu.reportError([arguments.callee.stack]);");
// TU_hookCode("gBrowser._endRemoveTab", "{", "Cu.reportError([arguments.callee.stack]);");
// TU_hookCode("gBrowser._blurTab", "{", "Cu.reportError([arguments.callee.stack]);");
//
// TU_hookCode("gBrowser.pinTab", "{", "Cu.reportError([arguments.callee.stack]);");
// TU_hookCode("gBrowser.mTabContainer.adjustTabstrip", "{", "Cu.reportError([arguments.callee.stack]);");
// TU_hookCode("gBrowser.mTabContainer.positionPinnedTabs", "{", "Cu.reportError([arguments.callee.stack]);");
// TU_hookCode("gBrowser.mTabContainer.stylePinnedTabs", "{", "Cu.reportError([arguments.callee.stack]);");
},
onload: function() {
this._miscFeatures();
this._mainContextMenu();
this._tabContextMenu();
this._allTabsPopup();
this._hideTabBar();
this._undoCloseTabButton();
this._tabPrefObserver.init();
this._tagsFolderObserver.init();
this._firstRun();
},
setAttribute: function(aTab, aAttr, aVal) {
if (!aVal)
return this.removeAttribute(aTab, aAttr);
aTab.setAttribute(aAttr, aVal);
this._ss.setTabValue(aTab, aAttr, String(aVal));
},
removeAttribute: function(aTab, aAttr) {
aTab.removeAttribute(aAttr);
this._ss.deleteTabValue(aTab, aAttr);
},
restoreAttribute: function(aTab, aAttr) {
let aVal = this._ss.getTabValue(aTab, aAttr);
if (aVal)
aTab.setAttribute(aAttr, aVal);
else
aTab.removeAttribute(aAttr);
},
getURIsForTag: function() this._tagsFolderObserver.getURIsForTag.apply(this._tagsFolderObserver, arguments),
getTagsForURI: function() this._tagsFolderObserver.getTagsForURI.apply(this._tagsFolderObserver, arguments),
getDomainFromURI: function(aURI, aAllowThirdPartyFixup) {
try {
if (typeof aURI == "string")
aURI = Services.nsIURIFixup.createFixupURI(aURI, aAllowThirdPartyFixup);
}
catch (e) {}
try {
return Services.eTLD.getBaseDomain(aURI);
}
catch (e) {}
try {
return aURI.host;
}
catch (e) {
return aURI.spec;
}
},
get _styleSheet() {
for (let sheet of Array.slice(document.styleSheets)) {
if (sheet.href == "chrome://tabutils/skin/tabutils.css") {
delete this._styleSheet;
return this._styleSheet = sheet;
}
}
return document.styleSheets[0];
},
insertRule: function(rule) {
var ss = this._styleSheet;
return ss.cssRules[ss.insertRule(rule, ss.cssRules.length)];
},
_eventListeners: [],
addEventListener: function() {
arguments[0].addEventListener.apply(arguments[0], Array.slice(arguments, 1));
this._eventListeners.push(arguments);
},
onunload: function() {
this._eventListeners.forEach(function(args) document.removeEventListener.apply(args[0], Array.slice(args, 1)));
this._tagsFolderObserver.uninit();
},
handleEvent: function(event) {
window.removeEventListener(event.type, this, false);
switch (event.type) {
case "DOMContentLoaded": this.init();break;
case "load": this.onload();break;
case "unload": this.onunload();break;
}
}
};
window.addEventListener("DOMContentLoaded", tabutils, false);
[
["@mozilla.org/browser/sessionstore;1", "nsISessionStore", "_ss", tabutils], // Bug 898732 [Fx26]
["@mozilla.org/docshell/urifixup;1", "nsIURIFixup"], // Bug 802026 [Fx20]
["@mozilla.org/places/colorAnalyzer;1", "mozIColorAnalyzer"],
["@mozilla.org/widget/clipboardhelper;1", "nsIClipboardHelper"],
["@mozilla.org/uuid-generator;1", "nsIUUIDGenerator"]
].forEach(function([aContract, aInterface, aName, aObject])
XPCOMUtils.defineLazyServiceGetter(aObject || Services, aName || aInterface, aContract, aInterface)
);
tabutils._tabEventListeners = {
init: function() {
TU_hookCode("gBrowser.addTab",
["{", "if (!aURI) aURI = 'about:blank';"],
[/(?=var evt)/, function() {
t.arguments = {
aURI: aURI,
aReferrerURI: aReferrerURI,
aRelatedToCurrent: aRelatedToCurrent
};
}]
);
gBrowser.onTabOpen = function onTabOpen(aTab) {
var aURI, aReferrerURI, aRelatedToCurrent;
if (aTab.arguments) {
aURI = aTab.arguments.aURI;
aReferrerURI = aTab.arguments.aReferrerURI;
aRelatedToCurrent = aTab.arguments.aRelatedToCurrent;
}
var uri, tags = [];
try {
uri = makeURI(aURI);
}
catch (e) {
uri = makeURI("about:blank");
}
if (uri.spec != "about:blank")
tags = tabutils.getTagsForURI(uri, {});
};
gBrowser.onLocationChange = function onLocationChange(aTab) {
var uri = aTab.linkedBrowser.currentURI;
var tags = tabutils.getTagsForURI(uri, {});
};
TU_hookCode("gBrowser.mTabProgressListener", /(?=.*isBlankPageURL.*)/, function() {
if (!isBlankPageURL(this.mBrowser.currentURI.spec) &&
(!this.mBrowser.lastURI || isBlankPageURL(this.mBrowser.lastURI.spec)) &&
!this.mBrowser.__SS_data) // Bug 867097 [Fx28]
this.mTabBrowser.onLocationChange(this.mTab);
});
gBrowser.onTabMove = function onTabMove(aTab, event) {};
gBrowser.onTabClose = function onTabClose(aTab) {};
gBrowser.onTabSelect = function onTabSelect(aTab) {};
gBrowser.onTabPinning = function onTabPinning(aTab) {};
gBrowser.onTabPinned = function onTabPinned(aTab) {};
gBrowser.onTabHide = function onTabHide(aTab) {};
gBrowser.onTabShow = function onTabShow(aTab) {};
gBrowser.onTabStacked = function onTabStacked(aTab) {};
gBrowser.onTabUnstacked = function onTabUnstacked(aTab) {};
gBrowser.onStackCollapsed = function onStackCollapsed(aTab) {};
gBrowser.onStackExpanded = function onStackExpanded(aTab) {};
gBrowser.onTabRestoring = function onTabRestoring(aTab) {var ss = tabutils._ss;};
gBrowser.onTabRestored = function onTabRestored(aTab) {var ss = tabutils._ss;};
gBrowser.onTabClosing = function onTabClosing(aTab) {var ss = tabutils._ss;};
[
"TabOpen", "TabMove", "TabClose", "TabSelect",
"TabPinning", "TabPinned", "TabHide", "TabShow",
"TabStacked", "TabUnstacked", "StackCollapsed", "StackExpanded",
"SSTabRestoring", "SSTabRestored", "SSTabClosing"
].forEach(function(type) {
tabutils.addEventListener(gBrowser.mTabContainer, type, this, false);
}, this);
},
handleEvent: function(event) {
switch (event.type) {
case "TabOpen": gBrowser.onTabOpen(event.target);break;
case "TabMove": gBrowser.onTabMove(event.target, event);break;
case "TabClose": gBrowser.onTabClose(event.target);break;
case "TabSelect": gBrowser.onTabSelect(event.target);break;
case "TabPinning": gBrowser.onTabPinning(event.target);break;
case "TabPinned": gBrowser.onTabPinned(event.target);break;
case "TabHide": gBrowser.onTabHide(event.target);break;
case "TabShow": gBrowser.onTabShow(event.target);break;
case "TabStacked": gBrowser.onTabStacked(event.target);break;
case "TabUnstacked": gBrowser.onTabUnstacked(event.target);break;
case "StackCollapsed": gBrowser.onStackCollapsed(event.target);break;
case "StackExpanded": gBrowser.onStackExpanded(event.target);break;
case "SSTabRestoring": gBrowser.onTabRestoring(event.target);break;
case "SSTabRestored": gBrowser.onTabRestored(event.target);break;
case "SSTabClosing": gBrowser.onTabClosing(event.target);break;
}
}
};
tabutils._PlacesUtilsExt = function() {
PlacesUtils.getItemIdForTag = function getItemIdForTag(aTag) {
var tagId = -1;
var tagsResultNode = this.getFolderContents(this.tagsFolderId).root;
for (var i = 0, cc = tagsResultNode.childCount; i < cc; i++) {
var node = tagsResultNode.getChild(i);
if (node.title.toLowerCase() == aTag.toLowerCase()) {
tagId = node.itemId;
break;
}
}
tagsResultNode.containerOpen = false;
return tagId;
};
PlacesUtils.getItemIdForTaggedURI = function getItemIdForTaggedURI(aURI, aTag) {
var tagId = this.getItemIdForTag(aTag);
if (tagId == -1)
return -1;
var bookmarkIds = this.bookmarks.getBookmarkIdsForURI(aURI, {});
for (let bookmarkId of bookmarkIds) {
if (this.bookmarks.getFolderIdForItem(bookmarkId) == tagId)
return bookmarkId;
}
return -1;
};
PlacesUtils.removeTag = function removeTag(aTag) {
this.tagging.getURIsForTag(aTag).forEach(function(aURI) {
this.tagging.untagURI(aURI, [aTag]);
}, this);
};
};
tabutils._openUILinkInTab = function() {
//主页
TU_hookCode("BrowserGoHome", "browser.tabs.loadBookmarksInBackground", "extensions.tabutils.loadHomepageInBackground");
//地址栏回车键
TU_hookCode("gURLBar.handleCommand",
[/(let altEnter\s*=.+)\s*((aTriggeringEvent|event)\s*&&\s*(aTriggeringEvent\.altKey|event\.altKey))\s*&&\s*.*isTabEmpty.*;/, function() {
let newTabPref = TU_getPref('extensions.tabutils.openUrlInTab', true);
let TU_altEnter = ($2 || newTabPref) && !(($3 ? $4 : false) && newTabPref && TU_getPref('extensions.tabutils.invertAlt', true));
$1TU_altEnter;
}],
[/(?=.*openUILinkIn\(url\, where\, params.*)/, function() {
params.inBackground = TU_getPref('extensions.tabutils.loadUrlInBackground', false);
params.disallowInheritPrincipal = !mayInheritPrincipal;
params.event = aTriggeringEvent || {};
}],
[/.*loadURIWithFlags.*(?=[\s\S]*(let params[\s\S]*openUILinkIn.*))/, function(s, s1) s1.replace("where", '"current"')],
["aTriggeringEvent.preventDefault();", ""],
["aTriggeringEvent.stopPropagation();", ""]
);
// TU_hookCode("openLinkIn", /(?=let uriObj)/, "w.gURLBar.handleRevert();");
//搜索栏回车键
if (BrowserSearch.searchBar)
TU_hookCode("BrowserSearch.searchBar.handleSearchCommand",
[/(\(aEvent && aEvent.altKey\)) \^ (newTabPref)/, "($1 || $2) && !($1 && $2 && TU_getPref('extensions.tabutils.invertAlt', true)) && !isTabEmpty(gBrowser.selectedTab)"],
[/"tab"/, "TU_getPref('extensions.tabutils.loadSearchInBackground', false) ? 'background' : 'foreground'"]
);
//右键点击书签
TU_hookCode("BookmarksEventHandler.onClick",
["aEvent.button == 2", "$& && (aEvent.ctrlKey || aEvent.altKey || aEvent.metaKey || !TU_getPref('extensions.tabutils.rightClickBookmarks', 0))"],
["aEvent.button == 1", "aEvent.button > 0"],
["}", "if (aEvent.button == 2) aEvent.preventDefault();"]
);
TU_hookCode("checkForMiddleClick",
["event.button == 1", "($& || event.button == 2 && !event.ctrlKey && !event.altKey && !event.metaKey && TU_getPref('extensions.tabutils.rightClickBookmarks', 0))"],
[/.*closeMenus.*/, "{$&;event.preventDefault();}"]
);
TU_hookCode("whereToOpenLink", "e.button == 1", "e.button > 0");
//保持菜单打开
TU_hookCode("BookmarksEventHandler.onClick", /.*hidePopup.*/, "if (!(TU_getPref('extensions.tabutils.middleClickBookmarks', 0) & 4)) $&");
TU_hookCode("checkForMiddleClick", /.*closeMenus.*/, "if (!(TU_getPref('extensions.tabutils.middleClickBookmarks', 0) & 4)) $&");
TU_hookCode.call(document.getElementById("PopupAutoCompleteRichResult"), "onPopupClick",
["aEvent.button == 2", "$& && (aEvent.ctrlKey || aEvent.altKey || aEvent.metaKey || !TU_getPref('extensions.tabutils.rightClickBookmarks', 0))"],
[/.*closePopup[\s\S]*handleEscape.*/, "if (aEvent.button && TU_getPref('extensions.tabutils.middleClickBookmarks', 0) & 4) gBrowser.userTypedValue = null; else {$&}"]
);
tabutils.addEventListener(gURLBar.parentNode, "blur", function(event) {
if (gURLBar.popupOpen && TU_getPref('extensions.tabutils.middleClickBookmarks', 0) & 4) {
gURLBar._dontBlur = true;
setTimeout(function() {
gURLBar.mIgnoreFocus = true;
gURLBar.focus();
gURLBar.mIgnoreFocus = false;
gURLBar._dontBlur = false;
}, 0);
}
}, true);
};
tabutils._openLinkInTab = function() {
//强制在新标签页打开所有链接
TU_hookCode("contentAreaClick", /if[^{}]*event.button == 0[^{}]*{([^{}]|{[^{}]*}|{([^{}]|{[^{}]*})*})*(?=})/, "$&" + (function() {
if (tabutils.gOpenLinkInTab && !href.startsWith("javascript:")) {
openNewTabWith(href, linkNode.ownerDocument, null, event, false);
event.preventDefault();
return;
}
}).toString().replace(/^.*{|}$/g, ""));
TU_hookCode("nsBrowserAccess.prototype.openURI", /(?=switch \(aWhere\))/, function() {
if (tabutils.gOpenLinkInTab && !isExternal)
aWhere = Ci.nsIBrowserDOMWindow.OPEN_NEWTAB;
});
//强制在后台打开所有新标签页
TU_hookCode("gBrowser.loadOneTab", /(?=var owner)/, "bgLoad = bgLoad && !tabutils.gLoadAllInForeground || tabutils.gLoadAllInBackground;");
TU_hookCode("gBrowser.loadTabs", /(?=var owner)/, "aLoadInBackground = aLoadInBackground && !tabutils.gLoadAllInForeground || tabutils.gLoadAllInBackground;");
//强制在新标签页打开外部链接
TU_hookCode("contentAreaClick", /if[^{}]*event.button == 0[^{}]*{([^{}]|{[^{}]*}|{([^{}]|{[^{}]*})*})*(?=})/, "$&" + (function() {
if (/^(https?|ftp)/.test(href) && TU_getPref("extensions.tabutils.openExternalInTab", false)) {
let ourDomain = tabutils.getDomainFromURI(linkNode.ownerDocument.documentURIObject);
let otherDomain = tabutils.getDomainFromURI(href);
if (ourDomain != otherDomain) {
openNewTabWith(href, linkNode.ownerDocument, null, event, false);
event.preventDefault();
return;
}
}
}).toString().replace(/^.*{|}$/g, ""));
//外来链接
TU_hookCode("nsBrowserAccess.prototype.openURI", '"browser.link.open_newwindow"', 'isExternal ? "browser.link.open_external" : $&');
// L-click
TU_hookCode("contentAreaClick", /.*handleLinkClick.*/g, "if (event.button || event.ctrlKey || event.altKey || event.shiftKey || event.metaKey) $&");
TU_hookCode("handleLinkClick", "current", "null");
// M-click
TU_hookCode("openNewTabWith", "aEvent.shiftKey", "$& ^ (aEvent.button == 1 && TU_getPref('extensions.tabutils.middleClickLinks', 0) & 2) > 0");
// R-Click
TU_hookCode("contentAreaClick",
["event.button == 2", "$& && (event.ctrlKey || event.altKey || event.metaKey || !TU_getPref('extensions.tabutils.rightClickLinks', 0))"]
);
TU_hookCode("handleLinkClick",
["event.button == 2", "false"],
["event.preventDefault();", 'document.getElementById("contentAreaContextMenu").hidePopup();$&', 'g']
);
TU_hookCode("openNewTabWith", "aEvent.button == 1", "aEvent.button > 0");
//拖曳链接
TU_hookCode("handleDroppedLink", /.*loadURI.*/, function(s) (function() {
{
switch (true) {
case /\.(xpi|user\.js)$/.test(typeof data == "object" ? data.url : uri): // Bug 846635 [Fx25]
case !TU_getPref("extensions.tabutils.dragAndGo", true):
$0;break;
case event.ctrlKey != TU_getPref("extensions.tabutils.invertDrag", false):
BrowserSearch.loadSearch(name || url, true);break;
default:
openNewTabWith(typeof data == "object" ? data.url : uri, null, typeof data == "object" ? data.postData : postData.value, event, true, event.target.ownerDocument.documentURIObject);break;
}
}
}).toString().replace(/^.*{|}$/g, "").replace("$0", s));
// For Fx51 and earlier
// The following edition applies to bug 92737 [Fx52] changes and later.
TU_hookCode("handleDroppedLink", /.*urls\.push\([\s\S]*?postData.*/g, function(s) (function() {
{
switch (true) {
case /\.(xpi|user\.js)$/.test(data.url): // Bug 846635 [Fx25]
case !TU_getPref("extensions.tabutils.dragAndGo", true):
$0;break;
case event.ctrlKey != TU_getPref("extensions.tabutils.invertDrag", false):
BrowserSearch.loadSearch(name || link.url, true);break;
default:
openNewTabWith(data.url, null, data.postData, event, true);break; // ", event.target.ownerDocument.documentURIObject" will break for example drop an local file (file:///) to about:newtab page, blocked for security reasons.
}
}
}).toString().replace(/^.*{|}$/g, "").replace("$0", s));
for (let b of gBrowser.browsers) {
b.droppedLinkHandler = handleDroppedLink;
}
//在新标签页打开链接时继承历史
TU_hookCode("gBrowser.loadOneTab",
["{", function() {
var currentTab = this.mCurrentTab;
}],
[/(?=return tab;)/, function() {
if (aReferrerURI && TU_getPref("extensions.tabutils.openLinkWithHistory", false)) {
let currentHistory = currentTab.linkedBrowser.sessionHistory;
let newHistory = tab.linkedBrowser.sessionHistory.QueryInterface(Ci.nsISHistoryInternal);
for (let i = 0; i <= currentHistory.index; i++) {
newHistory.addEntry(currentHistory.getEntryAtIndex(i, false), true);
}
}
}]
);
};
//单窗口模式
tabutils._singleWindowMode = function() {
if (TU_getPref("extensions.tabutils.singleWindowMode", false)) {
var win = (function() {
var winEnum = Services.wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
while (winEnum.hasMoreElements()) {
var win = winEnum.getNext();
if (win != window && win.toolbar.visible)
return win;
}
})();
if (win) {
TU_hookFunc((gBrowserInit.onLoad + gBrowserInit._delayedStartup).toString().match(/^.*{|if \(uriToLoad.*{([^{}]|{[^{}]*}|{([^{}]|{[^{}]*})*})*}|}$/g).join("\n"), // Bug 756313 [Fx19]
["{", "var uriToLoad = {window.arguments && window.arguments[0]};"],
["gBrowser.loadTabs(specs, false, true);", "this.gBrowser.loadTabs(specs, false, false);"],
["loadOneOrMoreURIs(uriToLoad);", "this.gBrowser.loadTabs(uriToLoad.split('|'), false, false);"],
[/.*loadURI.*\n.*/, "this.gBrowser.loadOneTab(uriToLoad, window.arguments[2], window.arguments[1] && window.arguments[1].split('=')[1], window.arguments[3] || null, false, window.arguments[4] || false);"],
[/.*swapBrowsersAndCloseOther.*/, "return;"],
["}", "if (uriToLoad) window.close();"]
).apply(win);
}
}
tabutils._tabPrefObserver.singleWindowMode = function() {
if (TU_getPref("extensions.tabutils.singleWindowMode", false)) {
if (TU_getPref("browser.link.open_external", 3) == 2)
TU_setPref("browser.link.open_external", 3);
if (TU_getPref("browser.link.open_newwindow") == 2)
TU_setPref("browser.link.open_newwindow", 3);
if (TU_getPref("browser.link.open_newwindow.override.external") == 2) // Bug 509664 [Fx10]
TU_setPref("browser.link.open_newwindow.override.external", 3);
if (TU_getPref("browser.link.open_newwindow.restriction") != 0)
TU_setPref("browser.link.open_newwindow.restriction", 0);
}
};
TU_hookCode("OpenBrowserWindow", "{", function() {
if (TU_getPref("extensions.tabutils.singleWindowMode", false)
&& typeof options != "object") // .remote for non-e10s; .private (window)
return BrowserOpenTab() || gBrowser.getLastOpenedTab();
});
TU_hookCode("undoCloseWindow", "{", function() {
if (TU_getPref("extensions.tabutils.singleWindowMode", false))
return undoCloseTab(aIndex);
});
TU_hookCode("openNewWindowWith", "{", function() {
if (TU_getPref("extensions.tabutils.singleWindowMode", false))
return openNewTabWith(aURL, aDocument, aPostData, null, aAllowThirdPartyFixup, aReferrer);
});
TU_hookCode("openLinkIn", /(?=.*getTopWin.*)/, function() {
if (where == "window" && TU_getPref("extensions.tabutils.singleWindowMode", false))
where = "tab";
});
TU_hookCode("nsBrowserAccess.prototype.openURI", /(?=switch \(aWhere\))/, function() {
if (aWhere == Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW && TU_getPref("extensions.tabutils.singleWindowMode", false))
aWhere = Ci.nsIBrowserDOMWindow.OPEN_NEWTAB;
});
TU_hookCode("gBrowser.replaceTabWithWindow", "{", function() {
if (TMP_console.isCallerInList(["_onDragEnd", "onxbldragend"]) && TU_getPref("extensions.tabutils.singleWindowMode", false))
return null;
});
tabutils.addEventListener(window, "popupshown", function(event) {
var singleWindowMode = TU_getPref("extensions.tabutils.singleWindowMode", false);
[
"appmenu_newNavigator",
"appmenu_newPrivateWindow",
"appmenu_recentlyClosedWindowsMenu",
"menu_newNavigator",
"menu_newPrivateWindow",
"historyUndoWindowMenu",
"context-openlink",
"context-openlinkprivate",
"context-openframe",
"placesContext_open:newwindow"
].forEach(function(aId) {
var item = event.originalTarget.getElementsByAttribute("id", aId)[0];
if (item)
item.setAttribute("disabled", singleWindowMode);
});
}, false);
};
tabutils._tabOpeningOptions = function() {
//新建标签页时利用已有空白标签页
TU_hookCode("gBrowser.addTab",
[/if \(arguments.length == 2[^{}]*\) {[^{}]*}/, "$&" + (function() {
if (!isBlankPageURL(aURI)) {
let t = aFromExternal && isTabEmpty(this.selectedTab) && this.selectedTab || this.getBlankTab();
if (t) {
let b = this.getBrowserForTab(t);
return t;
}
}
}).toString().replace(/^.*{|}$/g, "")],
[/(?=return t;)/, gBrowser.addTab.toString().match(
/var (?:uriIsBlankPage|uriIsNotAboutBlank|uriIsAboutBlank).*|let (?:options|browserParams) = \{[\s\S]*?dispatchEvent.+;|if.+!usingPreloadedContent[\s\S]*catch[^}]+?\}[^}]+?\}|let (docShellsSwapped|usingPreloadedContent)[\s\S]*(?=\n.*(docShellsSwapped|usingPreloadedContent).*)|if \((uriIsNotAboutBlank|.*uriIsAboutBlank)\) {([^{}]|{[^{}]*})*}/g
).join("\n").replace(/(?:var|let) b\s*=/, "b =")]
); // Bug 716108 [Fx16], Bug 1077652 [Fx37], Bug 1243707 [Fx48], etc. Grab all about preload tab, open tab, barring select tab.
gBrowser.getBlankTab = function getBlankTab() {
var reuseBlank = TU_getPref("extensions.tabutils.reuseBlank", 1);
return reuseBlank & 1 && this.isBlankTab(this.mCurrentTab) ? this.mCurrentTab :
reuseBlank & 2 && this.isBlankTab(this.mTabContainer.lastChild) ? this.mTabContainer.lastChild :
reuseBlank & 4 ? this.getFirstBlankTabBut() : null;
};
gBrowser.getFirstBlankTabBut = function getFirstBlankTabBut(aTab) {
for (let tab of this.visibleTabs) {
if (tab != aTab && this.isBlankTab(tab))
return tab;
}
};
gBrowser.isBlankTab = function isBlankTab(aTab) {
return this.isBlankBrowser(aTab.linkedBrowser)
&& ["busy", "pending"].every(function(aAttr) !aTab.hasAttribute(aAttr));
};
gBrowser.isBlankBrowser = function isBlankBrowser(aBrowser) {
return (!aBrowser.currentURI || isBlankPageURL(aBrowser.currentURI.spec))
&& (!aBrowser.sessionHistory || aBrowser.sessionHistory.count < 2)
&& (!aBrowser.webProgress || !aBrowser.webProgress.isLoadingDocument);
};
TU_hookCode("isBlankPageURL", 'aURL == "about:blank"', "gInitialPages.indexOf(aURL) > -1");
//自动关闭非主动打开的空白标签页
TU_hookCode("gBrowser.mTabProgressListener", /(?=var location)/, function() {
if (aWebProgress.DOMWindow.document.documentURI == "about:blank"
&& aRequest.QueryInterface(nsIChannel).URI.spec != "about:blank"
&& aStatus == 0
&& TU_getPref("extensions.tabutils.removeUnintentionalBlank", true)) {
let win = aWebProgress.DOMWindow;
win._closeTimer = win.setTimeout(function() {
this.mTabBrowser.isBlankTab(this.mTab) && this.mTabBrowser.removeTab(this.mTab);
}.bind(this), 750);
}
});
// Not understand the purpose of the module,
// and it has been broken since Firefox 38.
// https://hg.mozilla.org/releases/mozilla-aurora/diff/120b108aa176/toolkit/mozapps/downloads/DownloadLastDir.jsm [Bug 1115248]
/*
let tmp = {};
Cu.import("resource://gre/modules/DownloadLastDir.jsm", tmp);
if (tmp.DownloadLastDir && // Bug 722995 [Fx19]
tmp.DownloadLastDir.prototype.getFileAsync && // Bug 854299 [Fx23]
tmp.DownloadLastDir.prototype.getFileAsync.name != "TU_getFileAsync")
tmp.DownloadLastDir.prototype.getFileAsync = (function() {
let getFileAsync = tmp.DownloadLastDir.prototype.getFileAsync;
return function TU_getFileAsync(aURI, aCallback) {
let win = this.window;
if (win._closeTimer) {
win.clearTimeout(win._closeTimer);
win._closeTimer = null;
aCallback = (function() {
let lastDirCallback = aCallback;
return function TU_LastDirCallback(lastDir) {
lastDirCallback(lastDir);
if (!win.closed) {
win.setTimeout(win.close, 250);
}
};
})();
}
getFileAsync.apply(this, arguments);
};
})();
*/
//在当前标签页的右侧打开新标签页
//连续打开后台标签时保持原有顺序
TU_hookCode("gBrowser.addTab",
[/\S*insertRelatedAfterCurrent\S*(?=\))/, "false"], // replace "getBoolPref("browser.tabs.insertRelatedAfterCurrent")"
[/(?=(return t;)(?![\s\S]*\1))/, function() {
if (t.hasAttribute("opener")) {
function shouldStack(tab) { let args = tab.arguments; return args.aReferrerURI || args.aRelatedToCurrent && args.aURI != "about:blank"; }
let lastRelatedTab = this.mCurrentTab;
let isStack = this.isStackedTab(lastRelatedTab);
let willStack = (isStack || TU_getPref("extensions.tabutils.autoStack", false)) && shouldStack(t);
if (isStack && !willStack)
lastRelatedTab = this.lastSiblingTabOf(lastRelatedTab);
if (TU_getPref("extensions.tabutils.openTabNext.keepOrder", true)) {
let tab = lastRelatedTab.nextSibling;
let panelId = this.mCurrentTab.linkedPanel + "#";
for (; tab && tab.pinned; tab = tab.nextSibling);
for (; tab && tab.getAttribute("opener") == panelId && tab != t && (!willStack || shouldStack(tab)); tab = tab.nextSibling)
lastRelatedTab = tab;
}
if (willStack)
this.attachTabTo(t, lastRelatedTab, {move: true, expand: true});
this.moveTabTo(t, t._tPos > lastRelatedTab._tPos ? lastRelatedTab._tPos + 1 : lastRelatedTab._tPos);
}
}]
);
TU_hookCode("gBrowser.onTabOpen", "}", function() {
if ((function() {
switch (TU_getPref("extensions.tabutils.openTabNext", 1)) {
case 1: //All
case 2: return aRelatedToCurrent || aReferrerURI || (aURI != "about:blank" && aURI != "about:newtab"); //All but New Tab
case 3: return aRelatedToCurrent == null ? aReferrerURI : aRelatedToCurrent; //None but Links
default: return false; //None
}
})()) {
aTab.setAttribute("opener", this.mCurrentTab.linkedPanel + "#");
}
});
TU_hookCode("gBrowser.onTabPinned", "}", function() {
aTab.removeAttribute("opener");
});
TU_hookCode("gBrowser.onTabUnstacked", "}", function() {
aTab.removeAttribute("opener");
if (aTab.selected)
this.updateCurrentBrowser(true);
});
//新建标签页
if (BrowserOpenTab.name == "BrowserOpenTab") { //Compatibility with Speed Dial
TU_hookCode("BrowserOpenTab",
[/.*openUILinkIn\((.*)\)/, function(s, s1) s.replace(s1, (
s1 = s1.replace(/,\s*\{\s*relatedToCurrent\s*\}/, ""),
s1 = s1.split(","),
s1.push("{inBackground: TU_getPref('extensions.tabutils.loadNewInBackground', false)}"),
s1.push("{relatedToCurrent: TU_getPref('extensions.tabutils.openTabNext', 1) == 1}"),
s1.join().replace(/\}\s*,\s*\{/, ",")
))] // Bug 490225 [Fx11]
);
}
TU_hookCode("isBlankPageURL", "aURL == BROWSER_NEW_TAB_URL", "$& && TU_getPref('extensions.tabutils.markNewAsBlank', true)");
TU_hookCode("URLBarSetURI", "gInitialPages.indexOf(uri.spec) != -1", "isBlankPageURL(uri.spec)");
TU_hookCode("gBrowser._beginRemoveTab", /.*addTab.*/, "BrowserOpenTab();");
TU_hookCode("gBrowser._endRemoveTab", /.*addTab.*/, "BrowserOpenTab();");
gBrowser.getLastOpenedTab = function getLastOpenedTab() {
return this.mTabContainer.getElementsByAttribute("linkedpanel", this.mPanelContainer.lastChild.id)[0];
};
//复制标签页
TU_hookCode("gBrowser.duplicateTab",
[/return/g, "var tab ="],
["}", function() {
this.detachTab(tab, true);
if (TMP_console.isCallerInList(["_onDrop", "onxbldrop", "duplicateTabIn"])) {
if (TU_getPref("extensions.tabutils.openDuplicateNext", true)) {
if (this.isStackedTab(aTab))
aTab = this.lastSiblingTabOf(aTab);
this.moveTabTo(tab, tab._tPos > aTab._tPos ? aTab._tPos + 1 : aTab._tPos);
}
if (!tabutils.gLoadAllInBackground && !TU_getPref("extensions.tabutils.loadDuplicateInBackground", false))
this.selectedTab = tab;
}
return tab;
}]
);
//撤销关闭标签页
TU_hookCode("gBrowser.moveTabTo", "}", function() {
if (TMP_console.callerName() == "ssi_undoCloseTab"
&& !TU_getPref("extensions.tabutils.restoreOriginalPosition", true))
return;
});
};
tabutils._tabClosingOptions = function() {
//关闭标签页时选择左侧/右侧/第一个/最后一个标签
gBrowser._tabsToSelect = function _tabsToSelect(aTabs) {
if (!aTabs)
aTabs = this.visibleTabs;
let tabs = new Array(this.mTabs.length);
for (let tab of aTabs)
tabs[tab._tPos] = tab;
var aTab = this.mCurrentTab;
var seenTabs = [];
seenTabs[aTab._tPos] = true;
var selectOnClose = TU_getPref("extensions.tabutils.selectOnClose", 0);
if (selectOnClose & 0x80) for (let tab of _tabs_(0x80)) yield tab;
if (selectOnClose & 0x40) for (let tab of _tabs_(0x40)) yield tab;
if (selectOnClose & 0x20) for (let tab of _tabs_(0x20)) yield tab;
if (selectOnClose & 0x03) for (let tab of _tabs_(selectOnClose & 0x03)) yield tab;
if (selectOnClose & 0x1c) for (let tab of _tabs_(selectOnClose & 0x1c)) yield tab;
function _tabs_(selectOnClose) {
for (let tab of __tabs__(selectOnClose)) {
if (!(tab._tPos in seenTabs)) {
seenTabs[tab._tPos] = true;
yield tab;
}
}
}
function __tabs__(selectOnClose) {
switch (selectOnClose) {
case 1: //Left
for (let i = aTab._tPos - 1; i >= 0; i--) if (i in tabs) yield tabs[i];
break;
case 2: //Right
for (let i = aTab._tPos + 1; i < tabs.length; i++) if (i in tabs) yield tabs[i];
break;
case 4: //First
for (let i = 0; i < tabs.length; i++) if (i in tabs) yield tabs[i];
break;
case 8: //Last
for (let i = tabs.length - 1; i >= 0; i--) if (i in tabs) yield tabs[i];
break;
case 0x10: //Last selected
for (let tab of gBrowser.mTabContainer._tabHistory) if (tab._tPos in tabs) yield tab;
break;
case 0x20: //Unread
for (let tab of __tabs__()) if (tab.hasAttribute("unread")) yield tab;
break;
case 0x40: //Related
for (let tab of __tabs__()) if (gBrowser.isRelatedTab(tab, aTab)) yield tab;
break;
case 0x80: //Unread Related
for (let tab of __tabs__(0x20)) if (gBrowser.isRelatedTab(tab, aTab)) yield tab;
break;
case undefined: //Right or Rightmost
for (let i = aTab._tPos + 1; i < tabs.length; i++) if (i in tabs) yield tabs[i];
for (let i = aTab._tPos - 1; i >= 0; i--) if (i in tabs) yield tabs[i];
break;
}
}
};
gBrowser._blurTab = function _blurTab(aTab) {
if (!aTab.selected)
return this.mCurrentTab;
try {
return this.selectedTab = this._tabsToSelect().next();
}
catch (e) {
if (this.selectedTab = this.getLastSelectedTab())
return this.selectedTab;
return this.selectedTab = BrowserOpenTab() || gBrowser.getLastOpenedTab();
}
};
//关闭标签页时选择亲属标签
TU_hookCode("gBrowser.onTabSelect", "}", function() {
var panelId = aTab.linkedPanel + "#";
Array.forEach(this.visibleTabs, function(aTab) {
if (aTab.getAttribute("opener").startsWith(panelId))
aTab.setAttribute("opener", panelId + (+aTab.getAttribute("opener").slice(panelId.length) + 1));
});
});
TU_hookCode("gBrowser.onTabClose", "}", function() {
if (aTab.hasAttribute("opener")) {
let opener = aTab.getAttribute("opener");
let panelId = aTab.linkedPanel + "#";
Array.forEach(this.visibleTabs, function(aTab) {
if (aTab.getAttribute("opener").startsWith(panelId))
aTab.setAttribute("opener", opener);
});
}
});
TU_hookCode("gBrowser.loadTabs", "}", function() {
if (aURIs.length > 1)
this.updateCurrentBrowser(true);
});
gBrowser.isRelatedTab = function isRelatedTab(aTab, bTab) {
if (!bTab)
bTab = this.mCurrentTab;
return aTab.hasAttribute("opener") && aTab.getAttribute("opener") == bTab.getAttribute("opener")
|| aTab.getAttribute("opener").startsWith(bTab.linkedPanel + "#")
|| bTab.getAttribute("opener").startsWith(aTab.linkedPanel + "#");
};
//关闭标签页时选择上次浏览的标签
gBrowser.mTabContainer._tabHistory = Array.slice(gBrowser.mTabs);
TU_hookCode("gBrowser.onTabOpen", "}", function() {
var tabHistory = this.mTabContainer._tabHistory;
tabHistory.splice(1, 0, aTab);
aTab._lastAccessed = Date.now();
tabutils._ss.setTabValue(aTab, "lastAccessed", String(aTab._lastAccessed));
});
TU_hookCode("gBrowser.onTabSelect", "}", function() {
var tabHistory = this.mTabContainer._tabHistory;
lastTab = tabHistory[0];
lastTab._lastAccessed = Date.now();
tabutils._ss.setTabValue(lastTab, "lastAccessed", String(lastTab._lastAccessed));
var index = tabHistory.indexOf(aTab);
if (index > -1)
tabHistory.splice(index, 1);
tabHistory.unshift(aTab);
aTab._lastAccessed = Infinity;
tabutils._ss.setTabValue(aTab, "lastAccessed", String(aTab._lastAccessed));
});
TU_hookCode("gBrowser.onTabClose", "}", function() {
var tabHistory = this.mTabContainer._tabHistory;
var index = tabHistory.indexOf(aTab);
if (index > -1)
tabHistory.splice(index, 1);
});
TU_hookCode("gBrowser.onTabRestoring", "}", function() { // Bug 445461 [Fx30]
var tabHistory = this.mTabContainer._tabHistory;
var index = tabHistory.indexOf(aTab);
if (index > -1)
tabHistory.splice(index, 1);
if (aTab._lastAccessed == Infinity)
tabutils._ss.setTabValue(aTab, "lastAccessed", String(aTab._lastAccessed));
else
aTab._lastAccessed = tabutils._ss.getTabValue(aTab, "lastAccessed");
for (index = 0; index < tabHistory.length; index++) {
if (tabHistory[index]._lastAccessed < aTab._lastAccessed)
break;
}
tabHistory.splice(index, 0, aTab);
});
gBrowser.getLastSelectedTab = function getLastSelectedTab(aDir) {
var tabHistory = this.mTabContainer._tabHistory;
var index = tabHistory.indexOf(this.mCurrentTab);
return tabHistory[aDir < 0 ? index - 1 : index + 1]
|| tabHistory[aDir < 0 ? tabHistory.length - 1 : 0];
};
//Ctrl+Tab切换到上次浏览的标签
//Ctrl+左右方向键切换到前一个/后一个标签
tabutils.addEventListener(window, "keydown", function(event) {
if (!event.ctrlKey || event.altKey || event.metaKey)
return;
switch (event.keyCode) {
case event.DOM_VK_UP:
case event.DOM_VK_DOWN:
case event.DOM_VK_LEFT:
case event.DOM_VK_RIGHT:
if (!TU_getPref("extensions.tabutils.handleCtrlArrow"))
return;
// Fallback
case event.DOM_VK_PAGE_UP:
case event.DOM_VK_PAGE_DOWN:
if (event.shiftKey)
return;
event.stopPropagation(); // Compat. with some sites
// Fallback
case event.DOM_VK_TAB:
if (TU_getPref("extensions.tabutils.handleCtrl"))
gBrowser._previewMode = true;
break;
}
}, true);
tabutils.addEventListener(window, "keypress", function(event) {
if (!event.ctrlKey || event.altKey || event.metaKey)
return;
switch (event.keyCode) {
case event.DOM_VK_TAB:
if (TU_getPref("extensions.tabutils.handleCtrlTab")) {
gBrowser.selectedTab = gBrowser.getLastSelectedTab(event.shiftKey ? -1 : 1);
event.stopPropagation();
event.preventDefault();
}
break;
case event.DOM_VK_LEFT:
case event.DOM_VK_RIGHT:
if (!event.shiftKey && TU_getPref("extensions.tabutils.handleCtrlArrow")) {
let rtl = getComputedStyle(gBrowser.mTabContainer).direction == "rtl";
gBrowser.mTabContainer.advanceSelectedTab(event.keyCode == event.DOM_VK_LEFT ^ rtl ? -1 : 1, true);
event.stopPropagation();
event.preventDefault();
}
break;
case event.DOM_VK_UP:
case event.DOM_VK_DOWN:
if (!event.shiftKey && TU_getPref("extensions.tabutils.handleCtrlArrow")) {
gBrowser.selectedTab = gBrowser.nextSiblingTabOf(gBrowser.selectedTab, event.keyCode == event.DOM_VK_UP ? -1 : 1, true);
event.stopPropagation();
event.preventDefault();
}
break;
}
}, true);
tabutils.addEventListener(window, "keyup", function(event) {
switch (event.keyCode) {
case event.DOM_VK_LEFT:
case event.DOM_VK_RIGHT: