Skip to content

Instantly share code, notes, and snippets.

@jawdatls
Last active September 30, 2020 11:50
Show Gist options
  • Save jawdatls/cc9f9dfa48b6991dfdeeac0c3f4af623 to your computer and use it in GitHub Desktop.
Save jawdatls/cc9f9dfa48b6991dfdeeac0c3f4af623 to your computer and use it in GitHub Desktop.
Instagram Exporter - run the script into console tab of inspector of browser then use the methods of instagram object in console after scroll down some posts.
/**
* Instagram Media Exporter
*
* @author: Jawdat Sobh
*/
(function(){
let _list = {}
window.addEventListener('scroll',function(event){
setTimeout(() => {
document.querySelectorAll('.FFVAD').forEach((e) => {
_list[e.getAttribute('src')] = 'image';
})
document.querySelectorAll('.tWeCl').forEach((e) => {
_list[e.getAttribute('src')] = 'video';
})
}, 10)
})
function list(){
console.log(Object.keys(_list))
}
function clear(){
_list = {}
}
function copy(content){
if(!content){
content = Object.keys(_list).filter(url => {
if(url !== null && url !== 'null'){
return url;
}
return false;
}).join('\r\n');
}
const text = document.createElement('textarea');
text.value = content;
document.body.appendChild(text);
text.select();
text.setSelectionRange(0, 99999);
document.execCommand("copy");
document.body.removeChild(text);
console.log('Copied');
}
function copyHtml(){
copy(createHtml())
}
function show(){
const popup = window.open('about:blank', '_blank');
popup.document.write(createHtml());
popup.document.close();
let delay = setInterval(() => {
if (popup.document.readyState === "complete") {
clearInterval(delay)
setTimeout(() => {
popup.focus()
}, 1000)
}
}, 10)
}
function createHtml(){
const out = [];
for(let url in _list){
if(url !== null && url !== 'null'){
const type = _list[url]
if(type === 'image'){
out.push('<div class="container"><img src="'+url+'"></div>');
}else if(type === 'video'){
out.push('<div class="container"><video controls name="media"><source src="'+url+'" type="video/mp4"></video></div>');
}
}
}
return `
<!DOCTYPE html>
<html>
<head>
<title>Instagram</title>
<style>
.container{
position: relative;
max-width: 500px;
width: 100%;
margin: 20px auto;
}
.container img{
display: block;
width: 100%;
}
.container video{
display: block;
width: 100%;
}
</style>
</head>
<body>
${out.join('')}
</body>
</html>
`;
}
function download(){
const filename = 'instagram-'+(new Date())+'.html';
const element = document.createElement('a');
element.setAttribute('href', 'data:text/html;charset=utf-8,' + encodeURIComponent(createHtml()));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
window.instagram = {list, clear, copy, copyHtml, show, download}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment