YouTube URL Cleaner

Clean YouTube URLs to only keep the video ID when Shift + Left Click is used and show a popup

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTube URL Cleaner
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Clean YouTube URLs to only keep the video ID when Shift + Left Click is used and show a popup
// @author       maanimis
// @match        *://*.youtube.com/*
// @grant        clipboardWrite
// @run-at      document-end
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const showPopup = (message) => {
        const popup = document.createElement('div');
        Object.assign(popup.style, {
            position: 'fixed',
            bottom: '20px',
            right: '20px',
            padding: '10px',
            background: 'black',
            color: 'white',
            borderRadius: '5px',
            boxShadow: '0px 0px 10px rgba(0,0,0,0.5)',
            zIndex: '1000',
            fontSize: '14px',
            fontFamily: 'Arial, sans-serif'
        });
        popup.textContent = message;
        document.body.appendChild(popup);

        setTimeout(() => popup.remove(), 3000);
    };

    const cleanUrl = () => {
        const urlMatch = window.location.href.match(/https?:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_-]+)/);
        if (!urlMatch) return;

        const cleanUrl = `https://www.youtube.com/watch?v=${urlMatch[1]}`;
        navigator.clipboard.writeText(cleanUrl)
            .then(() => {
                console.log('Cleaned URL copied to clipboard:', cleanUrl);
                showPopup(`Copied: ${cleanUrl}`);
            })
            .catch(err => {
                console.error('Failed to copy URL:', err);
                showPopup('Failed to copy URL');
            });
    };

    document.addEventListener('click', (event) => {
        if (event.shiftKey && event.button === 0) {
            cleanUrl();
        }
    });
})();