[YouTube] Open Shorts on Default Watch

redirects shorts link to default watch?v=

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        [YouTube] Open Shorts on Default Watch
// @author      pootz10
// @namespace   https://www.tampermonkey.net
// @description redirects shorts link to default watch?v=
// @match       https://www.youtube.com/shorts/*
// @exclude     https://www.youtube.com/watch?v=*
// @exclude     https://youtu.be/*
// @version     1.1
// @history     1.1 - added exclude for watch?v= links
// @license     GNU
// @grant       GM_openInTab
// @grant       GM_addStyle
// @run-at      document-idle
// ==/UserScript==


// Função para criar o botão
function addWatchButton() {
    const actionsElement = document.querySelector('#actions');
    if (!actionsElement) return; // Sai se o elemento não existir

    // Evita adicionar múltiplos botões
    if (document.querySelector('#custom-watch-button')) return;

    // Cria o botão
    const button = document.createElement('button');
    button.id = 'custom-watch-button';
    button.textContent = 'Watch';

    // Ação ao clicar no botão
    button.addEventListener('click', () => {
        const urlParams = new URL(location.href);
        const videoId = urlParams.pathname.split('/')[2];
        if (videoId) {
            const watchUrl = `https://www.youtube.com/watch?v=${videoId}`;
            GM_openInTab(watchUrl, { active: true });
        }
    });

    // Insere o botão no início das ações
    actionsElement.prepend(button);
}

// Observa mudanças no DOM para detectar o carregamento do elemento
const observer = new MutationObserver(() => {
    addWatchButton();
});

observer.observe(document.body, { childList: true, subtree: true });

// Adiciona botão imediatamente caso o elemento já esteja carregado
addWatchButton();

GM_addStyle(`
    #custom-watch-button {
        color: #0f0f0f;
        background: rgba(0, 0, 0, 0.05);
        width: 48px;
        height: 48px;
        padding: 0;
        font-size: 12px;
        font-family: "Roboto", "Arial", sans-serif;
        font-weight: 500;
        line-height: 18px;
        border: none;
        border-radius: 24px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        margin: 0;
        text-transform: none;
    }

    #custom-watch-button:hover {
        background: rgba(0, 0, 0, 0.1); /* Ajuste para hover */
    }
`);