Copy Video URL

Copy Video URL of YouTube video

  1. // ==UserScript==
  2. // @name Copy Video URL
  3. // @namespace https://greasyfork.org/en/users/689482-quin15
  4. // @version 0.9
  5. // @description Copy Video URL of YouTube video
  6. // @author Quin15
  7. // @match *://*.youtube.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.  
  14. setInterval(function() {
  15. if (window.location.href.indexOf("watch") < 0) {
  16. return false;
  17. }
  18. if (document.getElementById("meta-contents") && document.getElementById("copyVidID") === null) {
  19. AddYT();
  20. }
  21. }, 1);
  22.  
  23. function AddYT() {
  24. var buttonDiv = document.createElement("span");
  25. buttonDiv.id = "copyVidID";
  26. buttonDiv.style = "width: 100%; margin-top: 3px; padding: 10px 0;"
  27. var addButton = document.createElement("a");
  28. addButton.appendChild(document.createTextNode("Copy ID"));
  29. 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';
  30. buttonDiv.appendChild(addButton);
  31.  
  32. document.querySelector('#meta #subscribe-button.style-scope').appendChild(buttonDiv);
  33.  
  34. document.getElementById("copyVidID").firstElementChild.onclick = function() {
  35. function YouTubeGetID(url){
  36. url = url.split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
  37. return (url[2] !== undefined) ? url[2].split(/[^0-9a-z_\-]/i)[0] : url[0];
  38. }
  39. var vidID = YouTubeGetID(window.location.href)
  40. navigator.clipboard.writeText(vidID);
  41. }
  42. }
  43. })();