You can conveniently copy the link of any comment and send it to your friend
当前为
// ==UserScript==
// @name YouTube: Copy Comment Link
// @namespace http://tampermonkey.net/
// @version 1.3
// @description You can conveniently copy the link of any comment and send it to your friend
// @author Grihail
// @match *://www.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// @license CC-BY
// ==/UserScript==
function addCopyLinkToHeaderAuthor() {
const headerAuthorElements = document.querySelectorAll('#header-author.ytd-comment-renderer');
headerAuthorElements.forEach(element => {
const copyLink = element.querySelector('.copy-comment-link');
if (!copyLink) {
const ytFormattedString = element.querySelector('yt-formatted-string a');
if (ytFormattedString) {
const originalHref = ytFormattedString.getAttribute('href');
const fullHref = 'https://www.youtube.com' + originalHref;
const copyLink = document.createElement('a');
copyLink.classList.add('copy-comment-link');
copyLink.href = fullHref;
copyLink.style.marginLeft = '10px';
copyLink.style.width = '32px';
copyLink.style.height = '32px';
copyLink.style.borderRadius = '54%';
copyLink.style.display = 'flex'; // Make it a flex container
copyLink.style.alignItems = 'center'; // Center content vertically
copyLink.style.justifyContent = 'center'; // Center content horizontally
copyLink.innerHTML = '<svg height="20px" viewBox="0 0 24 24" width="20px"><path d="M19,6v15H8V6H19 M15,2H4v16h1V3h10V2L15,2z M20,5H7v17h13V5L20,5z" fill="#000"></path></svg>';
copyLink.addEventListener('click', event => {
event.preventDefault();
navigator.clipboard.writeText(fullHref);
});
// Add hover and active styles
copyLink.style.transition = 'background-color 0.3s';
copyLink.style.backgroundColor = 'transparent';
copyLink.style.border = 'none';
copyLink.addEventListener('mouseenter', () => {
copyLink.style.backgroundColor = 'rgb(0 0 0 / 10%)';
});
copyLink.addEventListener('mouseleave', () => {
copyLink.style.backgroundColor = 'transparent';
});
copyLink.addEventListener('mousedown', () => {
copyLink.style.backgroundColor = 'rgb(0 0 0 / 20%)';
});
copyLink.addEventListener('mouseup', () => {
copyLink.style.backgroundColor = 'rgb(0 0 0 / 10%)';
});
element.style.alignItems = 'center';
element.appendChild(copyLink);
}
}
});
}
setInterval(addCopyLinkToHeaderAuthor, 1000);