Opens search results in new tab when you middle click
当前为
// ==UserScript==
// @name Google - Middle Click Search
// @namespace https://gf.qytechs.cn/users/649
// @version 1.1
// @description Opens search results in new tab when you middle click
// @author Adrien Pyke
// @include /^https?:\/\/www\.google\.[a-zA-Z]+\/?(?:\?.*)?$/
// @include /^https?:\/\/www\.google\.[a-zA-Z]+\/search\/?\?.*$/
// @require https://gf.qytechs.cn/scripts/5679-wait-for-elements/code/Wait%20For%20Elements.js?version=122976
// @require https://gf.qytechs.cn/scripts/25833-middle-click-event/code/Middle%20Click%20Event.js?version=164257
// @grant GM_openInTab
// ==/UserScript==
(function() {
'use strict';
var setQueryParameter = function(key, value, url) {
if (!url) url = window.location.href;
var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"),
hash;
if (re.test(url)) {
if (typeof value !== 'undefined' && value !== null)
return url.replace(re, '$1' + key + "=" + value + '$2$3');
else {
hash = url.split('#');
url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
url += '#' + hash[1];
return url;
}
}
else {
if (typeof value !== 'undefined' && value !== null) {
var separator = url.indexOf('?') !== -1 ? '&' : '?';
hash = url.split('#');
url = hash[0] + separator + key + '=' + value;
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
url += '#' + hash[1];
return url;
}
else
return url;
}
};
var getUrl = function(value) {
if (window.location.href.match(/^https?:\/\/www\.google\.[a-zA-Z]+\/search\/?\?.*$/)) {
return setQueryParameter('q', encodeURIComponent(value));
} else {
return location.protocol + '//' + location.host + '/search?q=' + encodeURIComponent(value);
}
};
waitForElems('#_fZl', function(btn) {
var input = document.querySelector('#lst-ib');
btn.onmousedown = function(e) {
if (e.button === 1) {
e.preventDefault();
}
};
btn.addEventListener('middleclick', function(e) {
e.stopImmediatePropagation();
var url = getUrl(input.value);
GM_openInTab(url, true);
});
});
waitForElems('.sbsb_b li .sbqs_c, .sbsb_b li .sbpqs_d', function(elem) {
elem.addEventListener('middleclick', function(e) {
e.stopImmediatePropagation();
var text = elem.classList.contains('sbpqs_d') ? elem.querySelector('span').textContent : elem.textContent;
var url = getUrl(text);
GM_openInTab(url, true);
});
});
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址