-
-
Save saleiva/9975531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any idea if this has worked for anyone recently, or has Twitter changed HTML structure/selectors too much?