1 | javascript: (function () { 'use strict'; const PAGE_TYPE_ARTICLE = "article"; const PAGE_TYPE_STORY = "story"; const TIMEOUT_INTERVAL = 400; let linkIds = []; let links = []; let currActions = []; let currActionStep = 0; init(); function init() { createActionList(); start(); } function start() { const page = getCurrentPageType(); switch(page) { case PAGE_TYPE_ARTICLE: getLinkFromArticleFlow(); break; case PAGE_TYPE_STORY: getLinkFromStory(); break; default: break; } } function getLinkFromStory() { const imgElement = document.querySelector(".y-yJ5"); const videoElement = document.querySelector("video"); if (isExist(imgElement)) { openLink(imgElement.src); removeElements(); } if (isExist(videoElement)) { openLink(videoElement.currentSrc); removeElements(); } } function removeElements() { linkIds.forEach(linkId => { document.getElementById(linkId).remove(); }); linkIds = []; } function createActionList() { let actionList = new Map(); actionList.set(1, ["G"]); actionList.set(2, ["G"]); actionList.set(3, ["N", "G"]); actionList.set(4, ["G", "N", "N", "N", "G"]); actionList.set(5, ["N", "G", "N", "N", "N", "G"]); actionList.set(6, ["N", "G", "N", "N", "N", "G"]); actionList.set(7, ["G", "N", "N", "N", "G", "N", "N", "N", "G"]); actionList.set(8, ["G", "N", "N", "N", "G", "N", "N", "N", "G"]); actionList.set(9, ["N", "G", "N", "N", "N", "G", "N", "N", "N", "G"]); actionList.set(10, ["G", "N", "N", "N", "G", "N", "N", "N", "G", "N", "N", "N", "G"]); const pageAmount = document.querySelectorAll(".Yi5aA").length; currActions = actionList.get(pageAmount); } function getLinkFromArticleFlow() { let currAction = currActions[currActionStep]; if (isExist(currAction)) { switch(currAction) { case "G": getLinkFromArticle().then(() => { currActionStep++; getLinkFromArticleFlow(); }); break; case "N": clickNextPageButton().then(() => { currActionStep++; getLinkFromArticleFlow(); }); break; } } else { openLinks(links); removeElements(); } } function getLinkFromArticle() { return new Promise((resolve, reject) => { window.setTimeout(() => { let imgElements = document.querySelectorAll(".FFVAD"); let videoElements = document.querySelectorAll("video"); if (isExist(imgElements)) { imgElements.forEach(element => { links.push(element.src); }); } if (isExist(videoElements)) { videoElements.forEach(element => { links.push(element.src); }); } resolve(); }, TIMEOUT_INTERVAL); }); } function getCurrentPageType() { const currUrl = window.location.href; const articlePattern = /^https:\/\/www\.instagram\.com\/p\//; const sotryPattern = /^https:\/\/www\.instagram\.com\/stories\//; if (currUrl.match(articlePattern)) { return PAGE_TYPE_ARTICLE; } else if (currUrl.match(sotryPattern)) { return PAGE_TYPE_STORY; } else { return null; } } function clickNextPageButton() { return new Promise((resolve, reject) => { window.setTimeout(() => { document.querySelector("._6CZji").click(); resolve(); }, TIMEOUT_INTERVAL); }); } function openLinks(links) { links.forEach(link => { let a = document.createElement('a'); a.setAttribute("href", link); a.setAttribute("target", "_blank"); a.id = getUUID(); document.body.appendChild(a); a.click(); linkIds.push(a.id); }); } function openLink(link) { if (isExist(link)) { let a = document.createElement('a'); a.setAttribute("href", link); a.setAttribute("target", "_blank"); a.id = getUUID(); document.body.appendChild(a); a.click(); linkIds.push(a.id); } } function getUUID() { let d = Date.now(); if (typeof performance !== 'undefined' && typeof performance.now === 'function'){ d += performance.now(); } return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { let r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); }); } function isExist(obj) { let result = true; if (obj == undefined || obj == null) { result = false; } return result; } })(); |
Direct link: https://paste.plurk.com/show/PP3qs6eGYqX5t3HKcGXC