IG小助手

一键下载对方 Instagram 帖子中的相片、视频甚至是他们的快拍、Reels!

当前为 2023-06-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name IG Helper
  3. // @name:zh-TW IG小精靈
  4. // @name:zh-CN IG小助手
  5. // @name:ja IG助手
  6. // @name:ko IG조수
  7. // @namespace https://github.snkms.com/
  8. // @version 2.5.6.2
  9. // @description Downloading is possible for both photos and videos from posts, as well as for stories or reels.
  10. // @description:zh-TW 一鍵下載對方 Instagram 貼文中的相片、影片甚至是他們的限時動態、連續短片!
  11. // @description:zh-CN 一键下载对方 Instagram 帖子中的相片、视频甚至是他们的快拍、Reels!
  12. // @description:ja 投稿された写真や動画だけでなく、ストーリーズやリール動画からもダウンロードが可能です。
  13. // @description:ko 게시물에 게시된 사진과 동영상 뿐만 아니라 스토리나 릴스에서도 다운로드가 가능합니다.
  14. // @author SN-Koarashi (5026)
  15. // @match https://*.instagram.com/*
  16. // @grant GM_setValue
  17. // @grant GM_getValue
  18. // @grant GM_xmlhttpRequest
  19. // @require https://code.jquery.com/jquery-3.6.3.min.js#sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=
  20. // @supportURL https://discord.gg/Sh8HJ4d
  21. // @contributionURL https://ko-fi.com/snkoarashi
  22. // @icon https://www.google.com/s2/favicons?domain=www.instagram.com
  23. // @compatible firefox >= 87
  24. // @compatible chrome >= 90
  25. // @compatible edge >= 90
  26. // @license GPLv3
  27. // ==/UserScript==
  28.  
  29. (function($) {
  30. 'use strict';
  31. // Icon download by https://www.flaticon.com/authors/pixel-perfect
  32.  
  33. /******** USER SETTINGS ********/
  34.  
  35. // Auto rename file to format type following:
  36. // USERNAME-TYPE-TIMESTAMP.FILETYPE
  37. // Example: instagram-photo-1670350000.jpg
  38. //
  39. // If set to false, the file name will remain as it is.
  40. // Example: instagram_321565527_679025940443063_4318007696887450953_n.jpg
  41. const AUTO_RENAME = true;
  42. /*******************************/
  43.  
  44. const checkInterval = 250;
  45. const lang = navigator.language || navigator.userLanguage;
  46.  
  47. var currentURL = location.href;
  48. var currentHeight = $(document).height();
  49. var firstStarted = false;
  50. var pageLoaded = false;
  51.  
  52. var GL_postPath;
  53. var GL_username;
  54. var GL_repeat
  55. var GL_dataCache = {
  56. stories: {},
  57. highlights: {}
  58. };
  59.  
  60. // Main Timer
  61. var timer = setInterval(function(){
  62. currentHeight = $(document).height();
  63.  
  64. // Call Instagram dialog function if url changed.
  65. if(currentURL != location.href || !firstStarted || !pageLoaded){
  66. clearInterval(GL_repeat);
  67. pageLoaded = false;
  68. firstStarted = true;
  69. currentURL = location.href;
  70.  
  71. if(location.href.startsWith("https://www.instagram.com/p/") || location.href.startsWith("https://www.instagram.com/reel/")){
  72. GL_dataCache.stories = {};
  73.  
  74. console.log('isDialog');
  75. setTimeout(()=>{
  76. onReadyMyDW(false);
  77. },150);
  78. pageLoaded = true;
  79. }
  80.  
  81. if(location.href.startsWith("https://www.instagram.com/reels/")){
  82. console.log('isReels');
  83. setTimeout(()=>{
  84. onReelsDW(false);
  85. },150);
  86. pageLoaded = true;
  87. }
  88.  
  89. if(location.href.split("?")[0] == "https://www.instagram.com/"){
  90. GL_dataCache.stories = {};
  91.  
  92. console.log('isHomepage');
  93. setTimeout(()=>{
  94. onReadyMyDW(false);
  95. },150);
  96. pageLoaded = true;
  97. }
  98. if(!$('body > div div.x9f619 div._adqx[data-visualcompletion="loading-state"]').length && $('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)){
  99. console.log('isProfile');
  100. setTimeout(()=>{
  101. onProfileDW(false);
  102. },150);
  103. pageLoaded = true;
  104. }
  105.  
  106. if(!pageLoaded){
  107. // Call Instagram stories function
  108. if(location.href.match(/^(https:\/\/www\.instagram\.com\/stories\/highlights\/)/ig)){
  109. GL_dataCache.highlights = {};
  110.  
  111. console.log('isHighlightsStory');
  112. onHighlightsStoryDW(false);
  113. GL_repeat = setInterval(()=>{
  114. onHighlightsStoryThumbnailDW(false);
  115. },checkInterval);
  116.  
  117. if($(".IG_DWHISTORY").length) setTimeout(()=>{pageLoaded = true;},150);
  118. }
  119. else if(location.href.match(/^(https:\/\/www\.instagram\.com\/stories\/)/ig)){
  120. console.log('isStory');
  121. onStoryDW(false);
  122. onStoryThumbnailDW(false);
  123.  
  124. if($(".IG_DWSTORY").length) setTimeout(()=>{pageLoaded = true;},150);
  125. }
  126. else{
  127. pageLoaded = false;
  128. // Remove the download icon
  129. $('.IG_DWSTORY').remove();
  130. $('.IG_DWSTORY_THUMBNAIL').remove();
  131. }
  132. }
  133.  
  134. }
  135.  
  136. // Direct Download Checkbox
  137. /*
  138. if(!$('.AutoDownload_dom').length){
  139. let ckValue = (GM_getValue('AutoDownload'))?'checked':'';
  140. $('body div.mfclru0v.astyfpdk.om3e55n1.jez8cy9q').css('position','relative');
  141. $('body div.mfclru0v.astyfpdk.om3e55n1.jez8cy9q').append(`<div class="AutoDownload_dom" style="position:absolute;left:10px;bottom:7px;padding:0px;line-height:1;display:inline-block;width:fit-content;"><label title="${_i18n("DDL_INTRO")}" style="cursor:help;"><input type="checkbox" value="1" class="AutoDownload" name="AutoDownload" ${ckValue} />${_i18n("DDL")}</label></div>`);
  142. }
  143. */
  144. },checkInterval);
  145.  
  146. // Call general function when user scroll the page
  147. $(document).scroll(function(){
  148. if(currentHeight != $(this).height() && location.href.split("?")[0] == "https://www.instagram.com/"){
  149. onReadyMyDW();
  150. }
  151. });
  152.  
  153. // Profile funcion
  154. async function onProfileDW(isDownload){
  155. if(isDownload){
  156. let date = new Date().getTime();
  157. let timestamp = Math.floor(date / 1000);
  158. let username = location.href.replace(/\/$/ig,'').split('/').at(-1);
  159. let userInfo = await getUserId(username);
  160.  
  161. saveFiles(userInfo.user.profile_pic_url,username,"avatar",timestamp,'jpg');
  162. }
  163. else{
  164. // Add the stories download button
  165. let style = "position: absolute;right:0px;top:0px;padding:5px;line-height:1;background:#fff;border-radius: 50%;cursor:pointer;border: 1px solid #ccc";
  166. if(!$('.IG_DWPROFILE').length){
  167. $('body > div main canvas._aarh').parent().append(`<div title="${_i18n("DW")}" class="IG_DWPROFILE" style="${style}"><svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"><g><g><path d="M382.56,233.376C379.968,227.648,374.272,224,368,224h-64V16c0-8.832-7.168-16-16-16h-64c-8.832,0-16,7.168-16,16v208h-64 c-6.272,0-11.968,3.68-14.56,9.376c-2.624,5.728-1.6,12.416,2.528,17.152l112,128c3.04,3.488,7.424,5.472,12.032,5.472 c4.608,0,8.992-2.016,12.032-5.472l112-128C384.192,245.824,385.152,239.104,382.56,233.376z"/></g></g><g><g><path d="M432,352v96H80v-96H16v128c0,17.696,14.336,32,32,32h416c17.696,0,32-14.304,32-32V352H432z"/></g></g></div>`);
  168. return true;
  169. }
  170. }
  171. }
  172.  
  173. // Highlight Stories funcion
  174. async function onHighlightsStoryDW(isDownload){
  175. if(isDownload){
  176. let date = new Date().getTime();
  177. let timestamp = Math.floor(date / 1000);
  178. let highlightId = location.href.replace(/\/$/ig,'').split('/').at(-1);
  179. let nowIndex = $("body > div section._ac0a header._ac0k > ._ac3r ._ac3n ._ac3p[style]").length;
  180. let username = "";
  181. let target = 0;
  182.  
  183. if(GL_dataCache.highlights[highlightId]){
  184. console.log('Fetch from memory cache:', highlightId);
  185.  
  186. let totIndex = GL_dataCache.highlights[highlightId].data.reels_media[0].items.length;
  187. username = GL_dataCache.highlights[highlightId].data.reels_media[0].owner.username;
  188. target = GL_dataCache.highlights[highlightId].data.reels_media[0].items[totIndex-nowIndex];
  189. }
  190. else{
  191. let highStories = await getHighlightsStories(highlightId);
  192. let totIndex = highStories.data.reels_media[0].items.length;
  193. username = highStories.data.reels_media[0].owner.username;
  194. target = highStories.data.reels_media[0].items[totIndex-nowIndex];
  195.  
  196. GL_dataCache.highlights[highlightId] = highStories;
  197. }
  198.  
  199. if(target.is_video){
  200. saveFiles(target.video_resources.at(-1).src,username,"highlights",timestamp,'mp4');
  201. }
  202. else{
  203. saveFiles(target.display_resources.at(-1).src,username,"highlights",timestamp,'jpg');
  204. }
  205. }
  206. else{
  207. // Add the stories download button
  208. let style = "position: absolute;right:-40px;top:15px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  209. if(!$('.IG_DWHISTORY').length){
  210. $('body > div section._ac0a').append(`<div title="${_i18n("DW")}" class="IG_DWHISTORY" style="${style}"><svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"><g><g><path d="M382.56,233.376C379.968,227.648,374.272,224,368,224h-64V16c0-8.832-7.168-16-16-16h-64c-8.832,0-16,7.168-16,16v208h-64 c-6.272,0-11.968,3.68-14.56,9.376c-2.624,5.728-1.6,12.416,2.528,17.152l112,128c3.04,3.488,7.424,5.472,12.032,5.472 c4.608,0,8.992-2.016,12.032-5.472l112-128C384.192,245.824,385.152,239.104,382.56,233.376z"/></g></g><g><g><path d="M432,352v96H80v-96H16v128c0,17.696,14.336,32,32,32h416c17.696,0,32-14.304,32-32V352H432z"/></g></g></div>`);
  211. return true;
  212. }
  213. }
  214. }
  215.  
  216. // Highlight Stories Thumbnail funcion
  217. async function onHighlightsStoryThumbnailDW(isDownload){
  218. if(isDownload){
  219. let date = new Date().getTime();
  220. let timestamp = Math.floor(date / 1000);
  221. let highlightId = location.href.replace(/\/$/ig,'').split('/').at(-1);
  222. let username = "";
  223. let nowIndex = $("body > div section._ac0a header._ac0k > ._ac3r ._ac3n ._ac3p[style]").length;
  224. let target = "";
  225.  
  226. if(GL_dataCache.highlights[highlightId]){
  227. console.log('Fetch from memory cache:', highlightId);
  228.  
  229. let totIndex = GL_dataCache.highlights[highlightId].data.reels_media[0].items.length;
  230. username = GL_dataCache.highlights[highlightId].data.reels_media[0].owner.username;
  231. target = GL_dataCache.highlights[highlightId].data.reels_media[0].items[totIndex-nowIndex];
  232. }
  233. else{
  234. let highStories = await getHighlightsStories(highlightId);
  235. let totIndex = highStories.data.reels_media[0].items.length;
  236. username = highStories.data.reels_media[0].owner.username;
  237. target = highStories.data.reels_media[0].items[totIndex-nowIndex];
  238.  
  239. GL_dataCache.highlights[highlightId] = highStories;
  240. }
  241.  
  242. saveFiles(target.display_resources.at(-1).src,username,"highlights",timestamp,'jpg');
  243. }
  244. else{
  245. if($('body > div section._ac0a video.xh8yej3').length){
  246. // Add the stories download button
  247. let style = "position: absolute;right:-40px;top:45px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  248. if(!$('.IG_DWHISTORY_THUMBNAIL').length){
  249. $('body > div section._ac0a').append(`<div title="${_i18n("THUMBNAIL_INTRO")}" class="IG_DWHISTORY_THUMBNAIL" style="${style}"><svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="512" viewBox="0 0 24 24" width="512"><circle cx="8.25" cy="5.25" r=".5"/><path d="m8.25 6.5c-.689 0-1.25-.561-1.25-1.25s.561-1.25 1.25-1.25 1.25.561 1.25 1.25-.561 1.25-1.25 1.25zm0-1.5c-.138 0-.25.112-.25.25 0 .275.5.275.5 0 0-.138-.112-.25-.25-.25z"/><path d="m7.25 11.25 2-2.5 2.25 1.5 2.25-3.5 3 4.5z"/><path d="m16.75 12h-9.5c-.288 0-.551-.165-.676-.425s-.09-.568.09-.793l2-2.5c.243-.304.678-.372 1.002-.156l1.616 1.077 1.837-2.859c.137-.212.372-.342.625-.344.246-.026.49.123.63.334l3 4.5c.153.23.168.526.037.77-.13.244-.385.396-.661.396zm-4.519-1.5h3.118l-1.587-2.381zm-3.42 0h1.712l-1.117-.745z"/><path d="m22.25 14h-2.756c-.778 0-1.452.501-1.676 1.247l-.859 2.862c-.16.533-.641.891-1.197.891h-7.524c-.556 0-1.037-.358-1.197-.891l-.859-2.861c-.224-.747-.897-1.248-1.676-1.248h-2.756c-.965 0-1.75.785-1.75 1.75v5.5c0 1.517 1.233 2.75 2.75 2.75h18.5c1.517 0 2.75-1.233 2.75-2.75v-5.5c0-.965-.785-1.75-1.75-1.75z"/><path d="m4 12c-.552 0-1-.448-1-1v-8c0-1.654 1.346-3 3-3h12c1.654 0 3 1.346 3 3v8c0 .552-.448 1-1 1s-1-.448-1-1v-8c0-.551-.449-1-1-1h-12c-.551 0-1 .449-1 1v8c0 .552-.448 1-1 1z"/></svg></div>`);
  250. }
  251. }
  252. else{
  253. $('.IG_DWHISTORY_THUMBNAIL').remove();
  254. }
  255. }
  256. }
  257.  
  258. // Stories funcion
  259. async function onStoryDW(isDownload,isForce){
  260. if(isDownload){
  261. let date = new Date().getTime();
  262. let timestamp = Math.floor(date / 1000);
  263. let username = $("body > div section._ac0a header._ac0k ._ac0l a + div a").text() || location.pathname.split('/').at(2);
  264.  
  265. if($('body > div section._ac0a div._ac0b video.x1lliihq').length){
  266. // Download stories if it is video
  267. let type = "mp4";
  268. let videoURL = "";
  269. let targetURL = location.href.replace(/\/$/ig,'').split("/").at(-1);
  270.  
  271. if(GL_dataCache.stories[username] && !isForce){
  272. console.log('Fetch from memory cache:', username);
  273. GL_dataCache.stories[username].data.reels_media[0].items.forEach(item => {
  274. if(item.id == targetURL){
  275. videoURL = item.video_resources[0].src;
  276. }
  277. });
  278.  
  279. if(videoURL.length == 0){
  280. console.log('Memory cache not found, try fetch from API:', username);
  281. onStoryDW(true,true);
  282. return;
  283. }
  284. }
  285. else{
  286. let userInfo = await getUserId(username);
  287. let userId = userInfo.user.pk;
  288. let stories = await getStories(userId);
  289.  
  290. stories.data.reels_media[0].items.forEach(item => {
  291. if(item.id == targetURL){
  292. videoURL = item.video_resources[0].src;
  293. }
  294. });
  295.  
  296. GL_dataCache.stories[username] = stories;
  297. }
  298.  
  299. if(videoURL.length == 0){
  300. alert(_i18n("NO_VID_URL"));
  301. }
  302. else{
  303. saveFiles(videoURL,username,"stories",timestamp,type);
  304. }
  305.  
  306. }
  307. else{
  308. // Download stories if it is image
  309. let srcset = $('section._ac0a ._aa64 img._aa63').attr('srcset').split(',')[0].split(' ')[0];
  310. let link = (srcset)?srcset:$('section._ac0a ._aa64 img._aa63').attr('src');
  311.  
  312. let downloadLink = link;
  313. let type = 'jpg';
  314.  
  315. saveFiles(downloadLink,username,"stories",timestamp,type);
  316. }
  317. }
  318. else{
  319. // Add the stories download button
  320. let style = "position: absolute;right:-40px;top:15px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  321. if(!$('.IG_DWSTORY').length){
  322. GL_dataCache.stories = {};
  323. $('body > div section._ac0a').append(`<div title="${_i18n("DW")}" class="IG_DWSTORY" style="${style}"><svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"><g><g><path d="M382.56,233.376C379.968,227.648,374.272,224,368,224h-64V16c0-8.832-7.168-16-16-16h-64c-8.832,0-16,7.168-16,16v208h-64 c-6.272,0-11.968,3.68-14.56,9.376c-2.624,5.728-1.6,12.416,2.528,17.152l112,128c3.04,3.488,7.424,5.472,12.032,5.472 c4.608,0,8.992-2.016,12.032-5.472l112-128C384.192,245.824,385.152,239.104,382.56,233.376z"/></g></g><g><g><path d="M432,352v96H80v-96H16v128c0,17.696,14.336,32,32,32h416c17.696,0,32-14.304,32-32V352H432z"/></g></g></div>`);
  324. return true;
  325. }
  326. }
  327. }
  328.  
  329. // Stories Thumbnail funcion
  330. async function onStoryThumbnailDW(isDownload,isForce){
  331. if(isDownload){
  332. // Download stories if it is video
  333. let date = new Date().getTime();
  334. let timestamp = Math.floor(date / 1000);
  335. let type = 'jpg';
  336. let username = $("body > div section._ac0a header._ac0k ._ac0l a + div a").text() || location.pathname.split('/').at(2);
  337. 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;';
  338. // Download thumbnail
  339. let targetURL = location.href.replace(/\/$/ig,'').split("/").at(-1);
  340. let videoThumbnailURL = "";
  341.  
  342.  
  343. if(GL_dataCache.stories[username] && !isForce){
  344. console.log('Fetch from memory cache:', username);
  345. GL_dataCache.stories[username].data.reels_media[0].items.forEach(item => {
  346. if(item.id == targetURL){
  347. videoThumbnailURL = item.display_url;
  348. }
  349. });
  350.  
  351. if(videoThumbnailURL.length == 0){
  352. console.log('Memory cache not found, try fetch from API:', username);
  353. onStoryThumbnailDW(true,true);
  354. return;
  355. }
  356. }
  357. else{
  358. let userInfo = await getUserId(username);
  359. let userId = userInfo.user.pk;
  360. let stories = await getStories(userId);
  361.  
  362. stories.data.reels_media[0].items.forEach(item => {
  363. if(item.id == targetURL){
  364. videoThumbnailURL = item.display_url;
  365. }
  366. });
  367. }
  368.  
  369. saveFiles(videoThumbnailURL,username,"thumbnail",timestamp,type);
  370. }
  371. else{
  372. if($('body > div section._ac0a video.xh8yej3').length){
  373. // Add the stories download button
  374. let style = "position: absolute;right:-40px;top:45px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  375. if(!$('.IG_DWSTORY_THUMBNAIL').length){
  376. $('body > div section._ac0a').append(`<div title="${_i18n("THUMBNAIL_INTRO")}" class="IG_DWSTORY_THUMBNAIL" style="${style}"><svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="512" viewBox="0 0 24 24" width="512"><circle cx="8.25" cy="5.25" r=".5"/><path d="m8.25 6.5c-.689 0-1.25-.561-1.25-1.25s.561-1.25 1.25-1.25 1.25.561 1.25 1.25-.561 1.25-1.25 1.25zm0-1.5c-.138 0-.25.112-.25.25 0 .275.5.275.5 0 0-.138-.112-.25-.25-.25z"/><path d="m7.25 11.25 2-2.5 2.25 1.5 2.25-3.5 3 4.5z"/><path d="m16.75 12h-9.5c-.288 0-.551-.165-.676-.425s-.09-.568.09-.793l2-2.5c.243-.304.678-.372 1.002-.156l1.616 1.077 1.837-2.859c.137-.212.372-.342.625-.344.246-.026.49.123.63.334l3 4.5c.153.23.168.526.037.77-.13.244-.385.396-.661.396zm-4.519-1.5h3.118l-1.587-2.381zm-3.42 0h1.712l-1.117-.745z"/><path d="m22.25 14h-2.756c-.778 0-1.452.501-1.676 1.247l-.859 2.862c-.16.533-.641.891-1.197.891h-7.524c-.556 0-1.037-.358-1.197-.891l-.859-2.861c-.224-.747-.897-1.248-1.676-1.248h-2.756c-.965 0-1.75.785-1.75 1.75v5.5c0 1.517 1.233 2.75 2.75 2.75h18.5c1.517 0 2.75-1.233 2.75-2.75v-5.5c0-.965-.785-1.75-1.75-1.75z"/><path d="m4 12c-.552 0-1-.448-1-1v-8c0-1.654 1.346-3 3-3h12c1.654 0 3 1.346 3 3v8c0 .552-.448 1-1 1s-1-.448-1-1v-8c0-.551-.449-1-1-1h-12c-.551 0-1 .449-1 1v8c0 .552-.448 1-1 1z"/></svg></div>`);
  377. }
  378. }
  379. else{
  380. $('.IG_DWSTORY_THUMBNAIL').remove();
  381. }
  382. }
  383. }
  384.  
  385. // Reels funcion
  386. async function onReelsDW(isDownload, isVideo){
  387. if(isDownload){
  388. let reelsPath = location.href.split('?').at(0).split('instagram.com/reels/').at(-1).replaceAll('/','');
  389. let data = await getBlobMedia(reelsPath);
  390. let timestamp = new Date().getTime();
  391.  
  392. if(isVideo && data.shortcode_media.is_video){
  393. let type = 'mp4';
  394. saveFiles(data.shortcode_media.video_url,data.shortcode_media.owner.username,"reels",timestamp,type);
  395. }
  396. else{
  397. let type = 'jpg';
  398. saveFiles(data.shortcode_media.display_resources.at(-1).src,data.shortcode_media.owner.username,"reels",timestamp,type);
  399. }
  400. }
  401. else{
  402. //$('.IG_REELS_THUMBNAIL, .IG_REELS').remove();
  403. var timer = setInterval(()=>{
  404. if($('section > main[role="main"] > div div.x1qjc9v5 video').length > 0){
  405. clearInterval(timer);
  406. $('section > main[role="main"] > div').children('div').each(function(){
  407. if($(this).children().length > 0){
  408. if(!$(this).children().find('.IG_REELS').length){
  409. let style = "position: absolute;right:40px;top:15px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  410. let style2 = "position: absolute;right:40px;top:45px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  411.  
  412. $(this).children().css('position','relative');
  413.  
  414. $(this).children().append(`<div title="${_i18n("DW")}" class="IG_REELS" style="${style}"><svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"><g><g><path d="M382.56,233.376C379.968,227.648,374.272,224,368,224h-64V16c0-8.832-7.168-16-16-16h-64c-8.832,0-16,7.168-16,16v208h-64 c-6.272,0-11.968,3.68-14.56,9.376c-2.624,5.728-1.6,12.416,2.528,17.152l112,128c3.04,3.488,7.424,5.472,12.032,5.472 c4.608,0,8.992-2.016,12.032-5.472l112-128C384.192,245.824,385.152,239.104,382.56,233.376z"/></g></g><g><g><path d="M432,352v96H80v-96H16v128c0,17.696,14.336,32,32,32h416c17.696,0,32-14.304,32-32V352H432z"/></g></g></div>`);
  415. $(this).children().append(`<div title="${_i18n("THUMBNAIL_INTRO")}" class="IG_REELS_THUMBNAIL" style="${style2}"><svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="512" viewBox="0 0 24 24" width="512"><circle cx="8.25" cy="5.25" r=".5"/><path d="m8.25 6.5c-.689 0-1.25-.561-1.25-1.25s.561-1.25 1.25-1.25 1.25.561 1.25 1.25-.561 1.25-1.25 1.25zm0-1.5c-.138 0-.25.112-.25.25 0 .275.5.275.5 0 0-.138-.112-.25-.25-.25z"/><path d="m7.25 11.25 2-2.5 2.25 1.5 2.25-3.5 3 4.5z"/><path d="m16.75 12h-9.5c-.288 0-.551-.165-.676-.425s-.09-.568.09-.793l2-2.5c.243-.304.678-.372 1.002-.156l1.616 1.077 1.837-2.859c.137-.212.372-.342.625-.344.246-.026.49.123.63.334l3 4.5c.153.23.168.526.037.77-.13.244-.385.396-.661.396zm-4.519-1.5h3.118l-1.587-2.381zm-3.42 0h1.712l-1.117-.745z"/><path d="m22.25 14h-2.756c-.778 0-1.452.501-1.676 1.247l-.859 2.862c-.16.533-.641.891-1.197.891h-7.524c-.556 0-1.037-.358-1.197-.891l-.859-2.861c-.224-.747-.897-1.248-1.676-1.248h-2.756c-.965 0-1.75.785-1.75 1.75v5.5c0 1.517 1.233 2.75 2.75 2.75h18.5c1.517 0 2.75-1.233 2.75-2.75v-5.5c0-.965-.785-1.75-1.75-1.75z"/><path d="m4 12c-.552 0-1-.448-1-1v-8c0-1.654 1.346-3 3-3h12c1.654 0 3 1.346 3 3v8c0 .552-.448 1-1 1s-1-.448-1-1v-8c0-.551-.449-1-1-1h-12c-.551 0-1 .449-1 1v8c0 .552-.448 1-1 1z"/></svg></div>`);
  416. }
  417. }
  418. });
  419. }
  420. },250);
  421. }
  422. }
  423.  
  424. // Prepare promise to fetch user stories
  425. function getHighlightsStories(highlightId){
  426. return new Promise((resolve,reject)=>{
  427. 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`;
  428.  
  429. GM_xmlhttpRequest({
  430. method: "GET",
  431. url: getURL,
  432. onload: function(response) {
  433. let obj = JSON.parse(response.response);
  434. resolve(obj);
  435. },
  436. onerror: function(err){
  437. reject(err);
  438. }
  439. });
  440. });
  441. }
  442.  
  443. // Prepare promise to fetch user stories
  444. function getStories(userId){
  445. return new Promise((resolve,reject)=>{
  446. 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`;
  447.  
  448. GM_xmlhttpRequest({
  449. method: "GET",
  450. url: getURL,
  451. onload: function(response) {
  452. let obj = JSON.parse(response.response);
  453. resolve(obj);
  454. },
  455. onerror: function(err){
  456. reject(err);
  457. }
  458. });
  459. });
  460. }
  461.  
  462. // Prepare promise to fetch user id by username
  463. function getUserId(username){
  464. return new Promise((resolve,reject)=>{
  465. let getURL = `https://www.instagram.com/web/search/topsearch/?query=${username}`;
  466.  
  467. GM_xmlhttpRequest({
  468. method: "GET",
  469. url: getURL,
  470. onload: function(response) {
  471. let obj = JSON.parse(response.response);
  472. resolve(obj.users[0]);
  473. },
  474. onerror: function(err){
  475. reject(err);
  476. }
  477. });
  478. });
  479. }
  480.  
  481. // Prepare promise to catch article author using shortcode
  482. function getPostOwner(postPath){
  483. return new Promise((resolve,reject)=>{
  484. if(!postPath) reject("NOPATH");
  485. let postShortCode = postPath;
  486. let getURL = `https://www.instagram.com/graphql/query/?query_hash=2c4c2e343a8f64c625ba02b2aa12c7f8&variables=%7B%22shortcode%22:%22${postShortCode}%22}`;
  487.  
  488. GM_xmlhttpRequest({
  489. method: "GET",
  490. url: getURL,
  491. onload: function(response) {
  492. let obj = JSON.parse(response.response);
  493. resolve(obj.data.shortcode_media.owner.username);
  494. },
  495. onerror: function(err){
  496. reject(err);
  497. }
  498. });
  499. });
  500. }
  501.  
  502. // Prepare promise to cache article which contains blob media
  503. function getBlobMedia(postPath){
  504. return new Promise((resolve,reject)=>{
  505. if(!postPath) reject("NOPATH");
  506. let postShortCode = postPath;
  507. let getURL = `https://www.instagram.com/graphql/query/?query_hash=2c4c2e343a8f64c625ba02b2aa12c7f8&variables=%7B%22shortcode%22:%22${postShortCode}%22}`;
  508.  
  509. GM_xmlhttpRequest({
  510. method: "GET",
  511. url: getURL,
  512. onload: function(response) {
  513. let obj = JSON.parse(response.response);
  514. console.log(obj);
  515. resolve(obj.data);
  516. },
  517. onerror: function(err){
  518. reject(err);
  519. }
  520. });
  521. });
  522. }
  523.  
  524. // Main function
  525. function onReadyMyDW(NoDialog){
  526. // Whether is Instagram dialog?
  527. if(!NoDialog){
  528. // Running if it is dialog
  529. $('article, div.x13ehr01').each(function(){
  530. $(this).removeAttr('data-snig');
  531. $(this).unbind('click');
  532. });
  533. $('.SNKMS_IG_DW_MAIN,.SNKMS_IG_DW_MAIN_VIDEO').remove();
  534. }
  535. if(NoDialog == false){
  536. var repeat = setInterval(() => {
  537. // div.x13ehr01 << (sigle post in top, not floating) >>
  538. if($('article[data-snig="canDownload"], div.x13ehr01[data-snig="canDownload"]').length > 0) clearInterval(repeat);
  539. createArtBtn();
  540. },250);
  541. }
  542. else{
  543. createArtBtn();
  544. }
  545. }
  546.  
  547. function createArtBtn(){
  548. // Add download icon per each posts
  549. $('article, div.x13ehr01').each(function(){
  550. // If it is have not download icon
  551. if(!$(this).attr('data-snig')){
  552. console.log("Found article");
  553. var rightPos = 15;
  554. if(this.tagName === "DIV"){
  555. rightPos = ($(this).children('div:last-child').width() !== undefined) ? $(this).children('div:last-child').width()+15 : 335+15
  556. }
  557.  
  558. var style = `position: absolute;right:${rightPos}px;top:15px;padding:6px;line-height:1;background:#fff;border-radius: 50%;cursor:pointer;`;
  559.  
  560. // Add the download icon
  561. let $childElement = $(this).children("div").children("div");
  562. $childElement.eq((this.tagName === "DIV")? 0 : $childElement.length - 2).append(`<div title="${_i18n("DW")}" class="SNKMS_IG_DW_MAIN" style="${style}"><svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"><g><g><path d="M382.56,233.376C379.968,227.648,374.272,224,368,224h-64V16c0-8.832-7.168-16-16-16h-64c-8.832,0-16,7.168-16,16v208h-64 c-6.272,0-11.968,3.68-14.56,9.376c-2.624,5.728-1.6,12.416,2.528,17.152l112,128c3.04,3.488,7.424,5.472,12.032,5.472 c4.608,0,8.992-2.016,12.032-5.472l112-128C384.192,245.824,385.152,239.104,382.56,233.376z"/></g></g><g><g><path d="M432,352v96H80v-96H16v128c0,17.696,14.336,32,32,32h416c17.696,0,32-14.304,32-32V352H432z"/></g></g></div>`);
  563.  
  564. // Running if user click the download icon
  565. $(this).on('click','.SNKMS_IG_DW_MAIN', async function(e){
  566. GL_username = $(this).parent().parent().parent().attr('data-username');
  567. GL_postPath = location.pathname.split('/p/').at(-1).replaceAll('/','') || $(this).parent().parent().children("div:last-child").children("div").children("div:last-child").find('a[href^="/p/"]').last().attr("href").split("/").at(2);
  568.  
  569. // Create element that download dailog
  570. IG_createDM(GM_getValue('AutoDownload'));
  571.  
  572. $("#article-id").text(GL_postPath);
  573. var style = 'display:block;margin:5px 0px;padding:5px 0px;color:#111;font-size:1rem;line-height:1rem;text-align:center;border:1px solid #000;border-radius: 5px;';
  574.  
  575. // Find video/image element and add the download icon
  576. var s = 0;
  577. var multiple = $(this).parent().parent().find('._aap0 ._acaz').length;
  578. var pathname = window.location.pathname;
  579. var fullpathname = "/"+pathname.split('/')[1]+"/"+pathname.split('/')[2]+"/";
  580. // If posts have more than one images or videos.
  581. if(multiple){
  582. var blob = false;
  583. $(this).parent().find('._aap0 ._acaz').each(function(){
  584. let element_videos = $(this).parent().parent().find('video');
  585. //if(element_videos && element_videos.attr('src') && element_videos.attr('src').match(/^blob:/ig)){
  586. if(element_videos && element_videos.attr('src')){
  587. blob = true;
  588. }
  589. });
  590.  
  591.  
  592. if(blob){
  593. createMediaCacheDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",style,_i18n("LOAD_BLOB_MULTIPLE"));
  594. }
  595. else{
  596. let blob = false;
  597. $(this).parent().find('._aap0 ._acaz').each(function(){
  598. s++;
  599. let element_videos = $(this).find('video');
  600. let element_images = $(this).find('._aagv img');
  601. let imgLink = (element_images.attr('srcset'))?element_images.attr('srcset').split(" ")[0]:element_images.attr('src');
  602.  
  603. if(element_videos && element_videos.attr('src')){
  604. blob = true;
  605. /*
  606. let video_image = element_videos.attr('poster');
  607. let video_url = element_videos.attr('src');
  608.  
  609. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY').append(`<a data-needed="direct" data-path="${GL_postPath}" data-name="IGTV" data-type="mp4" data-globalIndex="${s}" style="${style}" href="javascript:;" data-href="${video_url}"><img width="100" src="${video_image}" /><br/>- ${_i18n("VID")} ${s} -</a>`);
  610.  
  611. if(video_url.match(/^blob:/ig)) blob = true;
  612. */
  613. }
  614. if(element_images && imgLink){
  615. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY').append(`<a data-needed="direct" data-path="${GL_postPath}" data-name="photo" data-type="jpg" data-globalIndex="${s}" style="${style}" href="javascript:;" data-href="${imgLink}"><img width="100" src="${imgLink}" /><br/>- ${_i18n("IMG")} ${s} -</a>`);
  616. }
  617.  
  618. });
  619.  
  620. if(blob){
  621. createMediaCacheDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",style,_i18n("LOAD_BLOB_RELOAD"));
  622. }
  623. }
  624. }
  625. else{
  626. s++;
  627. let element_videos = $(this).parent().parent().find('video');
  628. let element_images = $(this).parent().parent().find('._aagv img');
  629. let imgLink = (element_images.attr('srcset'))?element_images.attr('srcset').split(" ")[0]:element_images.attr('src');
  630.  
  631.  
  632. if(element_videos && element_videos.attr('src')){
  633. createMediaCacheDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",style,_i18n("LOAD_BLOB_ONE"));
  634.  
  635. /*
  636. let video_image = element_videos.attr('poster');
  637. let video_url = element_videos.attr('src');
  638.  
  639. if(element_videos.attr('src').match(/^blob:/ig)){
  640. createMediaCacheDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",style,_i18n("LOAD_BLOB_ONE"));
  641. }
  642. else{
  643. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY').append(`<a data-needed="direct" data-path="${GL_postPath}" data-name="video" data-type="mp4" data-globalIndex="${s}" style="${style}" href="javascript:;" data-href="${video_url}"><img width="100" src="${video_image}" /><br/>- ${_i18n("VID")} ${s} -</a>`);
  644. }
  645. */
  646. }
  647. if(element_images && imgLink){
  648. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY').append(`<a data-needed="direct" data-path="${GL_postPath}" data-name="photo" data-type="jpg" data-globalIndex="${s}" style="${style}" href="javascript:;" href="" data-href="${imgLink}"><img width="100" src="${imgLink}" /><br/>- ${_i18n("IMG")} ${s} -</a>`);
  649. }
  650. }
  651. });
  652.  
  653. // Add the mark that download is ready
  654. var username = $(this).find("header > div:last-child > div:first-child span > a").first().text();
  655.  
  656. $(this).attr('data-snig','canDownload');
  657. $(this).attr('data-username',username);
  658. }
  659. });
  660. }
  661.  
  662. // Create media element from blob media
  663. async function createMediaCacheDOM(postURL,selector,style,message){
  664. $(`${selector} a`).remove();
  665. $(selector).append('<p style="text-align:center;font-size:20px;" id="_SNLOAD">'+ message +'</p>');
  666. let media = await getBlobMedia(postURL);
  667. let idx = 1;
  668. let resource = media.shortcode_media;
  669.  
  670. // GraphVideo
  671. if(resource.__typename == "GraphVideo" && resource.video_url){
  672. $(selector).append(`<a data-blob="true" data-needed="direct" data-path="${resource.shortcode}" data-name="video" data-type="mp4" data-username="${resource.owner.username}" data-globalIndex="${idx}" style="${style}" href="javascript:;" data-href="${resource.video_url}"><img width="100" src="${resource.display_resources[1].src}" /><br/>- ${_i18n("VID")} ${idx} -</a>`);
  673. idx++;
  674. }
  675. // GraphSidecar
  676. if(resource.__typename == "GraphSidecar" && resource.edge_sidecar_to_children){
  677. for(let e of resource.edge_sidecar_to_children.edges){
  678. if(e.node.__typename == "GraphVideo"){
  679. $(selector).append(`<a data-blob="true" data-needed="direct" data-path="${resource.shortcode}" data-name="video" data-type="mp4" data-username="${resource.owner.username}" data-globalIndex="${idx}" style="${style}" href="javascript:;" data-href="${e.node.video_url}"><img width="100" src="${e.node.display_resources[1].src}" /><br/>- ${_i18n("VID")} ${idx} -</a>`);
  680. }
  681.  
  682. if(e.node.__typename == "GraphImage"){
  683. $(selector).append(`<a data-blob="true" data-needed="direct" data-path="${resource.shortcode}" data-name="photo" data-type="jpg" data-username="${resource.owner.username}" data-globalIndex="${idx}" style="${style}" href="javascript:;" data-href="${e.node.display_resources[e.node.display_resources.length - 1].src}"><img width="100" src="${e.node.display_resources[1].src}" /><br/>- ${_i18n("IMG")} ${idx} -</a>`);
  684. }
  685. idx++;
  686. }
  687. }
  688. $("#_SNLOAD").remove();
  689. }
  690.  
  691. // Create the download dialog element funcion
  692. function IG_createDM(a){
  693. let style = (!a)?"position: fixed;left: 0px;right: 0px;bottom: 0px;top: 0px;":"display:none;";
  694. $('body').append('<div class="IG_SN_DIG" style="'+style+';z-index: 500;"><div class="IG_SN_DIG_BG" style="'+style+'z-index:502;background: rgba(0,0,0,.75);"></div><div class="IG_SN_DIG_MAIN" style="z-index: 510;padding:10px 15px;top:7%;position: absolute;left: 50%;transform: translateX(-50%);width: 500px;background:#fff;border-radius: 7px;"><div class="IG_SN_DIG_TITLE"></div><div style="min-height: 100px;max-height: 80vh;overflow-y:auto;" class="IG_SN_DIG_BODY"></div></div></div>');
  695. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_TITLE').append('<div style="position:relative;height:36px;text-align:center;"><div style="position:absolute;left:0px;line-height: 18px;">Alt+Q ['+_i18n("CLOSE")+']</div><div style="line-height: 18px;">IG Helper</div><div style="line-height: 14px;font-size:14px;">Article: <span id="article-id"></span></div><svg width="26" height="26" class="IG_SN_DIG_BTN" style="cursor:pointer;position:absolute;right:0px;top:0px;" xmlns="http://www.w3.org/2000/svg" id="bold" enable-background="new 0 0 24 24" height="512" viewBox="0 0 24 24" width="512"><path d="m14.828 12 5.303-5.303c.586-.586.586-1.536 0-2.121l-.707-.707c-.586-.586-1.536-.586-2.121 0l-5.303 5.303-5.303-5.304c-.586-.586-1.536-.586-2.121 0l-.708.707c-.586.586-.586 1.536 0 2.121l5.304 5.304-5.303 5.303c-.586.586-.586 1.536 0 2.121l.707.707c.586.586 1.536.586 2.121 0l5.303-5.303 5.303 5.303c.586.586 1.536.586 2.121 0l.707-.707c.586-.586.586-1.536 0-2.121z"/></svg></div>');
  696. }
  697.  
  698. // Download and rename files
  699. function saveFiles(downloadLink,username,index,timestamp,type){
  700. fetch(downloadLink).then(res => {
  701. return res.blob().then(dwel => {
  702. const a = document.createElement("a");
  703. const name = username+'-'+index+'-'+timestamp+'.'+type;
  704. const originally = username + '_' + downloadLink.split('/').at(-1).split('?').at(0);
  705.  
  706. a.href = URL.createObjectURL(dwel);
  707. a.setAttribute("download", (AUTO_RENAME)?name:originally);
  708. a.click();
  709. a.remove();
  710. });
  711. });
  712. }
  713.  
  714. // Supported language list
  715. function translateText(lang){
  716. return {
  717. "zh-TW": {
  718. "CLOSE": "關閉",
  719. "IMG": "相片",
  720. "VID": "影片",
  721. "DDL": "快速下載",
  722. "DDL_INTRO": "勾選後將直接下載點選當下位置的相片/影片",
  723. "DW": "下載",
  724. "THUMBNAIL_INTRO": "下載影片縮圖",
  725. "LOAD_BLOB_ONE": "正在載入二進位大型物件...",
  726. "LOAD_BLOB_MULTIPLE": "正在載入多個二進位大型物件...",
  727. "LOAD_BLOB_RELOAD": "正在重新載入二進位大型物件...",
  728. "NO_VID_URL": "找不到影片網址"
  729. },
  730. "zh-CN": {
  731. "CLOSE": "关闭",
  732. "IMG": "图像",
  733. "VID": "视频",
  734. "DDL": "便捷下载",
  735. "DDL_INTRO": "勾选后将直接下载點擊當下位置的图像/视频",
  736. "DW": "下载",
  737. "THUMBNAIL_INTRO": "下载视频缩略图",
  738. "LOAD_BLOB_ONE": "正在载入大型媒体对象...",
  739. "LOAD_BLOB_MULTIPLE": "正在载入多个大型媒体对象...",
  740. "LOAD_BLOB_RELOAD": "正在重新载入大型媒体对象...",
  741. "NO_VID_URL": "找不到视频网址"
  742. },
  743. "en-US": {
  744. "CLOSE": "Close",
  745. "IMG": "Image",
  746. "VID": "Video",
  747. "DDL": "Quick Download",
  748. "DDL_INTRO": "Checking it will direct download current photo/media in the posts.",
  749. "DW": "Download",
  750. "THUMBNAIL_INTRO": "Download video thumbnail.",
  751. "LOAD_BLOB_ONE": "Loading Blob Media...",
  752. "LOAD_BLOB_MULTIPLE": "Loading Blob Media and others...",
  753. "LOAD_BLOB_RELOAD": "Detect Blob Media, now reloading...",
  754. "NO_VID_URL": "Can not find video url."
  755. }
  756. };
  757. }
  758.  
  759. // Translate display text to user country
  760. function _i18n(text){
  761. let userLang = (lang)?lang:"en-US";
  762. let translate = {
  763. "zh-TW": function(){
  764. return translateText()["zh-TW"];
  765. },
  766. "zh-HK": function(){
  767. return translateText()["zh-TW"];
  768. },
  769. "zh-MO": function(){
  770. return translateText()["zh-TW"];
  771. },
  772. "zh-CN": function(){
  773. return translateText()["zh-CN"];
  774. },
  775. "en-US": function(){
  776. return translateText()["en-US"];
  777. }
  778. }
  779.  
  780. try{
  781. return translate[lang]()[text];
  782. }
  783. catch{
  784. return translate["en-US"]()[text];
  785. }
  786. }
  787.  
  788. // Running if document is ready
  789. $(function(){
  790. // Close the download dialog if user click the close icon
  791. $('body').on('click','.IG_SN_DIG_BTN,.IG_SN_DIG_BG',function(){
  792. $('.IG_SN_DIG').remove();
  793. });
  794.  
  795. // Hot key [Alt+Q] to close the download dialog
  796. $(window).keydown(function(e){
  797. if (e.keyCode == '81' && e.altKey){
  798. $('.IG_SN_DIG').remove();
  799. e.preventDefault();
  800. }
  801. });
  802. $('body').on('click','.AutoDownload',function(){
  803. if($('.AutoDownload:checked').length){
  804. GM_setValue('AutoDownload',true);
  805. }
  806. else{
  807. GM_setValue('AutoDownload',false);
  808. }
  809. });
  810.  
  811. $('body').on('click','a[data-needed="direct"]',async function(){
  812. let date = new Date().getTime();
  813. let timestamp = Math.floor(date / 1000);
  814. let username = ($(this).attr('data-username')) ? $(this).attr('data-username') : GL_username;
  815.  
  816. if(!username && $(this).attr('data-path')){
  817. console.log('catching owner name from shortcode:',$(this).attr('data-href'));
  818. username = await getPostOwner($(this).attr('data-path'));
  819. }
  820.  
  821. saveFiles($(this).attr('data-href'),username,$(this).attr('data-name'),timestamp,$(this).attr('data-type'));
  822. });
  823.  
  824. // Running if user left-click download icon in stories
  825. $('body').on('click','.IG_DWSTORY',function(){
  826. onStoryDW(true);
  827. });
  828.  
  829. // Running if user left-click download icon in stories
  830. $('body').on('click','.IG_DWSTORY_THUMBNAIL',function(){
  831. onStoryThumbnailDW(true);
  832. });
  833.  
  834. // Running if user left-click download icon in profile
  835. $('body').on('click','.IG_DWPROFILE',function(e){
  836. e.stopPropagation();
  837. onProfileDW(true);
  838. });
  839.  
  840. // Running if user left-click download icon in highlight stories
  841. $('body').on('click','.IG_DWHISTORY',function(){
  842. onHighlightsStoryDW(true);
  843. });
  844.  
  845. // Running if user left-click download icon in highlight stories
  846. $('body').on('click','.IG_DWHISTORY_THUMBNAIL',function(){
  847. onHighlightsStoryThumbnailDW(true);
  848. });
  849.  
  850. // Running if user left-click download icon in reels
  851. $('body').on('click','.IG_REELS',function(){
  852. onReelsDW(true,true);
  853. });
  854.  
  855. // Running if user left-click download icon in reels
  856. $('body').on('click','.IG_REELS_THUMBNAIL',function(){
  857. onReelsDW(true,false);
  858. });
  859. });
  860.  
  861. })(jQuery);