-
Notifications
You must be signed in to change notification settings - Fork 123
/
000-reuseBlankTabIfCcurrentTab.uc.js
47 lines (46 loc) · 2.33 KB
/
000-reuseBlankTabIfCcurrentTab.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
// ==UserScript==
// @name 000-reuseBlankTabIfCcurrentTab.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description Reuse Blank Tab If CcurrentTab is Blank Tab and NewTab
// @include *
// @exclude about:*
// @exclude chrome://mozapps/content/downloads/unknownContentType.xul
// @compatibility 60
// @version 2018/11/04 22:30 fix Bug 1502069, use selectedTab.isEmpty insted isTabEmpty()
// @version 2018/09/24 22:30 fix conflict with other eval, use isTabEmpty()
// @version 2018/09/23 23:30 fix variable name
// @version 2018/09/23 23:00 check tab busy flag
// @version 2018/09/23 16:00
// ==/UserScript==
if (window.openLinkIn && !/reuseBlankTabIfCcurrentTab_org/.test(window.openLinkIn.toString())) {
window.openLinkIn_reuseBlankTabIfCcurrentTab_org = window.openLinkIn;
window.openLinkIn = function(url, where, params) {
var mainWindow = (typeof BrowserWindowTracker != "undefined") ? BrowserWindowTracker.getTopWindow(): Services.wm.getMostRecentWindow("navigator:browser");
if (("isTabEmpty" in mainWindow) ? mainWindow.isTabEmpty(mainWindow.gBrowser.selectedTab)
: mainWindow.gBrowser && mainWindow.gBrowser.selectedTab.isEmpty
&& (where == "tab" || where == "tabshifted")
&& !mainWindow.isBlankPageURL(url)) {
where = "current";
Services.console.logStringMessage("======REUSE EMPTY TAB======");
}
openLinkIn_reuseBlankTabIfCcurrentTab_org(url, where, params);
}
}
if (location.href == "chrome://browser/content/browser.xul") {
let func;
if (gBrowser && !/reuseBlankTabIfCcurrentTab/.test(gBrowser.loadTabs.toString())) {
func = gBrowser.loadTabs.toString();
if (!/justCreated/.test(func)) {
func = func.replace('if (!aURIs.length) {',
`if (("isTabEmpty" in window) ? isTabEmpty(gBrowser.selectedTab)
: window.gBrowser && gBrowser.selectedTab.isEmpty
) {
/*reuseBlankTabIfCcurrentTab*/
replace = true;
}
$&`
);
eval("gBrowser.loadTabs = function " + func.replace(/^function/, ''));
}
}
}