-
Notifications
You must be signed in to change notification settings - Fork 8
/
openNewTab.uc.js
72 lines (67 loc) · 3.36 KB
/
openNewTab.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
// ==UserScript==
// @name openNewTab.uc.js
// @namespace [email protected]
// @include main
// @include chrome://browser/content/browser.xhtml
// @description Open Bookmarks/History/Search in New Tab
// @downloadURL https://raw.githubusercontent.com/Harv/userChromeJS/master/openNewTab.uc.js
// @version 1.5.1
// ==/UserScript==
location == "chrome://browser/content/browser.xhtml" && (function () {
const { Services } = globalThis || Cu.import("resource://gre/modules/Services.jsm");
Services.obs.addObserver(function observer(subject, topic, data) {
if (data != "init-complete") return;
Services.obs.removeObserver(observer, topic);
doReplace();
}, "browser-search-service");
function generateReplacement(func, regexp, replacementFunc, appendMatch) {
var replacementStr = replacementFunc.toString().replace(/^.*{|}$/g, '');
if (appendMatch) {
replacementStr = replacementStr + '$&';
}
var funcStr = func.toString().replace(regexp, replacementStr);
if (!funcStr.startsWith("function")) {
funcStr = "function " + funcStr;
}
return funcStr;
}
function doReplace() {
eval('BrowserUtils.whereToOpenLink = ' + generateReplacement(BrowserUtils.whereToOpenLink, /(return "current";)(?![\s\S]*\1)/g, function() {
if (!e) return 'current';
if (gBrowser.selectedTab.isEmpty) return 'current';
var node = e.originalTarget;
while (node) {
if(node.className && node.className.indexOf('bookmark-item') != -1
&& node.outerHTML && node.outerHTML.indexOf('scheme="javascript"') != -1) { // javascript bookmarks
return 'current';
}
if (node.className && node.className.indexOf('sync-state') != -1) { // sidebar syncedtabs
return 'tab';
}
switch (node.id) {
case 'bookmarksMenuPopup': // menubar bookmarks
case 'BMB_bookmarksPopup': // navibar bookmarks
case 'PanelUI-bookmarks': // navibar bookmarks
case 'bookmarksPanel': // sidebar bookmarks
case 'historyMenuPopup': // menubar history
case 'PanelUI-history': // navibar history
case 'history-panel': // sidebar history
case 'placeContent': // library bookmarks&history
case 'PanelUI-remotetabs': // navibar syncedtabs
return 'tab';
}
node = node.parentNode;
}
return 'current';
}));
// // urlbar
// eval('gURLBar._whereToOpen = ' + generateReplacement(gURLBar._whereToOpen, /(return where;)(?![\s\S]*\1)/g, function() {
// where = gBrowser.selectedTab.isEmpty ? 'current' : 'tab';
// }, true));
// searchbar
var searchbar = document.getElementById('searchbar');
searchbar && eval('searchbar.handleSearchCommandWhere=' + generateReplacement(searchbar.handleSearchCommandWhere, /this\.doSearch\(textValue, aWhere, aEngine, aParams, isOneOff\);/, function() {
aWhere = gBrowser.selectedTab.isEmpty ? 'current' : 'tab';
}, true));
}
})();