Last active
May 8, 2017 05:38
-
-
Save patrickhulce/de719998bf47f637a731e945b9db2567 to your computer and use it in GitHub Desktop.
Gather GMail Images
This file contains hidden or 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
(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