Copy Video URL

Copy Video URL of YouTube video

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Copy Video URL
// @namespace    https://greasyfork.org/en/users/689482-quin15
// @version      0.9
// @description  Copy Video URL of YouTube video
// @author       Quin15
// @match        *://*.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// ==/UserScript==

(function() {

    setInterval(function() {
        if (window.location.href.indexOf("watch") < 0) {
            return false;
        }
        if (document.getElementById("meta-contents") && document.getElementById("copyVidID") === null) {
            AddYT();
        }
    }, 1);

    function AddYT() {
        var buttonDiv = document.createElement("span");
        buttonDiv.id = "copyVidID";
        buttonDiv.style = "width: 100%; margin-top: 3px; padding: 10px 0;"
        var addButton = document.createElement("a");
        addButton.appendChild(document.createTextNode("Copy ID"));
        addButton.style = 'width: 100%; margin: 3px; padding: 10px 22px; cursor: pointer; height: inherit; background-color: #393939; color: #fff; border-radius: 2px; font-size: 1.4rem; font-family: inherit; text-align: center';
        buttonDiv.appendChild(addButton);

        document.querySelector('#meta #subscribe-button.style-scope').appendChild(buttonDiv);

        document.getElementById("copyVidID").firstElementChild.onclick = function() {
            function YouTubeGetID(url){
                url = url.split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
                return (url[2] !== undefined) ? url[2].split(/[^0-9a-z_\-]/i)[0] : url[0];
            }
            var vidID = YouTubeGetID(window.location.href)
            navigator.clipboard.writeText(vidID);
        }
    }
})();