[YouTube] Open Shorts on Default Watch

redirects shorts link to default watch?v=

当前为 2025-01-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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/*
// @version     1.0
// @history     1.0
// @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 */
    }
`);