// ==UserScript== // @name IG Helper // @name:zh-TW IG小精靈 // @name:zh-CN IG小助手 // @name:ja IG助手 // @name:ko IG조수 // @namespace https://github.snkms.com/ // @version 2.3.4.5 // @description Downloading Instagram posts photos and videos or their stories! // @description:zh-TW 一鍵下載對方 Instagram 貼文中的相片、影片甚至是他們的限時動態! // @description:zh-CN 一键下载对方 Instagram 帖子中的相片、视频甚至是他们的快拍! // @description:ja 写真、ビデオ、そしてお互いの Instagram 投稿からのストーリーずズのワンクリックダウンロード! // @description:ko Instagram 게시물에서 사진, 비디오 또는 이야기를 다운로드하십시오. // @author SN-Koarashi (5026) // @match https://*.instagram.com/* // @grant GM_setValue // @grant GM_getValue // @grant GM_xmlhttpRequest // @grant unsafeWindow // @require https://code.jquery.com/jquery-3.6.0.min.js // @supportURL https://www.facebook.com/smileopwe/ // @compatible firefox >= 87 // @compatible chrome >= 90 // @compatible edge >= 90 // @license GPLv3 // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Icon download by https://www.flaticon.com/authors/pixel-perfect // Global variable GM_setValue('currnetURL',location.href); const $ = window.jQuery; const checkInterval = 250; var __additionalData = unsafeWindow.__additionalData; var currentURL = location.href; var currentHeight = $(document).height(); var firstStarted = false; var pageLoaded = false; // Main Timer var timer = setInterval(function(){ currentHeight = $(document).height(); // Call Instagram dialog function if url changed. if(currentURL != location.href || GM_getValue('currnetURL') != location.href || !firstStarted || !pageLoaded){ pageLoaded = false; firstStarted = true; currentURL = location.href; GM_setValue('currnetURL',location.href); if($('div.sspdcydq[role="dialog"]').length){ console.log('isDialog'); onReadyMyDW(false); pageLoaded = true; } if(location.href == "https://www.instagram.com/"){ console.log('isHomepage'); onReadyMyDW(false); pageLoaded = true; } if(!pageLoaded){ // Call Instagram stories function if(location.href.match(/^(https:\/\/www\.instagram\.com\/stories\/)/ig)){ console.log('isStory'); onStoryDW(false); onStoryThumbnailDW(false); if($(".IG_DWSTORY").length) setTimeout(()=>{pageLoaded = true;},150); } else{ pageLoaded = false; // Remove the download icon $('.IG_DWSTORY').remove(); $('.IG_DWSTORY_THUMBNAIL').remove(); } } } // Direct Download Checkbox if(!$('.AutoDownload_dom').length){ let ckValue = (GM_getValue('AutoDownload'))?'checked':''; $('body ._acuq._acur').append('
'); } },checkInterval); // Call general function when user scroll the page $(document).scroll(function(){ if(currentHeight != $(this).height()){ onReadyMyDW(); } }); // Stories funcion function onStoryDW(isDownload){ if(isDownload){ let date = new Date().getTime(); let timestamp = Math.floor(date / 1000); let username = $("body > div section._ac0a header._ac0k ._ac0l div ._ac0q > a").text(); if($('body > div section._ac0a video._aa63').length){ // Download stories if it is video let downloadLink = $('video._aa63 source').attr('src')+'&dl=1'; let type = 'mp4'; saveFiles(downloadLink,username,"stories",timestamp,type); } else{ // Download stories if it is image let srcset = $('section._ac0a ._aa64 img._aa63').attr('srcset').split(',')[0].split(' ')[0]; let link = (srcset)?srcset:$('section._ac0a ._aa64 img._aa63').attr('src'); let downloadLink = link+'&dl=1'; let type = 'jpg'; saveFiles(downloadLink,username,"stories",timestamp,type); } } else{ // Add the stories download button let style = "position: absolute;right:-40px;top:15px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;"; if(!$('.IG_DWSTORY').length){ $('body > div section._ac0a').append('
'); return true; } } } // Stories Thumbnail funcion function onStoryThumbnailDW(isDownload){ if(isDownload){ // Download stories if it is video let srcset = $('section._ac0a ._aa64 img._aa63').attr('srcset').split(',')[0].split(' ')[0]; let downloadLink = (srcset)?srcset:$('section._ac0a ._aa64 img._aa63').attr('src'); let date = new Date().getTime(); let timestamp = Math.floor(date / 1000); let type = 'jpg'; let username = $("body > div section._ac0a header._ac0k ._ac0l div ._ac0q > a").text(); let style = 'margin:5px 0px;padding:5px 0px;color:#111;font-size:1rem;line-height:1rem;text-align:center;border:1px solid #000;border-radius: 5px;'; // Download thumbnail saveFiles(downloadLink,username,"thumbnail",timestamp,type); } else{ if($('body > div section._ac0a video._aa63').length){ // Add the stories download button let style = "position: absolute;right:-40px;top:45px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;"; if(!$('.IG_DWSTORY_THUMBNAIL').length){ $('body > div section._ac0a').append('
'); } } else{ $('.IG_DWSTORY_THUMBNAIL').remove(); } } } // Prepare promise to cache article which contains blob media function getBlobMedia(){ return new Promise((resolve,reject)=>{ if(!GM_getValue('postpath')) reject("NOPATH"); GM_xmlhttpRequest({ method: "GET", url: "https://www.instagram.com"+GM_getValue('postpath'), onload: function(response) { let result = response.response; let mediaArr = [...result.matchAll(/