Created
December 29, 2014 03:53
-
-
Save leebyron/d4ad335f833389642af8 to your computer and use it in GitHub Desktop.
Unsubscribe from all Amazon Birthday Alerts
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
/* | |
At some point I connected Facebook friends to Amazon wishlists. Now I get | |
multiple emails from Amazon for the birthday of everyone I ever met. | |
Removing people from this list requires a bunch of manual clicking. | |
Automation FTW. | |
1) http://www.amazon.com/gp/registry?ie=UTF8&type=wishlist | |
2) Paste this into Console | |
3) Make a coffee | |
*/ | |
function getPeople() { | |
return [].slice.call(document.getElementsByClassName('a-expander-container'), 2); | |
} | |
function isOpen(e) { | |
return e.getElementsByClassName('a-icon-section-collapse').length > 0; | |
} | |
function openPerson(e, cb) { | |
if (!isOpen(e)) { | |
if (![].slice.apply(e.getElementsByClassName('a-expander-prompt')).some( | |
a => (a.click(), true) | |
)) { | |
return cb(false); | |
} | |
var i = setInterval(() => { | |
if (isOpen(e)) { | |
clearInterval(i); | |
cb(true); | |
} | |
}, 10); | |
} else { | |
setTimeout(() => cb(true), 0); | |
} | |
} | |
function firstRemove(e) { | |
return [].slice.apply(e.getElementsByClassName('a-declarative')).filter(a => a.title === 'Remove this person').some( | |
a => (a.click(), true) | |
); | |
} | |
function clickRemove(e, cb) { | |
var r = [].slice.apply(document.getElementsByClassName('a-modal-scroller')).some( | |
p => [].slice.apply(p.getElementsByClassName('a-button-inner')).filter(a => 'Remove').some( | |
a => [].slice.apply(a.getElementsByTagName('input')).some( | |
i => { | |
i.click(); | |
var t = setInterval(() => { | |
if (e.parentElement == null) { | |
clearInterval(t); | |
p.parentElement.removeChild(p); | |
cb(true); | |
} | |
}, 10); | |
return true; | |
} | |
) | |
) | |
); | |
if (!r) { | |
cb(r); | |
} | |
} | |
function removePerson(cb) { | |
var p = getPeople()[0]; | |
if (p) { | |
openPerson( | |
p, | |
success => success && firstRemove(p) ? clickRemove(p, cb) : cb(false) | |
); | |
} else { | |
console.log('DONE'); | |
cb(false); | |
} | |
} | |
function removeAll() { | |
removePerson(success => success ? removeAll() : console.log('stopped')); | |
} | |
removeAll(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment