Opens Youtube video links in new tab
当前为
// ==UserScript==
// @name Open Youtube video links in new tab
// @description Opens Youtube video links in new tab
// @version 1.0.1
// @license MIT License
// @include https://www.youtube.com/*
// @exclude https://www.youtube.com/watch*
// @grant GM_openInTab
// @run-at document-start
// @require https://greasyfork.org/scripts/12228/code/setMutationHandler.js
// @namespace https://greasyfork.org/users/14346
// ==/UserScript==
attachHandler([].slice.call(document.getElementsByTagName('a')));
setMutationHandler(document, 'a[href^="/watch"]', function(nodes) {
attachHandler(nodes);
return true;
});
function attachHandler(nodes) {
nodes.forEach(function(node) {
if (node.target != '_blank') {
node.onclick = clickHandler;
node.addEventListener('click', clickHandler);
}
});
}
function clickHandler(e) {
if (e.button > 1)
return;
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
GM_openInTab(this.href, e.button || e.ctrlKey);
}