YouTube: Copy Comment Link

You can conveniently copy the link of any comment and send it to your friend

  1. // ==UserScript==
  2. // @name YouTube: Copy Comment Link
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.6
  5. // @description You can conveniently copy the link of any comment and send it to your friend
  6. // @author Grihail
  7. // @match *://www.youtube.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  9. // @grant none
  10. // @license CC-BY
  11. // ==/UserScript==
  12.  
  13. function addCopyLinkToHeaderAuthor() {
  14. const headerAuthorElements = document.querySelectorAll('#header-author.ytd-comment-renderer');
  15.  
  16. headerAuthorElements.forEach(element => {
  17. const copyLink = element.querySelector('.copy-comment-link');
  18.  
  19. if (!copyLink) {
  20. const ytFormattedString = element.querySelector('yt-formatted-string a');
  21.  
  22. if (ytFormattedString) {
  23. const originalHref = ytFormattedString.getAttribute('href');
  24. const fullHref = 'https://www.youtube.com' + originalHref;
  25.  
  26. const copyLink = document.createElement('a');
  27. copyLink.classList.add('copy-comment-link');
  28. copyLink.href = fullHref;
  29. copyLink.style.marginLeft = '10px';
  30. copyLink.style.width = '36px';
  31. copyLink.style.height = '36px';
  32. copyLink.style.borderRadius = '54%';
  33. copyLink.style.display = 'flex'; // Make it a flex container
  34. copyLink.style.alignItems = 'center'; // Center content vertically
  35. copyLink.style.justifyContent = 'center'; // Center content horizontally
  36. copyLink.innerHTML = '<svg height="24px" viewBox="0 0 24 24" width="24px"><path style="stroke: var(--yt-spec-text-primary);" d="M13 8H17.3333C19.5424 8 21.3333 9.79086 21.3333 12C21.3333 14.2091 19.5424 16 17.3333 16H13M16 12H7.99996M11 8H6.66663C4.45749 8 2.66663 9.79086 2.66663 12C2.66663 14.2091 4.45749 16 6.66663 16H11" fill="none"></path></svg>';
  37.  
  38. copyLink.addEventListener('click', event => {
  39. event.preventDefault();
  40. navigator.clipboard.writeText(fullHref);
  41. });
  42.  
  43. // Add hover and active styles
  44. copyLink.style.transition = 'background-color 0.3s';
  45. copyLink.style.backgroundColor = 'transparent';
  46. copyLink.style.border = 'none';
  47.  
  48. copyLink.addEventListener('mouseenter', () => {
  49. copyLink.style.backgroundColor = 'rgb(0 0 0 / 10%)';
  50. });
  51.  
  52. copyLink.addEventListener('mouseleave', () => {
  53. copyLink.style.backgroundColor = 'transparent';
  54. });
  55.  
  56. copyLink.addEventListener('mousedown', () => {
  57. copyLink.style.backgroundColor = 'rgb(0 0 0 / 20%)';
  58. });
  59.  
  60. copyLink.addEventListener('mouseup', () => {
  61. copyLink.style.backgroundColor = 'rgb(0 0 0 / 10%)';
  62. });
  63.  
  64. element.style.alignItems = 'center';
  65. element.appendChild(copyLink);
  66. }
  67. }
  68. });
  69. }
  70.  
  71. setInterval(addCopyLinkToHeaderAuthor, 1000);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址