YouTuBu click text link open new tab

try to take over the world!

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         YouTuBu click text link open new tab
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.1.3
// @description  try to take over the world!
// @author       xiaofeiwu
// @match        https://www.youtube.com/
// @run-at       document-end
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    setTimeout(() => {
        // document.body.addEventListener('click', (event) => {
        //     event.stopPropagation();
        //     event.preventDefault(); 
        // })
        const textHrefList = document.querySelectorAll('#video-title-link')
        for (let i = 0; i < textHrefList.length; i++) {
            textHrefList[i].style.backgroundColor = 'skyblue'
        }
        const links = document.querySelectorAll('a[href*="/watch?v="]');
        for (let i = 0; i < links.length; i++) {
            links[i].addEventListener('click', (event) => {
                event.stopPropagation(); // 阻止事件冒泡
                event.preventDefault(); // 阻止链接的跳转行为
                window.open(links[i].href, '_blank'); // 在新标签页中打开链接
            });
        }
    }, 3000)
})();

// GM_addStyle(`
//   #video-title-link {
//       backgroundColor: 'skyBlue'
//   }
// `)