Ndrs24 / ig-post-fetcher

Descarga fotos y videos de publicaciones de instagram

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Para que sirve

Este script sirve para poder descargar las imágenes y videos de una publicación de instagram, ojo, este script solo funciona estando dentro de una publicación de instagram, de lo contrario no funcionará, solo sirve para poder descargar las imágenes y videos de una publicación de instagram, pronto agregaré más funciones.

Como usar

Estando dentro de una publicación de instagram, abre la consola del navegador, copia el codigo de abajo y pégalo en la consola, le das enter, y listo.

(async()=>{let t,e=!1,n=!1;const i=document.createElement("div");i.role="button",i.textContent="Abrir",i.addEventListener("click",(async()=>{if(e)t.remove(),t=null,e=!1,i.textContent="Abrir";else{if(n)return;n=!0,i.textContent="Cargando...";try{t=await async function(){if(void 0===typeof window)throw alert("This script must be run in the browser");const t=new URL(window.location.href);if("https://www.instagram.com"!==t.origin)throw alert("This script must be run on Instagram");const e=t.pathname.split("/");if("p"!==e[1])throw alert("This script must be run on a post");t.pathname=e.slice(0,3).join("/"),t.search="__a=1&__d=dis";const n=await fetch(t);if(!n.ok)throw alert("Failed to fetch post");const i=await n.json();if(!i.items[0])throw alert("Uknow fetch data");const o=i.items[0];let r;switch(o.media_type){case 1:r={type:"image",sources:[o.image_versions2.candidates[0].url]};break;case 2:r={type:"video",sources:[o.video_versions[0].url]};break;case 8:r={type:"image",sources:o.carousel_media.map((t=>t.image_versions2.candidates[0].url))};break;default:throw alert("Uknow post type")}const s=document.createElement("div");return s.innerHTML=`<style>.modalIGPF {position: fixed;inset: 0;margin: auto;width: 15rem;height: 21rem;padding: 1rem;background: blue;color: white;border-radius: 5px;box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);overflow: auto;z-index: 99999;}.fcIGPF {display:flex;align-items:center;jutify-content:center;}.imgIGPF {width: 50px;height: 50px;object-fit: cover;border-radius: 5px;}</style><h1 style="margin-bottom:12px;text-align:center;font-size:20px">Resultado</h1><div class="fcIGPF" style="width:100%;flex-direction:column;gap:5px">${r.sources.map((t=>"image"===r.type?`<div class="fcIGPF" style="gap:10px"><div><img src="${t}" class="imgIGPF" /></div><div><a href="${t}" target="_blank">Ver en HD</a></div></div>`:`<div class="fcIGPF" style="gap:10px"><div><video src="${t}" class="imgIGPF"></video></div><div><a href="${t}" target="_blank">Ver en HD</a></div></div>`)).join("")}</div>`,s.classList.add("modalIGPF"),document.body.appendChild(s),s}()}catch(t){return n=!1,void(i.textContent="Abrir")}n=!1,e=!0,i.textContent="Cerrar"}})),i.style.position="fixed",i.style.bottom="1rem",i.style.right="1rem",i.style.padding="10px",i.style.zIndex="99999",i.style.backgroundColor="blue",i.style.color="white",i.style.borderRadius="5px",i.style.cursor="pointer",i.addEventListener("mouseover",(()=>{i.style.backgroundColor="darkblue"})),i.addEventListener("mouseout",(()=>{i.style.backgroundColor="blue"})),document.body.appendChild(i)})();  

Como usar en celular

Primero copia el código de arriba, luego estando dentro de una publicación de instagram, en la barra de navegación, borra todo y escribe lo siguiente:

javascript:

Luego pega el codigo copiado, te quedaría así:

javascript:(async()=>{if(void 0===typ...

Recuerda escribir "javascript:" manualmente y despues pegar el código, debido a que no se puede pegar directamente todo.

Si usas el teclado GBoard y tienes activado el portapales, puedes copiar lo siguiente de uno en uno y despues pegarlo en la barra de navegación para que te sea más fácil.

javascript
:
(async()=>{let t,e=!1,n=!1;const i=document.createElement("div");i.role="button",i.textContent="Abrir",i.addEventListener("click",(async()=>{if(e)t.remove(),t=null,e=!1,i.textContent="Abrir";else{if(n)return;n=!0,i.textContent="Cargando...";try{t=await async function(){if(void 0===typeof window)throw alert("This script must be run in the browser");const t=new URL(window.location.href);if("https://www.instagram.com"!==t.origin)throw alert("This script must be run on Instagram");const e=t.pathname.split("/");if("p"!==e[1])throw alert("This script must be run on a post");t.pathname=e.slice(0,3).join("/"),t.search="__a=1&__d=dis";const n=await fetch(t);if(!n.ok)throw alert("Failed to fetch post");const i=await n.json();if(!i.items[0])throw alert("Uknow fetch data");const o=i.items[0];let r;switch(o.media_type){case 1:r={type:"image",sources:[o.image_versions2.candidates[0].url]};break;case 2:r={type:"video",sources:[o.video_versions[0].url]};break;case 8:r={type:"image",sources:o.carousel_media.map((t=>t.image_versions2.candidates[0].url))};break;default:throw alert("Uknow post type")}const s=document.createElement("div");return s.innerHTML=`<style>.modalIGPF {position: fixed;inset: 0;margin: auto;width: 15rem;height: 21rem;padding: 1rem;background: blue;color: white;border-radius: 5px;box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);overflow: auto;z-index: 99999;}.fcIGPF {display:flex;align-items:center;jutify-content:center;}.imgIGPF {width: 50px;height: 50px;object-fit: cover;border-radius: 5px;}</style><h1 style="margin-bottom:12px;text-align:center;font-size:20px">Resultado</h1><div class="fcIGPF" style="width:100%;flex-direction:column;gap:5px">${r.sources.map((t=>"image"===r.type?`<div class="fcIGPF" style="gap:10px"><div><img src="${t}" class="imgIGPF" /></div><div><a href="${t}" target="_blank">Ver en HD</a></div></div>`:`<div class="fcIGPF" style="gap:10px"><div><video src="${t}" class="imgIGPF"></video></div><div><a href="${t}" target="_blank">Ver en HD</a></div></div>`)).join("")}</div>`,s.classList.add("modalIGPF"),document.body.appendChild(s),s}()}catch(t){return n=!1,void(i.textContent="Abrir")}n=!1,e=!0,i.textContent="Cerrar"}})),i.style.position="fixed",i.style.bottom="1rem",i.style.right="1rem",i.style.padding="10px",i.style.zIndex="99999",i.style.backgroundColor="blue",i.style.color="white",i.style.borderRadius="5px",i.style.cursor="pointer",i.addEventListener("mouseover",(()=>{i.style.backgroundColor="darkblue"})),i.addEventListener("mouseout",(()=>{i.style.backgroundColor="blue"})),document.body.appendChild(i)})();

Como volver a compilar

Si tienes dudas sobre el código, puedes revisar los archivos del respositorio y ver que hace el codígo que estás usando. Para compilar (minificar) el codigo ejecuta el siguiente comando en NodeJS, este comando regenerará tambien el README.md (Este mismo archivo) con el código actulizado.

npm run build

About

Descarga fotos y videos de publicaciones de instagram


Languages

Language:JavaScript 100.0%