// ==UserScript== // @name Instagram Download Button // @name:zh-TW Instagram 下載器 // @namespace https://github.com/y252328/Instagram_Download_Button // @version 1.1.2 // @description Add download button to download media in the post and the story in Instagram // @description:zh-TW 在Instagram頁面加入下載按鈕,透過此按鈕可以下載貼文及限時動態 // @author ZhiYu // @match https://www.instagram.com/* // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; Date.prototype.yyyymmdd = function() { // ref: https://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object?page=1&tab=votes#tab-top var mm = this.getMonth() + 1; // getMonth() is zero-based var dd = this.getDate(); return [this.getFullYear(), (mm>9 ? '' : '0') + mm, (dd>9 ? '' : '0') + dd ].join(''); }; var svgTemplate = ` `; var checkExistTimer = setInterval(function() { let lang = document.getElementsByTagName("html")[0].getAttribute('lang'); let sharePost = "Share Post"; let menu = "Menu"; if (lang === "zh-tw") { menu = "功能表"; sharePost = "分享貼文"; } // check story if (document.getElementsByClassName("story-dl-btn").length == 0) { if(document.querySelector('span[aria-label="' + menu + '"]')) { addDownloadBtn(document.querySelector('span[aria-label="' + menu + '"]'), "story-dl-btn", "white"); } } // check post let articleList = document.querySelectorAll("article"); for( let i = 0 ; i < articleList.length ; i ++ ) { if(articleList[i].querySelector('svg[aria-label="' + sharePost + '"]') && articleList[i].getElementsByClassName("post-dl-btn").length == 0) { addDownloadBtn(articleList[i].querySelector('svg[aria-label="' + sharePost + '"]'), 'post-dl-btn', "black"); } } }, 500); function addDownloadBtn(node, className, iconColor) { // add download button to post or story page and set onclick handler var btn = document.createElement("div"); // Create a