Copy Video URL

Copy Video URL of YouTube video

Versión del día 18/5/2022. Echa un vistazo a la versión más reciente.

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

(function() {
    setInterval(function() {
        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() {var vidID = document.querySelector('link[rel="shortlinkUrl"]').href.substr(document.querySelector('link[rel="shortlinkUrl"]').href.lastIndexOf('/') + 1); navigator.clipboard.writeText(vidID);}
        document.getElementById("copyVidID").firstElementChild.onclick = function() {var vidID = (new URL(document.querySelector('link[rel="shortlinkUrl"]').href).pathname).substring(1); navigator.clipboard.writeText(vidID);}

        var descriptionBox = document.querySelectorAll("ytd-video-secondary-info-renderer");
        if(descriptionBox[0].className.indexOf("loading") > -1){
            descriptionBox[0].classList.remove("loading");
        }
    }
})();