Skip to content

Instantly share code, notes, and snippets.

@palaueb
Last active January 17, 2025 09:16
Show Gist options
  • Save palaueb/8ce2f9eddd6babdd4c398f4d5e8dc5b5 to your computer and use it in GitHub Desktop.
Save palaueb/8ce2f9eddd6babdd4c398f4d5e8dc5b5 to your computer and use it in GitHub Desktop.
DDT: Deleter of Data on Twitter
/*
* DISCLAIMER:
* This script is provided 'as is', without warranty of any kind, express or implied.
* The author will not be liable for any damages, loss of data, or any other harm
* resulting from the use of this script.
*
* This script is intended for educational purposes only. Use it at your own risk.
* By using this script, you agree to assume all responsibilities and consequences
* associated with its execution.
*
* This code will continue working meanwhile Twitter don't delete the attributes for
* his functional tests, it uses data-testid attribute to find the desired elements
* and click it.
*
* INSTRUCTIONS:
* 1. Open Twitter in your web browser.
* 2. Open the browser's developer console.
* 3. Copy and paste this script into the console and execute it.
*
* IMPORTANT: Ensure you understand the effects of this script before running it.
*
*/
function processTweet(tweet) {
var article = tweet.querySelector('article');
if (!article) {
tweet.remove();
return;
}
var like = tweet.querySelector('button[data-testid="unlike"]');
if (like) {
like.click();
}
var ret = tweet.querySelector('button[data-testid="unretweet"]');
if (ret) {
ret.click();
var randomVal=randomIntFromInterval(100,300);
setTimeout(confirmUnretweet, randomVal);
}
var caret = tweet.querySelector('button[data-testid="caret"]');
if (caret) {
caret.click();
var randomVal=randomIntFromInterval(100,300);
setTimeout(pressDelete, randomVal);
}
}
function pressDelete() {
var dropmenu = document.querySelector('div[data-testid="Dropdown"]');
if (dropmenu) {
//get first div child of dropmenu
var delbtn = dropmenu.querySelector('div:first-child');
if (delbtn) {
delbtn.click();
var randomVal=randomIntFromInterval(100,300);
setTimeout(confirmDelete, randomVal);
}
}
}
function confirmDelete() {
var confirm = document.querySelector('button[data-testid="confirmationSheetConfirm"]');
if (confirm) {
confirm.click();
}
}
function confirmUnretweet() {
var confirm = document.querySelector('div[data-testid="unretweetConfirm"]');
if (confirm) {
confirm.click();
}
}
function processTweets(tweets, index = 0) {
if (index < tweets.length) {
processTweet(tweets[index]);
}
}
function goWithAnotherTweet(){
var panel = document.querySelectorAll('div[aria-label^="Cronologia: Pub"]');
tweets = panel.querySelectorAll('div[data-testid="cellInnerDiv"]');
console.log("Remaining:", tweets.length);
processTweets(tweets);
var initialRandomVal=randomIntFromInterval(1000,3000);
console.log("Next action in " + initialRandomVal + " milliseconds (Done " + (++totalActions) + " actions)");
setTimeout(goWithAnotherTweet, initialRandomVal);
}
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min);
}
var totalActions = 0;
var initialRandomVal=randomIntFromInterval(1000,3000);
console.log("Initial action in " + initialRandomVal + " milliseconds");
setTimeout(goWithAnotherTweet, initialRandomVal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment