Last active
February 20, 2024 20:22
-
-
Save lionbytes/7dd4d7db25f8686ab5918ac17850dcd7 to your computer and use it in GitHub Desktop.
A JavaScript script that deliberately and automatically undoes reposts or retweets one by one on X (Twitter).
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
/** | |
* Before you execute the script on your profile page, scroll down to the 7th post or so. | |
* Use stop() to clear the time interval and stop the process at will. | |
*/ | |
let interval; | |
// Stop process function | |
const stop = () => { | |
clearInterval(interval); | |
} | |
// The post undoing process function | |
const undoRepost = (index) => { | |
interval = setInterval(() => { | |
try { | |
let button = document.querySelectorAll('[data-testid=cellInnerDiv]')[4].querySelector('[role=group]').querySelectorAll('[dir]')[1]; | |
//Click the button only if it's a Repost button | |
if (button.style.color === 'rgb(0, 186, 124)') { | |
button.click(); | |
} | |
//Click the Undo Repost button from the dropdown menu | |
setTimeout(() => { | |
try { | |
document.querySelector('[data-testid=unretweetConfirm]').click(); | |
window.scrollTo(0, window.pageYOffset+300); | |
} catch (error) { | |
console.log("Undo Post button doesn't exist: ", error); | |
window.scrollTo(0, window.pageYOffset+300); | |
} | |
}, 1000); | |
} catch (error) { | |
console.log("Post index was: ", index); | |
console.error(error); | |
if (index < 9) { | |
index++; | |
console.log("Post index is now: ", index); | |
} | |
clearInterval(interval); | |
undoRepost(index); | |
} | |
}, 2000); | |
} | |
// Find and highlight the first post in the chain of posts to be removed, | |
// by increasing or decreasing the number in the square brackets below. | |
document.querySelectorAll('[data-testid=cellInnerDiv]')[6]; | |
// Start the process | |
undoRepost(6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment