// ==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.1.2 // @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 // @require https://code.jquery.com/jquery-3.5.1.min.js // @supportURL https://www.facebook.com/smileopwe/ // @compatible firefox >=52 // @compatible chrome >=55 // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Close icon download by https://www.flaticon.com/authors/roundicons // Download icon download by https://www.flaticon.com/authors/pixel-perfect // Global variable GM_setValue('dialog',true); GM_setValue('URLs',location.href); var $ = window.jQuery; // Main Timer var timer = setInterval(function(){ // Record document height GM_setValue('oldHeight',$(document).height()); // Call Instagram dialog function if url changed. if(GM_getValue('URLs') != location.href && $('div.PdwC2.fXiEu.s2MYR').length && onChangeURL()){ console.log('isDialog'); onReadyMyDW(false); GM_setValue('URLs',location.href); } // Call general function if($('article ._97aPb[data-snig="canDownload"]').length==0 && onChangeURL() && !$('div._2dDPU[role="dialog"]').length){ console.log(true); onReadyMyDW(true); } // Call Instagram stories function if($('div#react-root section._9eogI._01nki.lXJWB').length && onChangeStoryURL()){ onStoryDW(false); } else{ // Remove the download icon $('.IG_DWSTORY').remove(); } // Direct Download Checkbox if(!$('.AutoDownload_dom').length){ var ckValue = (GM_getValue('AutoDownload'))?'checked':''; $('body .ctQZg').append('
'); } },500); // Call general function when user scroll the page $(document).scroll(function(){ if(GM_getValue('oldHeight') != $(this).height()){ console.log('onChange'); onReadyMyDW(); } }); // Stories funcion function onStoryDW(a){ if(a){ if($('video.y-yJ5').length){ // Download stories if it is video let downloadLink = $('video.y-yJ5 source').attr('src')+'&dl=1'; let date = new Date().getTime(); let timestamp = Math.floor(date / 1000); let type = 'mp4'; let username = $("._8XqED .QgJA_ .aOX72 .MS2JH .soMvl ._4EzTm .yn6BW").text(); saveFiles(downloadLink,username,0,timestamp,type); } else{ // Download stories if it is image let downloadLink = $('img.y-yJ5').attr('src')+'&dl=1'; let date = new Date().getTime(); let timestamp = Math.floor(date / 1000); let type = 'jpg'; let username = $("._8XqED .QgJA_ .aOX72 .MS2JH .soMvl ._4EzTm .yn6BW").text(); saveFiles(downloadLink,username,0,timestamp,type); } } else{ // Add the stories download button var style = "position: absolute;right:-40px;top:15px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;"; if(!$('.IG_DWSTORY').length){ $('div#react-root section._8XqED').append('') } } } // URL change function function onChangeURL(){ var reA = /^(https:\/\/www.instagram.com\/p\/)/g; var reB = /^(https:\/\/www.instagram.com\/)$/g; var URLs = location.href; if(URLs.match(reA) || URLs.match(reB)){ return true; } } // URL change function if page in stories function onChangeStoryURL(){ var re = /^(https:\/\/www.instagram.com\/stories\/)/g; var URLs = location.href; if(URLs.match(re)){ return true; } } // Main function function onReadyMyDW(NoDialog){ // Whether is Instagram dialog? if(!NoDialog){ // Running if it is dialog $('article ._97aPb').each(function(){ $(this).removeAttr('data-snig'); $(this).unbind('click'); }); $('.SNKMS_IG_DW_MAIN,.SNKMS_IG_DW_MAIN_VIDEO').remove(); } // Add download icon per each posts $('article ._97aPb').each(function(){ // If it is have not download icon if(!$(this).attr('data-snig')){ var style = "position: absolute;right:15px;top:15px;padding:6px;line-height:1;background:#fff;border-radius: 50%;cursor:pointer;"; // Add the download icon $(this).append(''); // Running if user click the download icon $(this).on('click','.SNKMS_IG_DW_MAIN',function(e){ GM_setValue('username',$(this).parent().attr('data-username')); // Create element that download dailog IG_createDM(GM_getValue('AutoDownload')); var 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;'; // Find video/image element and add the download icon var s = 0; $(this).parent().find('.EcJQs .RzuR0').each(function(){ s++; if($(this).children().find('video.tWeCl') && $(this).children().find('video.tWeCl').attr('src')){ $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('