Created
December 15, 2018 16:03
-
-
Save khaosdoctor/dabf95683171514725ca075d9704ac32 to your computer and use it in GitHub Desktop.
Saves all your saved images on instagram
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
Array.from($('#react-root > section > main > div > header + div + div + div > article > div > div').children).forEach(row => { | |
Array.from(row.children).forEach(async (image) => { | |
try { | |
const photoUrl = image.querySelector('a').getAttribute('href') | |
const response = await fetch(`https://instagram.com${photoUrl}`) | |
const responseText = await response.text() | |
const parser = new DOMParser() | |
const htmlDocument = parser.parseFromString(responseText, 'text/html') | |
const sharedData = JSON.parse(htmlDocument.querySelector('#react-root+script').innerText.replace('window._sharedData = ', '').replace('};', '}')) | |
const picData = sharedData.entry_data.PostPage[0] ? sharedData.entry_data.PostPage[0].graphql.shortcode_media : sharedData.entry_data | |
const username = `@${picData.owner.username}` | |
console.log(username, picData) | |
switch (picData.__typename) { | |
case 'GraphImage': | |
case 'GraphSidecar': | |
window.open(picData.display_url, '_blank') | |
break | |
case 'GraphVideo': | |
window.open(picData.video_url, '_blank') | |
break | |
} | |
} catch (err) { console.log(`Could not load image due to ${err.message}`); console.log(image) } | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment