在手机浏览器中点击任何链接后在新标签页打开,原标签页不响应,并切换到新标签页,取消静音
当前为
// ==UserScript==
// @name youtube新标签页打开🍀💪
// @namespace http://tampermonkey.net/
// @version 1.1.6
// @description 在手机浏览器中点击任何链接后在新标签页打开,原标签页不响应,并切换到新标签页,取消静音
// @author ZZGGCC
// @match *://*.youtube.com/*
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// Function to open links in a new tab, switch to it, and prevent original tab response
function openLinksInNewTab(event) {
// Ensure the clicked element is a link
const link = event.target.closest('a');
if (link && link.href) {
event.preventDefault(); // Prevent the default link behavior
const newTab = window.open(link.href, '_blank'); // Open the link in a new tab
if (newTab) {
newTab.focus(); // Switch to the new tab
// Adding an interval to continuously check for video elements
const checkVideoInterval = setInterval(() => {
const videoElements = newTab.document.querySelectorAll('video, audio');
if (videoElements.length > 0) {
videoElements.forEach(video => {
video.muted = false; // Unmute the video
video.volume = 1.0; // Set volume to maximum
});
clearInterval(checkVideoInterval); // Clear the interval once video is found and unmuted
}
}, 1000); // Check every second
}
event.stopPropagation(); // Stop the event from propagating further
}
}
// Add event listener to the document to capture all click events
document.addEventListener('click', openLinksInNewTab, true);
})();