Skip to content

Instantly share code, notes, and snippets.

@patrickhulce
Last active May 8, 2017 05:38
Show Gist options
  • Save patrickhulce/de719998bf47f637a731e945b9db2567 to your computer and use it in GitHub Desktop.
Save patrickhulce/de719998bf47f637a731e945b9db2567 to your computer and use it in GitHub Desktop.
Gather GMail Images
(alreadySeen => {
function downloadURI(uri) {
console.log('trying to download')
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
return new Promise(resolve => setTimeout(resolve, 2000 + Math.round(Math.random() * 1000)))
}
const images = [...document.querySelectorAll('img')]
images.reduce((promise, img, index) => {
return promise.then(() => {
const url = new URL(img.src)
if (url.host === 'mail.google.com' && !alreadySeen.has(url.href)) {
alreadySeen.add(url.href)
url.searchParams.set('sz', 'w10000-h10000')
return downloadURI(url.href, `image${index}.jpg`)
}
}).catch(() => Promise.resolve())
}, Promise.resolve())
})(window.__alreadySeen = window.__alreadySeen || new Set())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment