// ==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.12.2 // @description Downloading is possible for both photos and videos from posts, as well as for stories, reels or profile picture. // @description:zh-TW 一鍵下載對方 Instagram 貼文中的相片、影片甚至是他們的限時動態、連續短片及大頭貼圖片! // @description:zh-CN 一键下载对方 Instagram 帖子中的相片、视频甚至是他们的快拍、Reels及头像图片! // @description:ja 投稿された写真や動画だけでなく、ストーリーズやリール動画からもダウンロードが可能です。 // @description:ko 게시물에 게시된 사진과 동영상 뿐만 아니라 스토리나 릴스에서도 다운로드가 가능합니다. // @author SN-Koarashi (5026) // @match https://*.instagram.com/* // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @grant GM_xmlhttpRequest // @grant GM_registerMenuCommand // @grant GM_getResourceText // @connect i.instagram.com // @require https://code.jquery.com/jquery-3.6.3.min.js#sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU= // @resource INTERNAL_CSS https://raw.githubusercontent.com/SN-Koarashi/ig-helper/master/style.css // @supportURL https://github.com/SN-Koarashi/ig-helper/ // @contributionURL https://ko-fi.com/snkoarashi // @icon https://www.google.com/s2/favicons?domain=www.instagram.com // @compatible firefox >= 87 // @compatible chrome >= 90 // @compatible edge >= 90 // @license GPL-3.0-only // @downloadURL none // ==/UserScript== (function($) { 'use strict'; // Icon download by https://www.flaticon.com/authors/pixel-perfect /******** USER SETTINGS ********/ // !!! DO NOT CHANGE THIS AREA !!! // PLEASE CHANGE SETTING WITH MENU const USER_SETTING = { 'AUTO_RENAME': (GM_getValue('AUTO_RENAME'))?GM_getValue('AUTO_RENAME'):true, 'RENAME_SHORTCODE': (GM_getValue('RENAME_SHORTCODE'))?GM_getValue('RENAME_SHORTCODE'):true, 'DISABLE_VIDEO_LOOPING': (GM_getValue('DISABLE_VIDEO_LOOPING'))?GM_getValue('DISABLE_VIDEO_LOOPING'):false, 'REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE': (GM_getValue('REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE'))?GM_getValue('REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE'):false, 'FORCE_FETCH_ALL_RESOURCES': (GM_getValue('FORCE_FETCH_ALL_RESOURCES'))?GM_getValue('FORCE_FETCH_ALL_RESOURCES'):false }; /*******************************/ const checkInterval = 250; const lang = navigator.language || navigator.userLanguage; const style = GM_getResourceText("INTERNAL_CSS"); GM_addStyle(style); GM_registerMenuCommand(_i18n('SETTING'), () => { showSetting(); }); GM_registerMenuCommand(_i18n('DEBUG'), () => { showDebugDOM(); }); var currentURL = location.href; var currentHeight = $(document).height(); var firstStarted = false; var pageLoaded = false; var GL_postPath; var GL_username; var GL_repeat; var GL_dataCache = { stories: {}, highlights: {} }; // Main Timer var timer = setInterval(function(){ currentHeight = $(document).height(); // Call Instagram dialog function if url changed. if(currentURL != location.href || !firstStarted || !pageLoaded){ clearInterval(GL_repeat); pageLoaded = false; firstStarted = true; currentURL = location.href; if(location.href.startsWith("https://www.instagram.com/p/") || location.href.startsWith("https://www.instagram.com/reel/")){ GL_dataCache.stories = {}; console.log('isDialog'); setTimeout(()=>{ onReadyMyDW(false); },150); pageLoaded = true; } if(location.href.startsWith("https://www.instagram.com/reels/")){ console.log('isReels'); setTimeout(()=>{ onReels(false); },150); pageLoaded = true; } if(location.href.split("?")[0] == "https://www.instagram.com/"){ GL_dataCache.stories = {}; console.log('isHomepage'); setTimeout(()=>{ onReadyMyDW(false); },150); pageLoaded = true; } if($('div[id^="mount"] > div > div > div').first().is(':hidden') && $('canvas._aarh').length && location.href.match(/^(https:\/\/www\.instagram\.com\/)([0-9A-Za-z\.\-_]+)\/?$/ig) && !location.href.match(/^(https:\/\/www\.instagram\.com\/(stories|explore)\/?)/ig)){ console.log('isProfile'); setTimeout(()=>{ onProfileAvatar(false); },150); pageLoaded = true; } if(!pageLoaded){ // Call Instagram stories function if(location.href.match(/^(https:\/\/www\.instagram\.com\/stories\/highlights\/)/ig)){ GL_dataCache.highlights = {}; console.log('isHighlightsStory'); onHighlightsStory(false); GL_repeat = setInterval(()=>{ onHighlightsStoryThumbnail(false); },checkInterval); if($(".IG_DWHISTORY").length) setTimeout(()=>{pageLoaded = true;},150); } else if(location.href.match(/^(https:\/\/www\.instagram\.com\/stories\/)/ig)){ console.log('isStory'); onStory(false); onStoryThumbnail(false); if($(".IG_DWSTORY").length) setTimeout(()=>{pageLoaded = true;},150); } else{ pageLoaded = false; // Remove the download icon $('.IG_DWSTORY').remove(); $('.IG_DWSTORY_THUMBNAIL').remove(); } } } },checkInterval); // Call general function when user scroll the page $(document).scroll(function(){ if(currentHeight != $(this).height() && location.href.split("?")[0] == "https://www.instagram.com/"){ onReadyMyDW(); } }); /** * onProfileAvatar * Trigger user avatar download event or button display event. * * @param {Boolean} isDownload - Check if it is a download operation * @return {void} */ async function onProfileAvatar(isDownload){ if(isDownload){ let date = new Date().getTime(); let timestamp = Math.floor(date / 1000); let username = location.href.replace(/\/$/ig,'').split('/').at(-1); let userInfo = await getUserId(username); try{ let dataURL = await getUserHighSizeProfile(userInfo.user.pk); saveFiles(dataURL,username,"avatar",timestamp,'jpg'); } catch(err){ saveFiles(userInfo.user.profile_pic_url,username,"avatar",timestamp,'jpg'); } } else{ // Add the profile download button if(!$('.IG_DWPROFILE').length){ let profileTimer = setInterval(()=>{ if($('.IG_DWPROFILE').length) clearInterval(profileTimer); $('body > div main canvas._aarh').parent().append(`
`); },150); } } } /** * onHighlightsStory * Trigger user's highlight download event or button display event. * * @param {Boolean} isDownload - Check if it is a download operation * @return {void} */ async function onHighlightsStory(isDownload){ if(isDownload){ let date = new Date().getTime(); let timestamp = Math.floor(date / 1000); let highlightId = location.href.replace(/\/$/ig,'').split('/').at(-1); let nowIndex = $("body > div section._ac0a header._ac0k > ._ac3r ._ac3n ._ac3p[style]").length || $('body > div section:visible > div > div:not([class]) > div > div div.x1ned7t2.x78zum5 div.x1caxmr6').length || $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div').find('div div.x1ned7t2.x78zum5 div.x1caxmr6').length; let username = ""; let target = 0; if(GL_dataCache.highlights[highlightId]){ console.log('Fetch from memory cache:', highlightId); let totIndex = GL_dataCache.highlights[highlightId].data.reels_media[0].items.length; username = GL_dataCache.highlights[highlightId].data.reels_media[0].owner.username; target = GL_dataCache.highlights[highlightId].data.reels_media[0].items[totIndex-nowIndex]; } else{ let highStories = await getHighlightStories(highlightId); let totIndex = highStories.data.reels_media[0].items.length; username = highStories.data.reels_media[0].owner.username; target = highStories.data.reels_media[0].items[totIndex-nowIndex]; GL_dataCache.highlights[highlightId] = highStories; } if(target.is_video){ saveFiles(target.video_resources.at(-1).src,username,"highlights",timestamp,'mp4', highlightId); } else{ saveFiles(target.display_resources.at(-1).src,username,"highlights",timestamp,'jpg', highlightId); } } else{ // Add the stories download button if(!$('.IG_DWHISTORY').length){ let $element = null; // Default detecter (section layout mode) if($('body > div section._ac0a').length > 0){ $element = $('body > div section:visible._ac0a'); } else{ $element = $('body > div section:visible > div > div[style]:not([class])'); $element.css('position','relative'); } // Detecter for div layout mode // GitHub issue #3: DiceMast3r if($element.length === 0){ let $$element = $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div'); let nowSize = 0; $$element.each(function(){ if($(this).width() > nowSize){ nowSize = $(this).width(); $element = $(this); } }); } if($element != null){ //$element.css('position','relative'); $element.append(``); } } } } /** * onHighlightsStoryThumbnail * Trigger user's highlight video thumbnail download event or button display event. * * @param {Boolean} isDownload - Check if it is a download operation * @return {void} */ async function onHighlightsStoryThumbnail(isDownload){ if(isDownload){ let date = new Date().getTime(); let timestamp = Math.floor(date / 1000); let highlightId = location.href.replace(/\/$/ig,'').split('/').at(-1); let username = ""; let nowIndex = $("body > div section._ac0a header._ac0k > ._ac3r ._ac3n ._ac3p[style]").length || $('body > div section:visible > div > div:not([class]) > div > div div.x1ned7t2.x78zum5 div.x1caxmr6').length || $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div').find('div div.x1ned7t2.x78zum5 div.x1caxmr6').length; let target = ""; if(GL_dataCache.highlights[highlightId]){ console.log('Fetch from memory cache:', highlightId); let totIndex = GL_dataCache.highlights[highlightId].data.reels_media[0].items.length; username = GL_dataCache.highlights[highlightId].data.reels_media[0].owner.username; target = GL_dataCache.highlights[highlightId].data.reels_media[0].items[totIndex-nowIndex]; } else{ let highStories = await getHighlightStories(highlightId); let totIndex = highStories.data.reels_media[0].items.length; username = highStories.data.reels_media[0].owner.username; target = highStories.data.reels_media[0].items[totIndex-nowIndex]; GL_dataCache.highlights[highlightId] = highStories; } saveFiles(target.display_resources.at(-1).src,username,"highlights",timestamp,'jpg', highlightId); } else{ if($('body > div section video.xh8yej3').length){ // Add the stories download button if(!$('.IG_DWHISTORY_THUMBNAIL').length){ let $element = null; // Default detecter (section layout mode) if($('body > div section._ac0a').length > 0){ $element = $('body > div section:visible._ac0a'); } else{ $element = $('body > div section:visible > div > div[style]:not([class])'); $element.css('position','relative'); } // Detecter for div layout mode // GitHub issue #3: DiceMast3r if($element.length === 0){ let $$element = $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div'); let nowSize = 0; $$element.each(function(){ if($(this).width() > nowSize){ nowSize = $(this).width(); $element = $(this); } }); } if($element != null){ $element.append(``); } } } else{ $('.IG_DWHISTORY_THUMBNAIL').remove(); } } } /** * onStory * Trigger user's story download event or button display event. * * @param {Boolean} isDownload - Check if it is a download operation * @return {void} */ async function onStory(isDownload,isForce){ if(isDownload){ let date = new Date().getTime(); let timestamp = Math.floor(date / 1000); let username = $("body > div section._ac0a header._ac0k ._ac0l a + div a").first().text() || location.pathname.split('/').at(2); if($('body > div section:visible video[playsinline]').length > 0){ // Download stories if it is video let type = "mp4"; let videoURL = ""; let targetURL = location.pathname.replace(/\/$/ig,'').split("/").at(-1); if(GL_dataCache.stories[username] && !isForce){ console.log('Fetch from memory cache:', username); GL_dataCache.stories[username].data.reels_media[0].items.forEach(item => { if(item.id == targetURL){ videoURL = item.video_resources[0].src; } }); if(videoURL.length == 0){ console.log('Memory cache not found, try fetch from API:', username); onStory(true,true); return; } } else{ let userInfo = await getUserId(username); let userId = userInfo.user.pk; let stories = await getStories(userId); stories.data.reels_media[0].items.forEach(item => { if(item.id == targetURL){ videoURL = item.video_resources[0].src; } }); // GitHub issue #4: thinkpad4 if(videoURL.length == 0){ $('body > div section:visible div.x1ned7t2.x78zum5 > div').each(function(index){ if($(this).hasClass('x1lix1fw')){ if($(this).children().length > 0){ videoURL = stories.data.reels_media[0].items[index].video_resources[0].src; } } }); } GL_dataCache.stories[username] = stories; } if(videoURL.length == 0){ alert(_i18n("NO_VID_URL")); } else{ saveFiles(videoURL,username,"stories",timestamp,type); } } else{ // Download stories if it is image let srcset = $('body > div section:visible img[referrerpolicy]').attr('srcset')?.split(',')[0]?.split(' ')[0]; let link = (srcset)?srcset:$('body > div section:visible img[referrerpolicy]').attr('src'); let downloadLink = link; 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){ GL_dataCache.stories = {}; let $element = null; // Default detecter (section layout mode) if($('body > div section._ac0a').length > 0){ $element = $('body > div section:visible._ac0a'); } // detecter (single story layout mode) else{ $element = $('body > div section:visible > div > div[style]:not([class])'); $element.css('position','relative'); } // Detecter for div layout mode // GitHub issue #3: DiceMast3r if($element.length === 0){ let $$element = $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div'); let nowSize = 0; $$element.each(function(){ if($(this).width() > nowSize){ nowSize = $(this).width(); $element = $(this); } }); } if($element != null){ $element.css('position','relative'); $element.append(``); } } } } /** * onStoryThumbnail * Trigger user's story video thumbnail download event or button display event. * * @param {Boolean} isDownload - Check if it is a download operation * @return {void} */ async function onStoryThumbnail(isDownload,isForce){ if(isDownload){ // Download stories if it is video let date = new Date().getTime(); let timestamp = Math.floor(date / 1000); let type = 'jpg'; let username = $("body > div section._ac0a header._ac0k ._ac0l a + div a").first().text() || location.pathname.split('/').at(2); 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 let targetURL = location.pathname.replace(/\/$/ig,'').split("/").at(-1); let videoThumbnailURL = ""; if(GL_dataCache.stories[username] && !isForce){ console.log('Fetch from memory cache:', username); GL_dataCache.stories[username].data.reels_media[0].items.forEach(item => { if(item.id == targetURL){ videoThumbnailURL = item.display_url; } }); if(videoThumbnailURL.length == 0){ console.log('Memory cache not found, try fetch from API:', username); onStoryThumbnail(true,true); return; } } else{ let userInfo = await getUserId(username); let userId = userInfo.user.pk; let stories = await getStories(userId); stories.data.reels_media[0].items.forEach(item => { if(item.id == targetURL){ videoThumbnailURL = item.display_url; } }); // GitHub issue #4: thinkpad4 if(videoThumbnailURL.length == 0){ $('body > div section:visible div.x1ned7t2.x78zum5 > div').each(function(index){ if($(this).hasClass('x1lix1fw')){ if($(this).children().length > 0){ videoThumbnailURL = stories.data.reels_media[0].items[index].display_url; } } }); } } saveFiles(videoThumbnailURL,username,"thumbnail",timestamp,type); } else{ if($('body > div section video.xh8yej3').length){ // Add the stories download button if(!$('.IG_DWSTORY_THUMBNAIL').length){ let $element = null; // Default detecter (section layout mode) if($('body > div section._ac0a').length > 0){ $element = $('body > div section:visible._ac0a'); } // detecter (single story layout mode) else{ $element = $('body > div section:visible > div > div[style]:not([class])'); $element.css('position','relative'); } // Detecter for div layout mode // GitHub issue #3: DiceMast3r if($element.length === 0){ let $$element = $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div'); let nowSize = 0; $$element.each(function(){ if($(this).width() > nowSize){ nowSize = $(this).width(); $element = $(this); } }); } if($element != null){ $element.css('position','relative'); $element.append(``); } } } else{ $('.IG_DWSTORY_THUMBNAIL').remove(); } } } /** * onReels * Trigger user's reels download event or button display event. * * @param {Boolean} isDownload - Check if it is a download operation * @param {Boolean} isVideo - Check if reel is a video element * @return {void} */ async function onReels(isDownload, isVideo){ if(isDownload){ let reelsPath = location.href.split('?').at(0).split('instagram.com/reels/').at(-1).replaceAll('/',''); let data = await getBlobMedia(reelsPath); let timestamp = new Date().getTime(); if(isVideo && data.shortcode_media.is_video){ let type = 'mp4'; saveFiles(data.shortcode_media.video_url,data.shortcode_media.owner.username,"reels",timestamp,type,reelsPath); } else{ let type = 'jpg'; saveFiles(data.shortcode_media.display_resources.at(-1).src,data.shortcode_media.owner.username,"reels",timestamp,type,reelsPath); } } else{ //$('.IG_REELS_THUMBNAIL, .IG_REELS').remove(); var timer = setInterval(()=>{ if($('section > main[role="main"] > div div.x1qjc9v5 video').length > 0){ clearInterval(timer); $('section > main[role="main"] > div').children('div').each(function(){ if($(this).children().length > 0){ if(!$(this).children().find('.IG_REELS').length){ $(this).children().css('position','relative'); $(this).children().append(``); $(this).children().append(``); // Disable video autoplay if(USER_SETTING.DISABLE_VIDEO_LOOPING){ $(this).find('video').each(function(){ if(!$(this).data('loop')){ console.log('Added video event listener'); $(this).on('ended',function(){ $(this).attr('data-loop', true); $(this).parent().find('.xpgaw4o').removeAttr('style'); console.log('paused'); this.pause(); }); } }); } } } }); } },250); } } /** * getHighlightStories * Get a list of all stories in highlight Id. * * @param {Integer} highlightId * @return {Object} */ function getHighlightStories(highlightId){ return new Promise((resolve,reject)=>{ let getURL = `https://www.instagram.com/graphql/query/?query_hash=45246d3fe16ccc6577e0bd297a5db1ab&variables=%7B%22highlight_reel_ids%22:%5B%22${highlightId}%22%5D,%22precomposed_overlay%22:false%7D`; GM_xmlhttpRequest({ method: "GET", url: getURL, onload: function(response) { let obj = JSON.parse(response.response); resolve(obj); }, onerror: function(err){ reject(err); } }); }); } /** * getStories * Get a list of all stories in user Id. * * @param {Integer} userId * @return {Object} */ function getStories(userId){ return new Promise((resolve,reject)=>{ let getURL = `https://www.instagram.com/graphql/query/?query_hash=15463e8449a83d3d60b06be7e90627c7&variables=%7B%22reel_ids%22:%5B%22${userId}%22%5D,%22precomposed_overlay%22:false%7D`; GM_xmlhttpRequest({ method: "GET", url: getURL, onload: function(response) { let obj = JSON.parse(response.response); resolve(obj); }, onerror: function(err){ reject(err); } }); }); } /** * getUserId * Get user's id with username * * @param {String} username * @return {Integer} */ function getUserId(username){ return new Promise((resolve,reject)=>{ let getURL = `https://www.instagram.com/web/search/topsearch/?query=${username}`; GM_xmlhttpRequest({ method: "GET", url: getURL, onload: function(response) { let obj = JSON.parse(response.response); resolve(obj.users[0]); }, onerror: function(err){ reject(err); } }); }); } /** * getUserHighSizeProfile * Get user's high quality avatar image. * * @param {Integer} userId * @return {String} */ function getUserHighSizeProfile(userId){ return new Promise((resolve,reject)=>{ let getURL = `https://i.instagram.com/api/v1/users/${userId}/info/`; GM_xmlhttpRequest({ method: "GET", url: getURL, headers: { 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; Pixel 7 XL)Build/RP1A.20845.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/5.0 Chrome/117.0.5938.60 Mobile Safari/537.36 Instagram 307.0.0.34.111' }, onload: function(response) { let obj = JSON.parse(response.response); if(obj.status !== 'ok'){ reject('faild'); } else{ resolve(obj.user.hd_profile_pic_url_info?.url); } }, onerror: function(err){ reject(err); } }); }); } /** * getPostOwner * Get post's author with post shortcode * * @param {String} postPath * @return {String} */ function getPostOwner(postPath){ return new Promise((resolve,reject)=>{ if(!postPath) reject("NOPATH"); let postShortCode = postPath; let getURL = `https://www.instagram.com/graphql/query/?query_hash=2c4c2e343a8f64c625ba02b2aa12c7f8&variables=%7B%22shortcode%22:%22${postShortCode}%22}`; GM_xmlhttpRequest({ method: "GET", url: getURL, onload: function(response) { let obj = JSON.parse(response.response); resolve(obj.data.shortcode_media.owner.username); }, onerror: function(err){ reject(err); } }); }); } /** * getBlobMedia * Get list of all media files in post with post shortcode * * @param {String} postPath * @return {Object} */ function getBlobMedia(postPath){ return new Promise((resolve,reject)=>{ if(!postPath) reject("NOPATH"); let postShortCode = postPath; let getURL = `https://www.instagram.com/graphql/query/?query_hash=2c4c2e343a8f64c625ba02b2aa12c7f8&variables=%7B%22shortcode%22:%22${postShortCode}%22}`; GM_xmlhttpRequest({ method: "GET", url: getURL, onload: function(response) { let obj = JSON.parse(response.response); console.log(obj); resolve(obj.data); }, onerror: function(err){ reject(err); } }); }); } /** * onReadyMyDW * Create an event entry point for the download button for the post * * @param {Boolean} NoDialog - Check if it not showing the dialog * @return {void} */ function onReadyMyDW(NoDialog){ // Whether is Instagram dialog? if(!NoDialog){ // Running if it is dialog $('article, main > div > div.xdt5ytf > div').each(function(){ $(this).removeAttr('data-snig'); $(this).unbind('click'); }); $('.SNKMS_IG_DW_MAIN,.SNKMS_IG_DW_MAIN_VIDEO').remove(); } if(NoDialog == false){ var repeat = setInterval(() => { // div.x13ehr01 << (sigle post in top, not floating) >> if($('article[data-snig="canDownload"], section:visible > main > div > div.xdt5ytf > div[data-snig="canDownload"]').length > 0) clearInterval(repeat); createDownloadButton(); },250); } else{ createDownloadButton(); } } /** * createDownloadButton * Create a download button in the upper right corner of each post * * @return {void} */ function createDownloadButton(){ // Add download icon per each posts $('article, section:visible > main > div > div.xdt5ytf').each(function(index){ // If it is have not download icon // class x1iyjqo2 mean user profile pages post list container if(!$(this).attr('data-snig') && !$(this).hasClass('x1iyjqo2') && !$(this).children('article')?.hasClass('x1iyjqo2')){ console.log("Found article"); var rightPos = 15; // not loop each in single top post if(this.tagName === "DIV" && index != 0){ return; } // Add the download icon let $childElement = $(this).children("div").children("div"); $childElement.eq((this.tagName === "DIV")? 0 : $childElement.length - 2).append(``); $childElement.css('position','relative'); // Disable video autoplay if(USER_SETTING.DISABLE_VIDEO_LOOPING){ $(this).find('video').each(function(){ if(!$(this).data('loop')){ console.log('Added video event listener'); $(this).on('ended',function(){ $(this).attr('data-loop', true); this.pause(); }); } }); } // Running if user click the download icon $(this).on('click','.SNKMS_IG_DW_MAIN', async function(e){ GL_username = $(this).parent().parent().parent().attr('data-username'); GL_postPath = location.pathname.replace(/\/$/,'').split('/').at(-1) || $(this).parent().parent().children("div:last-child").children("div").children("div:last-child").find('a[href^="/p/"]').last().attr("href").split("/").at(2); // Create element that download dailog IG_createDM(GM_getValue('AutoDownload'), true); $("#article-id").html(`${GL_postPath}`); // Find video/image element and add the download icon var s = 0; var multiple = $(this).parent().parent().find('._aap0 ._acaz').length; var pathname = window.location.pathname; var fullpathname = "/"+pathname.split('/')[1]+"/"+pathname.split('/')[2]+"/"; var blob = USER_SETTING.FORCE_FETCH_ALL_RESOURCES; // If posts have more than one images or videos. if(multiple){ $(this).parent().find('._aap0 ._acaz').each(function(){ let element_videos = $(this).parent().parent().find('video'); //if(element_videos && element_videos.attr('src') && element_videos.attr('src').match(/^blob:/ig)){ if(element_videos && element_videos.attr('src')){ blob = true; } }); if(blob){ createMediaListDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",_i18n("LOAD_BLOB_MULTIPLE")); } else{ $(this).parent().find('._aap0 ._acaz').each(function(){ s++; let element_videos = $(this).find('video'); let element_images = $(this).find('._aagv img'); let imgLink = (element_images.attr('srcset'))?element_images.attr('srcset').split(" ")[0]:element_images.attr('src'); if(element_videos && element_videos.attr('src')){ blob = true; /* let video_image = element_videos.attr('poster'); let video_url = element_videos.attr('src'); $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY').append(`'+ message +'
'); let media = await getBlobMedia(postURL); let idx = 1; let resource = media.shortcode_media; // GraphVideo if(resource.__typename == "GraphVideo" && resource.video_url){ $(selector).append(`