-
-
Save antlionguard/000e24bb039e8824fa5c58d6e324c78e to your computer and use it in GitHub Desktop.
const timer = ms => new Promise(res => setTimeout(res, ms)); | |
// Unretweet normally | |
const unretweetTweet = async (tweet) => { | |
await tweet.querySelector('[data-testid="unretweet"]').click(); | |
await timer(250); | |
await document.querySelector('[data-testid="unretweetConfirm"]').click(); | |
console.log('****// Unretweeted Successfully //****') | |
} | |
// Sometimes twitter shows your retweet but green retweet button is invisible and therefore you need to retweet again for make unreweet. This function is for that. | |
const unretweetUnretweetedTweet = async (tweet) => { | |
await tweet.querySelector('[data-testid="retweet"]').click(); | |
await timer(250); | |
await document.querySelector('[data-testid="retweetConfirm"]').click(); | |
console.log('****// Retweeted Successfully //****') | |
await timer(250); | |
unretweetTweet(tweet); | |
} | |
setInterval(async () => | |
{ | |
// Get all tweets | |
const retweetedTweetList = document.querySelectorAll('[data-testid="socialContext"]'); | |
console.log('****// Retweeted Tweet List Collected //****') | |
for (const retweet of retweetedTweetList) { | |
const tweetWrapper = retweet.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement; | |
tweetWrapper.scrollIntoView(); | |
const isRetweeted = tweetWrapper.querySelector('[data-testid="unretweet"]'); | |
if (isRetweeted) { | |
console.log('****// Green Retweet Button Found - Starting "unretweetTweet" process //****') | |
await unretweetTweet(tweetWrapper); | |
} else { | |
console.log('****// Green Retweet Button Not Found - Starting "unretweetUnretweetedTweet" process //****') | |
await unretweetUnretweetedTweet(tweetWrapper); | |
} | |
await timer(2000); | |
} | |
console.log('****// List Completed //****') | |
console.log('****// Scrolling //****') | |
console.log(' ') | |
console.log(' ') | |
console.log(' ') | |
console.log(' ') | |
console.log(' ') | |
console.log(' ') | |
console.log(' ') | |
console.log(' ') | |
await window.scrollTo(0, document.body.scrollHeight); | |
}, 60000); |
Confirmed working as of June 26, 2022
29.06.2023 still works. Thanks.
I got the next message
Uncaught (in promise) TypeError: Cannot read properties of null (reading 'click')
at unretweetTweet (:7:74)
at async :33:19
what does it mean? and how to fix? @antlionguard
not working for me too
This code does the same but you dont have to wait.
const timer = ms => new Promise(res => setTimeout(res, ms));
const unretweetTweet = async (tweet) => {
try {
await tweet.querySelector('div[data-testid="unretweet"]').click();
await timer(250);
await document.querySelector('div[data-testid="unretweetConfirm"]').click();
console.log('****// Unretweeted Successfully //****');
} catch (error) {
console.error('Error during unretweet:', error);
}
};
const unretweetUnretweetedTweet = async (tweet) => {
try {
await tweet.querySelector('div[data-testid="retweet"]').click();
await timer(250);
await document.querySelector('div[data-testid="retweetConfirm"]').click();
console.log('****// Retweeted Successfully //****');
await timer(250);
unretweetTweet(tweet);
} catch (error) {
console.error('Error during unretweetUnretweetedTweet:', error);
}
};
const processTweets = async () => {
const retweetedTweetList = document.querySelectorAll('span[data-testid="socialContext"]');
console.log('****// Retweeted Tweet List Collected //****');
for (const retweet of retweetedTweetList) {
const tweetWrapper = retweet.closest('[data-testid="tweet"]');
tweetWrapper.scrollIntoView();
const isRetweeted = tweetWrapper.querySelector('div[data-testid="unretweet"]');
if (isRetweeted) {
console.log('****// Green Retweet Button Found - Starting "unretweetTweet" process //****');
await unretweetTweet(tweetWrapper);
} else {
console.log('****// Green Retweet Button Not Found - Starting "unretweetUnretweetedTweet" process //****');
await unretweetUnretweetedTweet(tweetWrapper);
}
await timer(2000);
}
console.log('****// List Completed //****');
console.log('****// Scrolling //****');
console.log(' ');
console.log(' ');
console.log(' ');
console.log(' ');
console.log(' ');
console.log(' ');
console.log(' ');
console.log(' ');
window.scrollTo(0, document.body.scrollHeight);
// Call processTweets again using requestAnimationFrame to keep the loop going
requestAnimationFrame(processTweets);
};
// Start the process initially
processTweets();
it works well. Thx Bossman556.
This code does the same but you dont have to wait.
const timer = ms => new Promise(res => setTimeout(res, ms)); const unretweetTweet = async (tweet) => { try { await tweet.querySelector('div[data-testid="unretweet"]').click(); await timer(250); await document.querySelector('div[data-testid="unretweetConfirm"]').click(); console.log('****// Unretweeted Successfully //****'); } catch (error) { console.error('Error during unretweet:', error); } }; const unretweetUnretweetedTweet = async (tweet) => { try { await tweet.querySelector('div[data-testid="retweet"]').click(); await timer(250); await document.querySelector('div[data-testid="retweetConfirm"]').click(); console.log('****// Retweeted Successfully //****'); await timer(250); unretweetTweet(tweet); } catch (error) { console.error('Error during unretweetUnretweetedTweet:', error); } }; const processTweets = async () => { const retweetedTweetList = document.querySelectorAll('span[data-testid="socialContext"]'); console.log('****// Retweeted Tweet List Collected //****'); for (const retweet of retweetedTweetList) { const tweetWrapper = retweet.closest('[data-testid="tweet"]'); tweetWrapper.scrollIntoView(); const isRetweeted = tweetWrapper.querySelector('div[data-testid="unretweet"]'); if (isRetweeted) { console.log('****// Green Retweet Button Found - Starting "unretweetTweet" process //****'); await unretweetTweet(tweetWrapper); } else { console.log('****// Green Retweet Button Not Found - Starting "unretweetUnretweetedTweet" process //****'); await unretweetUnretweetedTweet(tweetWrapper); } await timer(2000); } console.log('****// List Completed //****'); console.log('****// Scrolling //****'); console.log(' '); console.log(' '); console.log(' '); console.log(' '); console.log(' '); console.log(' '); console.log(' '); console.log(' '); window.scrollTo(0, document.body.scrollHeight); // Call processTweets again using requestAnimationFrame to keep the loop going requestAnimationFrame(processTweets); }; // Start the process initially processTweets();
no. i added delay for preventing to rate limit.
Worked for me ♥
2023
Wait, so all the content is gone, but why is the number still there?
@antlionguard , @Bossman556 please would you mind to make this script as chrome addons extension but with popup read and show every thing as showing in console? please
Still working
@antlionguard , @Bossman556 please would you mind to make this script as chrome addons extension but with popup read and show every thing as showing in console? please
good idea. i will work on it.
This code does the same but you dont have to wait.
const timer = ms => new Promise(res => setTimeout(res, ms)); const unretweetTweet = async (tweet) => { try { await tweet.querySelector('div[data-testid="unretweet"]').click(); await timer(250); await document.querySelector('div[data-testid="unretweetConfirm"]').click(); console.log('****// Unretweeted Successfully //****'); } catch (error) { console.error('Error during unretweet:', error); } }; const unretweetUnretweetedTweet = async (tweet) => { try { await tweet.querySelector('div[data-testid="retweet"]').click(); await timer(250); await document.querySelector('div[data-testid="retweetConfirm"]').click(); console.log('****// Retweeted Successfully //****'); await timer(250); unretweetTweet(tweet); } catch (error) { console.error('Error during unretweetUnretweetedTweet:', error); } }; const processTweets = async () => { const retweetedTweetList = document.querySelectorAll('span[data-testid="socialContext"]'); console.log('****// Retweeted Tweet List Collected //****'); for (const retweet of retweetedTweetList) { const tweetWrapper = retweet.closest('[data-testid="tweet"]'); tweetWrapper.scrollIntoView(); const isRetweeted = tweetWrapper.querySelector('div[data-testid="unretweet"]'); if (isRetweeted) { console.log('****// Green Retweet Button Found - Starting "unretweetTweet" process //****'); await unretweetTweet(tweetWrapper); } else { console.log('****// Green Retweet Button Not Found - Starting "unretweetUnretweetedTweet" process //****'); await unretweetUnretweetedTweet(tweetWrapper); } await timer(2000); } console.log('****// List Completed //****'); console.log('****// Scrolling //****'); console.log(' '); console.log(' '); console.log(' '); console.log(' '); console.log(' '); console.log(' '); console.log(' '); console.log(' '); window.scrollTo(0, document.body.scrollHeight); // Call processTweets again using requestAnimationFrame to keep the loop going requestAnimationFrame(processTweets); }; // Start the process initially processTweets();
no. i added delay for preventing to rate limit.
this is working. thank you!
not working
any code for removing retweets from account that blocked you?
any code for removing retweets from account that blocked you?
I also need
Script not working on July 3rd, 2024.
const isRetweeted = tweetWrapper.querySelector('div[data-testid="unretweet"]')
has value Null
.
@ElPelado619 @iAjityadav @mainleblanc fixed now
It's working but slow !
take pause & start again.
Thank you.
The above code should be simplified to the following. I'm using this to remove unwanted retweets but not retweets my own tweets.
setInterval(
function() {
document.querySelector('[data-testid="unretweet"]').click()
document.querySelector('[data-testid="unretweetConfirm"]').click()
},
500
)
Reference: https://gist.github.com/martgil/ddd7da50712105777029bbacb5123265
This is a terrific idea, but I'm not sure I've got it working. It's throwing a few errors that might be, in light of the new ownership, to do with Twitter itself! Has anyone else got it working recently? It'd be great if someone could update! Cheers