Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
Created July 8, 2013 02:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save subtleGradient/5945754 to your computer and use it in GitHub Desktop.
Save subtleGradient/5945754 to your computer and use it in GitHub Desktop.
Delete Twitter Direct Messages. Go here: https://twitter.com/messages?since_id=0 Then paste this stuff into your Chrome inspector console
// 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, 500)
})
}
deleteTwitterDMLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment