1 | javascript: (function () { 'use strict'; const PAGE_TYPE_ARTICLE = "article"; const PAGE_TYPE_STORY = "story"; const TIMEOUT_INTERVAL = 50; let linkIds = []; let links = new Set(); init(); function init() { 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 getLinkFromArticleFlow() { clickNextPageButton() .then(() => { getLinkFromArticle(); if (hasNextPageButton()) { getLinkFromArticleFlow(); } else { openLinks(links); removeElements(); } }); } function getLinkFromArticle() { let imgElements = document.querySelectorAll("._97aPb .FFVAD"); let videoElements = document.querySelectorAll(".tWeCl"); if (isExist(imgElements)) { imgElements.forEach(element => { links.add(element.src); }); } if (isExist(videoElements)) { videoElements.forEach(element => { links.add(element.src); }); } } 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 hasNextPageButton() { return document.querySelector("._6CZji") != null; } function clickNextPageButton() { return new Promise(resolve => { setTimeout(() => { if (isExist(document.querySelector("._6CZji"))) { document.querySelector("._6CZji").click(); } resolve(); }, TIMEOUT_INTERVAL); }); } function openLinks(links) { for (let link of links) { 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 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; } else if (obj == "") { result = false; } return result; } })(); |
Direct link: https://paste.plurk.com/show/dH3xDrfDUk3TazE3Oz86