forked from feiruo/userChromeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabPlus.uc.js
353 lines (331 loc) · 11.2 KB
/
TabPlus.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
// ==UserScript==
// @name TabPlus
// @description 标签管理
// @modby feiruo
// @charset UTF-8
// @include chrome://browser/content/browser.xul
// @include chrome://browser/content/bookmarks/bookmarksPanel.xul
// @include chrome://browser/content/history/history-panel.xul
// @include chrome://browser/content/places/places.xul
// @include chrome://mozapps/content/downloads/unknownContentType.xul
// @include chrome://mozapps/content/downloads/downloads.xul
// @id [5C5BB610]
// @startup window.TabPlus_mod.init();
// @shutdown window.TabPlus_mod.onDestroy(true);
// @homepageURL https://github.com/feiruo/userchromejs/
// @version 0.2
// @note 新しいタブで開く(空白タブを利用)
// @note 新标签打开(智能利用空白标签)
// @note 必要なものだけ使って不要であれば削除するなりコメントアウトして下さい
// @note 不需要的功能请自行注释掉
// ==/UserScript==
(function() {
if (window.TabPlus_mod) {
window.TabPlus_mod.onDestroy();
delete window.TabPlus_mod;
}
var TabPlus_mod = {
gURLBar: gURLBar.handleCommand.toString(),
openLinkIn: openLinkIn.toString(),
whereToOpenLink: whereToOpenLink.toString(),
cKBOnMCa: BookmarksEventHandler.onClick.toString(),
cKBOnMCb: checkForMiddleClick.toString(),
cdbt: gBrowser.mTabProgressListener.toString(),
tab_hover: null,
};
TabPlus_mod.init = function() {
this.urlbarNewTab(true); // 地址栏新标签打开
this.historyNewTab(true); //新标签打开书签,历史和搜索栏
this.ldblclickC(true); //左键双击标签关闭
this.mouseScroll(true); //滚轮切换标签
this.rclickC(true); //标签上点击鼠标右键关闭标签
//this.mMousedownR(true); //标签栏空白部分中间恢复关闭的标签
//this.mMousedownP(true); //中键锁定标签
//this.ldblclickR(true); //双击标签刷新
//this.ldblclickRU(true); //未加载标签上双击刷新
//this.nearTab(true); //紧邻当前标签新建标签页
//this.cOLTab(true); //关闭标签聚焦左侧标签
//------------------------------------------------
this.whereToOpen(true); // 中クリックでフォーカスを反転
this.KeepBookmarksOnMiddleClick(true); // 鼠标中键点击时bookmark菜单不关闭
this.closeDownloadBankTab(true); // 自动关闭下载产生的空白标签
this.tabfocus(true); // 鼠标悬停激活标签
};
TabPlus_mod.onDestroy = function(isOk) {
this.urlbarNewTab(false);
this.historyNewTab(false);
this.whereToOpen(false);
this.ldblclickC(false);
this.mouseScroll(false);
this.rclickC(false);
this.mMousedownR(false);
this.mMousedownP(false);
this.ldblclickR(false);
this.ldblclickRU(false);
this.nearTab(false);
this.cOLTab(false);
this.KeepBookmarksOnMiddleClick(false);
this.closeDownloadBankTab(false);
this.tabfocus(false);
};
//--------------------------------------------------------------------------
TabPlus_mod.urlbarNewTab = function(isOk) {
if (isOk) {
try {
location == "chrome://browser/content/browser.xul" && eval("gURLBar.handleCommand=" + this.gURLBar.replace(/^\s*(load.+);/gm, "if(/^javascript:/.test(url)||isTabEmpty(gBrowser.selectedTab)){loadCurrent();}else{this.handleRevert();gBrowser.loadOneTab(url, {postData: postData, inBackground: false, allowThirdPartyFixup: true});}"));
} catch (e) {}
} else {
try {
location == "chrome://browser/content/browser.xul" && eval("gURLBar.handleCommand=" + this.gURLBar);
} catch (e) {}
}
};
TabPlus_mod.historyNewTab = function(isOk) {
if (isOk) {
try {
eval('openLinkIn=' + this.openLinkIn.replace('w.gBrowser.selectedTab.pinned', '(!w.isTabEmpty(w.gBrowser.selectedTab) || $&)').replace(/&&\s+w\.gBrowser\.currentURI\.host != uriObj\.host/, ''));
} catch (e) {}
} else {
try {
eval('openLinkIn=' + this.openLinkIn);
} catch (e) {}
}
};
TabPlus_mod.whereToOpen = function(isOk) {
if (isOk) {
try {
eval('whereToOpenLink=' + this.whereToOpenLink.replace(' || middle && middleUsesTabs', '').replace('if (alt', 'if (middle && middleUsesTabs) return shift ? "tab" : "tabshifted"; $&'));
} catch (e) {}
} else {
try {
eval('whereToOpenLink=' + this.whereToOpenLink);
} catch (e) {}
}
};
TabPlus_mod.ldblclickC = function(isOk) {
if (isOk) {
try {
gBrowser.mTabContainer.addEventListener('dblclick', TabPlus_mod.ldblclickC.acction, true);
} catch (e) {}
} else {
try {
gBrowser.mTabContainer.removeEventListener('dblclick', TabPlus_mod.ldblclickC.acction, true);
} catch (e) {}
}
};
TabPlus_mod.ldblclickC.acction = function(event) {
if (event.target.localName == 'tab' && event.button == 0)
gBrowser.removeTab(event.target);
};
TabPlus_mod.mouseScroll = function(isOk) {
if (isOk) {
try {
gBrowser.mTabContainer.addEventListener('DOMMouseScroll', TabPlus_mod.mouseScroll.acction, true);
} catch (e) {}
} else {
try {
gBrowser.mTabContainer.removeEventListener('DOMMouseScroll', TabPlus_mod.mouseScroll.acction, true);
} catch (e) {}
}
};
TabPlus_mod.mouseScroll.acction = function(event) {
this.advanceSelectedTab(event.detail > 0 ? +1 : -1, true);
};
TabPlus_mod.rclickC = function(isOk) {
if (isOk) {
try {
gBrowser.mTabContainer.addEventListener('click', TabPlus_mod.rclickC.acction, true);
} catch (e) {}
} else {
try {
gBrowser.mTabContainer.removeEventListener('click', TabPlus_mod.rclickC.acction, true);
} catch (e) {}
}
};
TabPlus_mod.rclickC.acction = function(event) {
if (event.target.localName == "tab" && event.button == 2 && !event.ctrlKey) {
gBrowser.removeTab(event.target);
event.stopPropagation();
event.preventDefault();
}
};
//--------------------------------------------------------------------------
TabPlus_mod.mMousedownR = function(isOk) {
if (isOk) {
try {
gBrowser.mTabContainer.addEventListener('mousedown', TabPlus_mod.mMousedownR.acction, false);
} catch (e) {}
} else {
try {
gBrowser.mTabContainer.removeEventListener('mousedown', TabPlus_mod.mMousedownR.acction, false);
} catch (e) {}
}
};
TabPlus_mod.mMousedownR.acction = function(event) {
if (event.target.localName != 'tab' && event.button == 1) {
document.getElementById('History:UndoCloseTab').doCommand();
}
};
TabPlus_mod.mMousedownP = function(isOk) {
if (isOk) {
try {
gBrowser.mTabContainer.addEventListener('click', TabPlus_mod.mMousedownP.acction, true);
} catch (e) {}
} else {
try {
gBrowser.mTabContainer.removeEventListener('click', TabPlus_mod.mMousedownP.acction, true);
} catch (e) {}
}
};
TabPlus_mod.mMousedownP.acction = function(event) {
if (event.target.localName == "tab" && event.button == 1 && !event.ctrlKey) {
var subTab = event.originalTarget;
while (subTab.localName != "tab") {
subTab = subTab.parentNode;
}
if (subTab.pinned) {
gBrowser.unpinTab(subTab);
} else {
gBrowser.pinTab(subTab);
}
event.stopPropagation();
event.preventDefault();
}
};
TabPlus_mod.ldblclickR = function(isOk) {
if (isOk) {
try {
gBrowser.mTabContainer.addEventListener('dblclick', TabPlus_mod.ldblclickR.acction, true);
} catch (e) {}
} else {
try {
gBrowser.mTabContainer.removeEventListener('dblclick', TabPlus_mod.ldblclickR.acction, true);
} catch (e) {}
}
};
TabPlus_mod.ldblclickR.acction = function(event) {
if (event.target.localName == 'tab' && event.button == 0) {
getBrowser().getBrowserForTab(event.target).reload();
}
};
TabPlus_mod.ldblclickRU = function(isOk) {
if (isOk) {
try {
gBrowser.mTabContainer.addEventListener('dblclick', acction, false);
} catch (e) {}
} else {
try {
gBrowser.mTabContainer.removeEventListener('dblclick', acction, false);
} catch (e) {}
}
};
TabPlus_mod.ldblclickRU.acction = function(event) {
if (event.target.localName == 'tab' && event.button == 0) {
if (event.target.hasAttribute("busy")) {
document.getElementById('cmd_close').doCommand();
} else {
getBrowser().getBrowserForTab(event.target).reload();
}
}
};
TabPlus_mod.nearTab = function(isOk) {
if (isOk) {
try {
gBrowser.tabContainer.addEventListener("TabOpen", TabPlus_mod.nearTab.acction, false);
} catch (e) {}
} else {
try {
gBrowser.tabContainer.removeEventListener("TabOpen", TabPlus_mod.nearTab.acction, false);
} catch (e) {}
}
};
TabPlus_mod.nearTab.acction = function(event) {
try {
if (!gBrowser) return;
} catch (e) {
return;
}
var tab = event.target;
gBrowser.moveTabTo(tab, gBrowser.mCurrentTab._tPos + 1);
};
TabPlus_mod.cOLTab = function(isOk) {
if (isOk) {
try {
gBrowser.tabContainer.addEventListener("TabClose", TabPlus_mod.cOLTab.acction, false);
} catch (e) {}
} else {
try {
gBrowser.tabContainer.removeEventListener("TabClose", TabPlus_mod.cOLTab.acction, false);
} catch (e) {}
}
};
TabPlus_mod.cOLTab.acction = function(event) {
try {
if (!gBrowser) return;
} catch (e) {
return;
}
var tab = event.target;
if (tab.linkedBrowser.contentDocument.URL == 'about:blank') return;
if (tab._tPos <= gBrowser.mTabContainer.selectedIndex) {
if (tab.previousSibling) {
gBrowser.mTabContainer.selectedIndex--;
}
}
};
//--------------------------------------------------------------------------
TabPlus_mod.KeepBookmarksOnMiddleClick = function(isOk) {
if (isOk) {
try {
eval('BookmarksEventHandler.onClick =' + this.cKBOnMCa.replace('node.hidePopup()', ''));
eval('checkForMiddleClick =' + this.cKBOnMCb.replace('closeMenus(event.target);', ''));
} catch (e) {}
} else {
try {
eval('BookmarksEventHandler.onClick =' + this.cKBOnMCa);
eval('checkForMiddleClick =' + this.cKBOnMCb);
} catch (e) {}
}
};
TabPlus_mod.closeDownloadBankTab = function(isOk) {
if (isOk) {
try {
eval("gBrowser.mTabProgressListener = " + this.cdbt.replace(/(?=var location)/, '\
if (aWebProgress.DOMWindow.document.documentURI == "about:blank"\
&& aRequest.QueryInterface(nsIChannel).URI.spec != "about:blank") {\
aWebProgress.DOMWindow.setTimeout(function() {\
!aWebProgress.isLoadingDocument && aWebProgress.DOMWindow.close();\
}, 100);\
}\
'));
} catch (e) {}
} else {
try {
location == eval("gBrowser.mTabProgressListener=" + this.cdbt);
} catch (e) {}
}
};
TabPlus_mod.tabfocus = function(isOk) {
if (isOk) {
try {
gBrowser.tabContainer.addEventListener("mouseout", TabPlus_mod.tabfocus.onMouseOut, false);
gBrowser.tabContainer.addEventListener("mouseover", TabPlus_mod.tabfocus.onMouseOver, false);
} catch (e) {}
} else {
try {
gBrowser.tabContainer.removeEventListener("mouseover", TabPlus_mod.tabfocus.onMouseOver, false);
gBrowser.tabContainer.removeEventListener("mouseout", TabPlus_mod.tabfocus.onMouseOut, false);
} catch (e) {}
}
};
TabPlus_mod.tabfocus.onMouseOver = function(event) {
this.tab_hover = setTimeout(function() {
gBrowser.selectedTab = event.target;
}, 250);
};
TabPlus_mod.tabfocus.onMouseOut = function() {
clearTimeout(this.tab_hover);
};
TabPlus_mod.init();
window.TabPlus_mod = TabPlus_mod;
})();