Skip to content

Instantly share code, notes, and snippets.

@lionbytes
Last active February 20, 2024 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lionbytes/7dd4d7db25f8686ab5918ac17850dcd7 to your computer and use it in GitHub Desktop.
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).
/**
* 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