This script adds a new button to Twitter posts. Clicking it, copies a TwitFix link to your clipboard, and strips any trancking data from it because might as well.
Last active
December 8, 2023 23:11
-
-
Save Atulin/b6a5975ac4f260d16496a2b519f6a698 to your computer and use it in GitHub Desktop.
FxTwitter Copy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Twitter Copy Fx Link | |
// @version 1.3.0 | |
// @grant none | |
// @run-at document-idle | |
// @match https://twitter.com/* | |
// ==/UserScript== | |
/***********************************************\ | |
|* CONFIGURATION *| | |
\***********************************************/ | |
// Configure the domain for the fixer | |
const domain = 'fxtwitter.com'; | |
(new MutationObserver(check)).observe(document, { childList: true, subtree: true }); | |
const mask = (!!navigator ? '1' : '0') + (!!navigator?.clipboard ? '1' : '0') + (!!navigator?.clipboard?.writeText ? '1' : '0'); | |
function check(changes, observer) { | |
if (document.querySelector('article [role=group]')) { | |
observer.disconnect(); | |
const base = document.querySelector('article [role=group]:last-child'); | |
//=== BUTTON ===\\ | |
const btn = document.createElement('button'); | |
btn.innerText = 'FX'; | |
btn.setAttribute('id', 'fx-copy'); | |
base.appendChild(btn); | |
//=== TOAST ===\\ | |
const toast = document.createElement('div'); | |
toast.setAttribute('id', 'fx-toast'); | |
document.body.appendChild(toast); | |
const showToast = (text) => { | |
toast.innerText = text; | |
toast.style.display = 'block'; | |
setTimeout(() => { toast.style.display = 'none' }, 1000); | |
} | |
//=== FUNCTIONALITY ===\\ | |
btn.addEventListener('click', () => { | |
const url = window.location.href; | |
const noTracking = url.split('?')[0]; | |
const fx = noTracking.replace('twitter.com', domain); | |
if (navigator?.clipboard?.writeText) { | |
navigator.clipboard.writeText(fx); | |
showToast('Copied!'); | |
} else { | |
showToast('Clipboard API not available: ' + mask); | |
} | |
}); | |
//=== STYLE ===\\ | |
const style = document.createElement('style'); | |
style.innerText = /* css */ ` | |
#fx-copy { | |
border-color: transparent; | |
border-radius: 50%; | |
background: transparent; | |
color: rgb(110, 118, 125); | |
line-height: 20px; | |
font-size: 1.1rem; | |
margin: 3px; | |
cursor: pointer; | |
aspect-ratio: 1; | |
} | |
#fx-copy:hover { | |
background: rgba(255, 227, 0, 0.1); | |
color: rgb(255, 227, 0); | |
} | |
#fx-toast { | |
background: rgba(41, 50, 62, 0.6); | |
padding: 1rem; | |
font-family: sans-serif; | |
font-size: 1.05rem; | |
border-radius: 2rem; | |
color: white; | |
position: fixed; | |
bottom: 4rem; | |
left: 50%; | |
transform: translate(-50%); | |
display: none; | |
} | |
`; | |
document.querySelector('head').appendChild(style); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this worked great for a while, but sometime recently it started only showing the FX button on the first tweet when you load the page, but all tweets after it do not have it