Instagram Downloader

Adds a download button for Instagram posts online.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Instagram Downloader
// @namespace    https://6869net.tk/
// @version      0.1
// @description  Adds a download button for Instagram posts online.
// @author       The 6869net Team
// @match        https://www.instagram.com/p/*
// @grant        none
// ==/UserScript==

(function() {
    // If you like my code and want to use it in your creation, feel free -- just cite my website link within your creation somewhere: https://6869net.tk/
    // (A developer's gotta eat! :D)
    function instagramDownloaderCode() {
        var img = document.querySelector("#react-root > section > main > div > div > article > div > div > div > div > img")
        var srcset = img.getAttribute("srcset");
        console.log(srcset);
        var splitsrcset = srcset.split(",");
        var splitsrc = splitsrcset[splitsrcset.length - 1].split(" ");
        var correctsrc = splitsrc[0];
        console.log(correctsrc);
        var downloadbutton = document.createElement("button");
        downloadbutton.setAttribute("onclick", "var link = document.createElement('a');link.download = 'instadl.jpg';link.href = '" + correctsrc + "';document.body.appendChild(link);link.click();document.body.removeChild(link);delete link;");
        downloadbutton.setAttribute("width", "40");
        downloadbutton.setAttribute("height", "40");
        var downloadtextnode = document.createTextNode("DL");
        downloadbutton.appendChild(downloadtextnode);
        var buttonspan = document.querySelector("#react-root > section > main > div > div > article > div > section > span");
        buttonspan.appendChild(downloadbutton);
    }
    // don't run the code until after a second -- until after the page has loaded
    setTimeout(instagramDownloaderCode, 1000);
})();