Open links in new tab. Ctrl-click or Middle-click loads it in background, Alt-click opens normally
目前為
// ==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
// @license MIT License
// @grant GM_openInTab
// @run-at document-start
// ==/UserScript==
window.addEventListener('mousedown', function(e) {
if (e.button > 1 || e.altKey)
return;
var link = e.target.closest('a');
if (!link ||
!link.href ||
link.href.match(/^javascript|^#/) ||
link.href.replace(/#.*/, '') == location.href.replace(/#.*/, '')
)
return;
GM_openInTab(link.href, e.button || e.ctrlKey);
prevent(e);
window.addEventListener('click', prevent, true);
window.addEventListener('mouseup', prevent, true);
window.addEventListener('auxclick', prevent, true);
}, true);
function prevent(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
setTimeout(function() {
window.removeEventListener('click', prevent, true);
window.removeEventListener('mouseup', prevent, true);
window.removeEventListener('auxclick', prevent, true);
}, 100);
}