Skip to content

Instantly share code, notes, and snippets.

@busybox11
Created July 17, 2023 00:30
Show Gist options
  • Save busybox11/db3bf6deec9e35b7142fdd93e7b6472a to your computer and use it in GitHub Desktop.
Save busybox11/db3bf6deec9e35b7142fdd93e7b6472a to your computer and use it in GitHub Desktop.
Replaces Twitter's Quotes button with a random spinning rat video
// ==UserScript==
// @name spinning rats for twitter
// @namespace twitter scripts
// @match *://*.twitter.com/*
// @grant none
// @version 1.0
// @author @chaoticvibing - GH @busybox11
// @description 7/17/2023, 2:15:52 AM
// ==/UserScript==
const ratsVideos = [
'https://www.youtube.com/watch?v=3X-iqFRGqbc',
'https://www.youtube.com/watch?v=PjFAvCFuONs',
'https://www.youtube.com/watch?v=N4_1lhrxYMk',
'https://www.youtube.com/watch?v=3sLxoKX6rUQ',
'https://www.youtube.com/watch?v=JPRYEUjfZSs',
'https://www.youtube.com/watch?v=zvTWi0eAybk',
'https://www.youtube.com/watch?v=zO-fZ6Na6Lc',
'https://www.youtube.com/watch?v=gW8tSw6lZ2Q',
'https://www.youtube.com/watch?v=Y8nHP6HEI4c',
'https://www.youtube.com/watch?v=bis7oEqLhU8',
'https://www.youtube.com/watch?v=T_Z2ixASt8Q',
'https://www.youtube.com/watch?v=lFLyfRKsMaU',
'https://www.youtube.com/watch?v=WuwqawzzgnE'
];
const handleMutation = (mutationsList, observer) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
const nodes = mutation.addedNodes
for (const node of nodes) {
// Get all a elements with href ending with /retweets/with_comments
const ratLinks = node.querySelectorAll('a[href$="/retweets/with_comments"]')
for (const ratLink of ratLinks) {
// Remove all event listeners
const newRatLink = ratLink.cloneNode(true)
ratLink.parentNode.replaceChild(newRatLink, ratLink)
// Add new event listener
newRatLink.addEventListener('click', (e) => {
e.preventDefault()
const randomRatVideo = ratsVideos[Math.floor(Math.random() * ratsVideos.length)]
window.open(randomRatVideo, '_blank')
});
}
}
}
}
}
const sc = {
log: (...args) => {
console.log('[twitter-spinning-rats]', ...args)
}
}
const observer = new MutationObserver(handleMutation)
observer.observe(document, { childList: true, subtree: true })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment