// ==UserScript== // @name One Click Copy Link Button for Twitter(X) // @namespace http://tampermonkey.net/ // @version 2.1 // @description Add a button to copy the URL of a tweet on Twitter without clicking dropdown. Default to vxtwitter but customizable. // @author Dinomcworld // @match https://twitter.com/* // @match https://mobile.twitter.com/* // @match https://tweetdeck.twitter.com/* // @match https://x.com/* // @icon https://www.google.com/s2/favicons?domain=twitter.com // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; const baseUrl = 'https://vxtwitter.com'; const defaultSVG = ''; const copiedSVG = ''; function addCopyButtonToTweets() { const tweets = document.querySelectorAll('button[data-testid="bookmark"]'); tweets.forEach(likeButton => { const parentDiv = likeButton.parentElement; const tweet = parentDiv.closest('article[data-testid="tweet"]'); if (tweet && !tweet.querySelector('.custom-copy-icon')) { const copyIcon = document.createElement('div'); copyIcon.classList.add('custom-copy-icon'); copyIcon.setAttribute('aria-label', 'Copy link'); copyIcon.setAttribute('role', 'button'); copyIcon.setAttribute('tabindex', '0'); copyIcon.style.cssText = 'display: flex; align-items: center; justify-content: center; width: 19px; height: 19px; border-radius: 9999px; transition-duration: 0.2s; cursor: pointer;'; copyIcon.innerHTML = defaultSVG; copyIcon.addEventListener('click', (event) => { event.stopPropagation(); const tweetUrl = extractTweetUrl(tweet); if (tweetUrl) { navigator.clipboard.writeText(tweetUrl) .then(() => { console.log('Tweet link copied!'); copyIcon.innerHTML = copiedSVG; }) .catch(err => console.error('Error copying link: ', err)); } }); const parentDivClone = parentDiv.cloneNode(true); parentDivClone.style.cssText = 'display: flex; align-items: center;'; parentDiv.parentNode.insertBefore(parentDivClone, parentDiv.nextSibling); parentDivClone.innerHTML = ''; parentDivClone.appendChild(copyIcon); } }); } function extractTweetUrl(tweetElement) { const linkElement = tweetElement.querySelector('a[href*="/status/"]'); if (!linkElement) { return; } let url = linkElement.getAttribute('href').split('?')[0]; // Remove any query parameters if (url.includes('/photo/')) { url = url.split('/photo/')[0]; } return `${baseUrl}${url}`; } const observer = new MutationObserver(addCopyButtonToTweets); observer.observe(document.body, { childList: true, subtree: true }); addCopyButtonToTweets(); })();