Allow use of middle click (wheel click) to open quoted tweets
function openquotedtweet(e) { | |
// Taken from https://stackoverflow.com/a/39165137/5798232 | |
function FindReact(dom) { | |
let key = Object.keys(dom).find(key=>key.startsWith("__reactInternalInstance$")); | |
let internalInstance = dom[key]; | |
if (internalInstance === null) return null; | |
if (internalInstance.return) { // react 16+ | |
return internalInstance._debugOwner | |
? internalInstance._debugOwner.stateNode | |
: internalInstance.return.stateNode; | |
} else { // react <16 | |
return internalInstance._currentElement._owner._instance; | |
} | |
} | |
if (e.button === 1 && e.which === 2) { | |
try { | |
let quotedtweet = e.target.closest('[role="blockquote"]'); | |
if (quotedtweet === null) return; | |
let reactElem = FindReact(quotedtweet); | |
if (reactElem === null) return; | |
let pathname = reactElem.props.link.pathname; | |
e.preventDefault(); | |
window.open(`${window.location.origin}${pathname}`); | |
} catch {} | |
} | |
} | |
document.querySelector('[data-reactroot]').onmousedown = openquotedtweet; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment