Skip to content

Instantly share code, notes, and snippets.

@saleiva
Forked from subtleGradient/delete twitter DMs.js
Last active July 16, 2020 01:00
Show Gist options
  • Save saleiva/9975531 to your computer and use it in GitHub Desktop.
Save saleiva/9975531 to your computer and use it in GitHub Desktop.
//goto: https://twitter.com/messages?since_id=0
// delete console.log
querySelectorAttempt._timerIDs = []
function querySelectorAttempt(selectors, callback, _attempts){
if (!Array.isArray(selectors)) selectors = selectors.toString().split(/\s*,\s*/)
console.log('querySelectorAttempt', selectors, _attempts)
if (_attempts == null) _attempts = 20;
var elements
selectors.forEach(function(selector){
if (elements && elements.length > 0) return;
elements = document.querySelectorAll(selector);
})
if (elements && elements.length > 0) callback(null, [].slice.call(elements))
else {
querySelectorAttempt._timerIDs[querySelectorAttempt._timerIDs.length] =
setTimeout(function(){
_attempts--
if (_attempts === 0) return callback(Error("ran out of attempts: " + selectors))
querySelectorAttempt(selectors, callback, _attempts)
}, 100)
}
}
function deleteTwitterDM(callback){
while (querySelectorAttempt._timerIDs.length) clearTimeout(querySelectorAttempt._timerIDs.pop());
querySelectorAttempt(['.dm-thread'], function(error, buttons){
if (error) return console.error(error)
buttons[0].click()
querySelectorAttempt(['.dm-delete'], function(error, buttons){
if (error) return console.error(error)
buttons.forEach(function(button){ button.click() })
querySelectorAttempt(['.js-prompt-ok'], function(error, buttons){
if (error) return console.error(error)
buttons.forEach(function(button){ button.click() })
callback && callback(null)
})
})
})
}
function deleteTwitterDMLoop(){
deleteTwitterDM(function(){
setTimeout(deleteTwitterDMLoop, 1000)
})
}
deleteTwitterDMLoop()
@pkedrosky
Copy link

Any idea if this has worked for anyone recently, or has Twitter changed HTML structure/selectors too much?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment