Open Youtube video links in new tab

Opens Youtube video links in new tab

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

// ==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://gf.qytechs.cn/scripts/12228/code/setMutationHandler.js
// @namespace https://gf.qytechs.cn/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);
}

QingJ © 2025

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