// ==UserScript==
// @name Chrome Middle Button Fix
// @description Forces opening links in a new tab when clicked with middle button
// @run-at document-end
// ==/UserScript==
// by 81403 at brm dot sk
// inspired by Peter Grabs' extension
document.addEventListener(
"click",
function (e)
{
function getAncestorOrSelfLink(node)
{
while (node && node.tagName !== "A") node = node.parentNode;
return node;
}
(e.ctrlKey && e.button === 0 || e.button === 1) // ctrl + left button OR middle button
&& getAncestorOrSelfLink(e.target) // the clicked element was an nchor or an element inside an nchor
&& e.stopPropagation(); // and this is the fix!
},
true // this event will be launched in the capture phase
);