// ==UserScript==
// @name Instagram Download Button
// @name:zh-TW Instagram 下載器
// @namespace https://github.com/y252328/Instagram_Download_Button
// @version 1.0.0
// @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
// @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() {
// check story
if (document.getElementsByClassName("story-dl-btn").length == 0) {
if(document.querySelector('span[aria-label="功能表"]')) {
addDownloadBtn(document.querySelector('span[aria-label="功能表"]'), "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="分享貼文"]') && articleList[i].getElementsByClassName("post-dl-btn").length == 0) {
addDownloadBtn(articleList[i].querySelector('svg[aria-label="分享貼文"]'), '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