Open links in new tab

Open links in new tab. Ctrl-click or Middle-click loads it in background, Alt-click opens normally

目前为 2016-09-20 提交的版本。查看 最新版本

// ==UserScript==
// @name         Open links in new tab
// @description  Open links in new tab. Ctrl-click or Middle-click loads it in background, Alt-click opens normally
// @include      *
// @namespace    wOxxOm.scripts
// @author       wOxxOm
// @version      2.0.2
// @license      MIT License
// @grant        GM_openInTab
// @run-at       document-start
// ==/UserScript==

var suppressing;
window.addEventListener('mousedown', function(e) {
	if (e.button > 1 || e.altKey)
		return;
	var link = e.target.closest('a');
	if (!link ||
		(link.getAttribute('href') || '').match(/^(javascript|#|$)/) ||
		link.href.replace(/#.*/, '') == location.href.replace(/#.*/, '')
	)
		return;

	GM_openInTab(link.href, e.button || e.ctrlKey);
	suppressing = true;
	prevent(e);
}, true);

window.addEventListener('click', prevent, true);
window.addEventListener('mouseup', prevent, true);
window.addEventListener('auxclick', prevent, true);

function prevent(e) {
	if (!suppressing)
		return;
	e.preventDefault();
	e.stopPropagation();
	e.stopImmediatePropagation();
	if (e.type == 'mouseup') {
		setTimeout(function() {
			suppressing = false;
		}, 100);
	}
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址