Last active
January 9, 2020 15:38
-
-
Save TsubasaKawajiri/c87f930dbfa528201a950ebaced47d21 to your computer and use it in GitHub Desktop.
add 'Tweets without RTs' link to anybodies profile.
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 Tweets without RT's | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description add 'Tweets without RTs' link to anybodies profile. | |
// @author Tsubasa Kawajiri | |
// @match https://twitter.com/* | |
// @grant none | |
// ==/UserScript== | |
let linkAdded = false | |
const PRESENTATION_CLASS = "css-1dbjc4n r-16y2uox r-6b64d0" | |
window.onload = function(){ | |
history.pushState = ( f => function pushState(){ | |
const ret = f.apply(this, arguments); | |
window.dispatchEvent(new Event('pushstate')); | |
window.dispatchEvent(new Event('locationchange')); | |
return ret; | |
})(history.pushState); | |
window.addEventListener('popstate',()=>{ | |
window.dispatchEvent(new Event('locationchange')) | |
}); | |
window.addEventListener('locationchange', init) | |
window.addEventListener('locationchange', scan) | |
init() | |
scan() | |
} | |
function init(){ | |
linkAdded = false | |
} | |
function addLink() { | |
if(linkAdded){ return } | |
linkAdded = true | |
const media = document.getElementsByClassName(PRESENTATION_CLASS)[2] | |
const presentations = media.parentNode | |
const tweetsWithoutRTsButton = document.createElement('div') | |
tweetsWithoutRTsButton.className = PRESENTATION_CLASS | |
const link = document.createElement('a') | |
link.href = `/search?q=from%3A%40${window.location.pathname.substr(1)}&f=live` | |
link.className = 'css-4rbku5 css-18t94o4 css-1dbjc4n r-1awozwy r-oucylx r-rull8r r-wgabs5 r-1loqt21 r-6koalj r-eqz5dr r-16y2uox r-1777fci r-1ny4l3l r-1oqcu8e r-o7ynqc r-6416eg' | |
const innerDiv = document.createElement('div') | |
innerDiv.className = 'css-901oao r-111h2gw r-1qd0xha r-a023e6 r-vw2c0b r-ad9z0x r-bcqeeo r-qvutc0' | |
const displaySpan = document.createElement('span') | |
displaySpan.className = 'css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0' | |
const text = document.createTextNode('Tweets without RTs') | |
displaySpan.appendChild(text) | |
innerDiv.appendChild(displaySpan) | |
link.appendChild(innerDiv) | |
tweetsWithoutRTsButton.appendChild(link) | |
presentations.insertBefore(tweetsWithoutRTsButton, media) | |
} | |
function scan(){ | |
const media = document.getElementsByClassName(PRESENTATION_CLASS)[2] | |
if(media){ | |
addLink() | |
} else { | |
setTimeout(scan, 500); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment