IG小助手

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

当前为 2024-02-22 提交的版本,查看 最新版本

  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.17.2
  9. // @description Downloading is possible for both photos and videos from posts, as well as for stories, reels or profile picture.
  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_addStyle
  17. // @grant GM_setValue
  18. // @grant GM_getValue
  19. // @grant GM_xmlhttpRequest
  20. // @grant GM_registerMenuCommand
  21. // @grant GM_getResourceText
  22. // @connect i.instagram.com
  23. // @require https://code.jquery.com/jquery-3.6.3.min.js#sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=
  24. // @resource INTERNAL_CSS https://raw.githubusercontent.com/SN-Koarashi/ig-helper/master/style.css
  25. // @supportURL https://github.com/SN-Koarashi/ig-helper/
  26. // @contributionURL https://ko-fi.com/snkoarashi
  27. // @icon https://www.google.com/s2/favicons?domain=www.instagram.com
  28. // @compatible firefox >= 87
  29. // @compatible chrome >= 90
  30. // @compatible edge >= 90
  31. // @license GPL-3.0-only
  32. // ==/UserScript==
  33.  
  34. (function($) {
  35. 'use strict';
  36. // Icon download by https://www.flaticon.com/authors/pixel-perfect
  37.  
  38. /******** USER SETTINGS ********/
  39. // !!! DO NOT CHANGE THIS AREA !!!
  40. // PLEASE CHANGE SETTING WITH MENU
  41. const USER_SETTING = {
  42. 'AUTO_RENAME': (GM_getValue('AUTO_RENAME') != null && typeof GM_getValue('AUTO_RENAME') === 'boolean')?GM_getValue('AUTO_RENAME'):true,
  43. 'RENAME_SHORTCODE': (GM_getValue('RENAME_SHORTCODE') != null && typeof GM_getValue('RENAME_SHORTCODE') === 'boolean')?GM_getValue('RENAME_SHORTCODE'):true,
  44. 'DISABLE_VIDEO_LOOPING': (GM_getValue('DISABLE_VIDEO_LOOPING') != null && typeof GM_getValue('DISABLE_VIDEO_LOOPING') === 'boolean')?GM_getValue('DISABLE_VIDEO_LOOPING'):false,
  45. 'REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE': (GM_getValue('REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE') != null && typeof GM_getValue('REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE') === 'boolean')?GM_getValue('REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE'):false,
  46. 'FORCE_FETCH_ALL_RESOURCES': (GM_getValue('FORCE_FETCH_ALL_RESOURCES') != null && typeof GM_getValue('FORCE_FETCH_ALL_RESOURCES') === 'boolean')?GM_getValue('FORCE_FETCH_ALL_RESOURCES'):false,
  47. 'DIRECT_DOWNLOAD_WHEN_SINGLE': (GM_getValue('DIRECT_DOWNLOAD_WHEN_SINGLE') != null && typeof GM_getValue('DIRECT_DOWNLOAD_WHEN_SINGLE') === 'boolean')?GM_getValue('DIRECT_DOWNLOAD_WHEN_SINGLE'):false,
  48. 'DIRECT_DOWNLOAD_ALL': (GM_getValue('DIRECT_DOWNLOAD_ALL') != null && typeof GM_getValue('DIRECT_DOWNLOAD_ALL') === 'boolean')?GM_getValue('DIRECT_DOWNLOAD_ALL'):false,
  49. 'MODIFY_VIDEO_VOLUME': (GM_getValue('MODIFY_VIDEO_VOLUME') != null && typeof GM_getValue('MODIFY_VIDEO_VOLUME') === 'boolean')?GM_getValue('MODIFY_VIDEO_VOLUME'):false,
  50. 'SCROLL_BUTTON': (GM_getValue('SCROLL_BUTTON') != null && typeof GM_getValue('SCROLL_BUTTON') === 'boolean')?GM_getValue('SCROLL_BUTTON'):true,
  51. 'FORCE_RESOURCE_VIA_MEDIA': (GM_getValue('FORCE_RESOURCE_VIA_MEDIA') != null && typeof GM_getValue('FORCE_RESOURCE_VIA_MEDIA') === 'boolean')?GM_getValue('FORCE_RESOURCE_VIA_MEDIA'):false
  52. };
  53. var VIDEO_VOLUME = (GM_getValue('G_VIDEO_VOLUME'))?GM_getValue('G_VIDEO_VOLUME'):1;
  54. /*******************************/
  55.  
  56. const checkInterval = 250;
  57. const lang = navigator.language || navigator.userLanguage;
  58. const style = GM_getResourceText("INTERNAL_CSS");
  59.  
  60. GM_addStyle(style);
  61. GM_registerMenuCommand(_i18n('SETTING'), () => {
  62. showSetting();
  63. });
  64. GM_registerMenuCommand(_i18n('DEBUG'), () => {
  65. showDebugDOM();
  66. });
  67.  
  68. var currentURL = location.href;
  69. var currentHeight = $(document).height();
  70. var firstStarted = false;
  71. var pageLoaded = false;
  72.  
  73. var GL_postPath;
  74. var GL_username;
  75. var GL_repeat;
  76. var GL_dataCache = {
  77. stories: {},
  78. highlights: {}
  79. };
  80. var GL_observer = new MutationObserver(function (mutation, owner) {
  81. onReadyMyDW();
  82. });
  83.  
  84. // Main Timer
  85. var timer = setInterval(function(){
  86. currentHeight = $(document).height();
  87. // Call Instagram dialog function if url changed.
  88. if(currentURL != location.href || !firstStarted || !pageLoaded){
  89. clearInterval(GL_repeat);
  90. pageLoaded = false;
  91. firstStarted = true;
  92. currentURL = location.href;
  93.  
  94. if(location.href.startsWith("https://www.instagram.com/p/") || location.href.startsWith("https://www.instagram.com/reel/")){
  95. GL_dataCache.stories = {};
  96.  
  97. console.log('isDialog');
  98.  
  99. // This is to prevent the detection of the "Modify Video Volume" setting from being too slow.
  100. setTimeout(()=>{
  101. onReadyMyDW(false);
  102. }, 5);
  103.  
  104. // This is a delayed function call that prevents the dialog element from appearing before the function is called.
  105. setTimeout(()=>{
  106. onReadyMyDW(false);
  107. }, 250);
  108. setTimeout(()=>{
  109. onReadyMyDW(false);
  110. }, 450);
  111.  
  112. pageLoaded = true;
  113. }
  114.  
  115. if(location.href.startsWith("https://www.instagram.com/reels/")){
  116. console.log('isReels');
  117. setTimeout(()=>{
  118. onReels(false);
  119. },150);
  120. pageLoaded = true;
  121. }
  122.  
  123. if(location.href.split("?")[0] == "https://www.instagram.com/"){
  124. GL_dataCache.stories = {};
  125.  
  126. console.log('isHomepage');
  127. setTimeout(()=>{
  128. onReadyMyDW(false);
  129. },150);
  130.  
  131. const element = $('div[id^="mount"] > div > div div > section > main div:not([class]):not([style]) > div > article').parent()[0];
  132. GL_observer.observe(element, {
  133. childList: true
  134. });
  135.  
  136. pageLoaded = true;
  137. }
  138. if($('div[id^="mount"] > div > div > div').first().is(':hidden') && $('canvas._aarh, div._aadm').length && location.href.match(/^(https:\/\/www\.instagram\.com\/)([0-9A-Za-z\.\-_]+)\/?(tagged|reels)?\/?$/ig) && !location.href.match(/^(https:\/\/www\.instagram\.com\/(stories|explore)\/?)/ig)){
  139. console.log('isProfile');
  140. setTimeout(()=>{
  141. onProfileAvatar(false);
  142. },150);
  143. pageLoaded = true;
  144. }
  145.  
  146. if(!pageLoaded){
  147. // Call Instagram stories function
  148. if(location.href.match(/^(https:\/\/www\.instagram\.com\/stories\/highlights\/)/ig)){
  149. GL_dataCache.highlights = {};
  150.  
  151. console.log('isHighlightsStory');
  152. onHighlightsStory(false);
  153. GL_repeat = setInterval(()=>{
  154. onHighlightsStoryThumbnail(false);
  155. },checkInterval);
  156.  
  157. if($(".IG_DWHISTORY").length) setTimeout(()=>{pageLoaded = true;},150);
  158. }
  159. else if(location.href.match(/^(https:\/\/www\.instagram\.com\/stories\/)/ig)){
  160. console.log('isStory');
  161. onStory(false);
  162. onStoryThumbnail(false);
  163.  
  164. if($(".IG_DWSTORY").length) setTimeout(()=>{pageLoaded = true;},150);
  165. }
  166. else{
  167. pageLoaded = false;
  168. // Remove the download icon
  169. $('.IG_DWSTORY').remove();
  170. $('.IG_DWSTORY_THUMBNAIL').remove();
  171. }
  172. }
  173.  
  174. }
  175. },checkInterval);
  176.  
  177. // Call general function when user scroll the page
  178. /*
  179. $(document).scroll(function(){
  180. if(currentHeight != $(this).height() && location.href.split("?")[0] == "https://www.instagram.com/"){
  181. onReadyMyDW();
  182. }
  183. });
  184. */
  185.  
  186. /**
  187. * onProfileAvatar
  188. * Trigger user avatar download event or button display event.
  189. *
  190. * @param {Boolean} isDownload - Check if it is a download operation
  191. * @return {void}
  192. */
  193. async function onProfileAvatar(isDownload){
  194. if(isDownload){
  195. let date = new Date().getTime();
  196. let timestamp = Math.floor(date / 1000);
  197. let username = location.pathname.replaceAll(/(reels|tagged)\/$/ig,'').split('/').filter(s => s.length > 0).at(-1);
  198. let userInfo = await getUserId(username);
  199. try{
  200. let dataURL = await getUserHighSizeProfile(userInfo.user.pk);
  201. saveFiles(dataURL,username,"avatar",timestamp,'jpg');
  202. }
  203. catch(err){
  204. saveFiles(userInfo.user.profile_pic_url,username,"avatar",timestamp,'jpg');
  205. }
  206. }
  207. else{
  208. // Add the profile download button
  209. if(!$('.IG_DWPROFILE').length){
  210. let profileTimer = setInterval(()=>{
  211. if($('.IG_DWPROFILE').length){
  212. clearInterval(profileTimer);
  213. return;
  214. }
  215.  
  216. $('body > div main canvas._aarh, body > div main div._aadm').parent().append(`<div title="${_i18n("DW")}" class="IG_DWPROFILE"><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>`);
  217. $('body > div main canvas._aarh, body > div main div._aadm').parent().css('position','relative');
  218. },150);
  219. }
  220. }
  221. }
  222.  
  223. /**
  224. * onHighlightsStory
  225. * Trigger user's highlight download event or button display event.
  226. *
  227. * @param {Boolean} isDownload - Check if it is a download operation
  228. * @return {void}
  229. */
  230. async function onHighlightsStory(isDownload){
  231. if(isDownload){
  232. let date = new Date().getTime();
  233. let timestamp = Math.floor(date / 1000);
  234. let highlightId = location.href.replace(/\/$/ig,'').split('/').at(-1);
  235. let nowIndex = $("body > div section._ac0a header._ac0k > ._ac3r ._ac3n ._ac3p[style]").length ||
  236. $('body > div section:visible > div > div:not([class]) > div > div div.x1ned7t2.x78zum5 div.x1caxmr6').length ||
  237. $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div').find('div div.x1ned7t2.x78zum5 div.x1caxmr6').length;
  238. let username = "";
  239. let target = 0;
  240.  
  241. if(GL_dataCache.highlights[highlightId]){
  242. console.log('Fetch from memory cache:', highlightId);
  243.  
  244. let totIndex = GL_dataCache.highlights[highlightId].data.reels_media[0].items.length;
  245. username = GL_dataCache.highlights[highlightId].data.reels_media[0].owner.username;
  246. target = GL_dataCache.highlights[highlightId].data.reels_media[0].items[totIndex-nowIndex];
  247. }
  248. else{
  249. let highStories = await getHighlightStories(highlightId);
  250. let totIndex = highStories.data.reels_media[0].items.length;
  251. username = highStories.data.reels_media[0].owner.username;
  252. target = highStories.data.reels_media[0].items[totIndex-nowIndex];
  253.  
  254. GL_dataCache.highlights[highlightId] = highStories;
  255. }
  256.  
  257. if(USER_SETTING.FORCE_RESOURCE_VIA_MEDIA){
  258. let result = await getMediaInfo(target.id);
  259.  
  260. if(result.status === 'ok'){
  261. if(result.items[0].video_versions){
  262. saveFiles(result.items[0].video_versions[0].url, username,"highlights",timestamp,'mp4');
  263. }
  264. else{
  265. saveFiles(result.items[0].image_versions2.candidates[0].url, username,"highlights",timestamp,'jpg');
  266. }
  267. }
  268. else{
  269. alert('fetch failed from Media API, ' + result.message);
  270. console.log(result);
  271. }
  272. }
  273. else{
  274. if(target.is_video){
  275. saveFiles(target.video_resources.at(-1).src,username,"highlights",timestamp,'mp4', highlightId);
  276. }
  277. else{
  278. saveFiles(target.display_resources.at(-1).src,username,"highlights",timestamp,'jpg', highlightId);
  279. }
  280. }
  281. }
  282. else{
  283. // Add the stories download button
  284. if(!$('.IG_DWHISTORY').length){
  285. let $element = null;
  286.  
  287. // Default detecter (section layout mode)
  288. if($('body > div section._ac0a').length > 0){
  289. $element = $('body > div section:visible._ac0a');
  290. }
  291. else{
  292. $element = $('body > div section:visible > div > div[style]:not([class])');
  293. $element.css('position','relative');
  294. }
  295.  
  296. // Detecter for div layout mode
  297. // GitHub issue #3: DiceMast3r
  298. if($element.length === 0){
  299. let $$element = $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div');
  300. let nowSize = 0;
  301.  
  302. $$element.each(function(){
  303. if($(this).width() > nowSize){
  304. nowSize = $(this).width();
  305. $element = $(this);
  306. }
  307. });
  308. }
  309.  
  310.  
  311. if($element != null){
  312. //$element.css('position','relative');
  313. $element.append(`<div title="${_i18n("DW")}" class="IG_DWHISTORY"><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>`);
  314. }
  315. }
  316. }
  317. }
  318.  
  319. /**
  320. * onHighlightsStoryThumbnail
  321. * Trigger user's highlight video thumbnail download event or button display event.
  322. *
  323. * @param {Boolean} isDownload - Check if it is a download operation
  324. * @return {void}
  325. */
  326. async function onHighlightsStoryThumbnail(isDownload){
  327. if(isDownload){
  328. let date = new Date().getTime();
  329. let timestamp = Math.floor(date / 1000);
  330. let highlightId = location.href.replace(/\/$/ig,'').split('/').at(-1);
  331. let username = "";
  332. let nowIndex = $("body > div section._ac0a header._ac0k > ._ac3r ._ac3n ._ac3p[style]").length ||
  333. $('body > div section:visible > div > div:not([class]) > div > div div.x1ned7t2.x78zum5 div.x1caxmr6').length ||
  334. $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div').find('div div.x1ned7t2.x78zum5 div.x1caxmr6').length;
  335. let target = "";
  336.  
  337. if(GL_dataCache.highlights[highlightId]){
  338. console.log('Fetch from memory cache:', highlightId);
  339.  
  340. let totIndex = GL_dataCache.highlights[highlightId].data.reels_media[0].items.length;
  341. username = GL_dataCache.highlights[highlightId].data.reels_media[0].owner.username;
  342. target = GL_dataCache.highlights[highlightId].data.reels_media[0].items[totIndex-nowIndex];
  343. }
  344. else{
  345. let highStories = await getHighlightStories(highlightId);
  346. let totIndex = highStories.data.reels_media[0].items.length;
  347. username = highStories.data.reels_media[0].owner.username;
  348. target = highStories.data.reels_media[0].items[totIndex-nowIndex];
  349.  
  350. GL_dataCache.highlights[highlightId] = highStories;
  351. }
  352.  
  353. if(USER_SETTING.FORCE_RESOURCE_VIA_MEDIA){
  354. let result = await getMediaInfo(target.id);
  355.  
  356. if(result.status === 'ok'){
  357. saveFiles(result.items[0].image_versions2.candidates[0].url, username,"highlights",timestamp,'jpg');
  358. }
  359. else{
  360. alert('fetch failed from Media API, ' + result.message);
  361. console.log(result);
  362. }
  363. }
  364. else{
  365. saveFiles(target.display_resources.at(-1).src,username,"highlights",timestamp,'jpg', highlightId);
  366. }
  367. }
  368. else{
  369. if($('body > div section video.xh8yej3').length){
  370. // Add the stories download button
  371. if(!$('.IG_DWHISTORY_THUMBNAIL').length){
  372. let $element = null;
  373.  
  374. // Default detecter (section layout mode)
  375. if($('body > div section._ac0a').length > 0){
  376. $element = $('body > div section:visible._ac0a');
  377. }
  378. else{
  379. $element = $('body > div section:visible > div > div[style]:not([class])');
  380. $element.css('position','relative');
  381. }
  382.  
  383. // Detecter for div layout mode
  384. // GitHub issue #3: DiceMast3r
  385. if($element.length === 0){
  386. let $$element = $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div');
  387. let nowSize = 0;
  388.  
  389. $$element.each(function(){
  390. if($(this).width() > nowSize){
  391. nowSize = $(this).width();
  392. $element = $(this);
  393. }
  394. });
  395. }
  396.  
  397. if($element != null){
  398. $element.append(`<div title="${_i18n("THUMBNAIL_INTRO")}" class="IG_DWHISTORY_THUMBNAIL"><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>`);
  399. }
  400. }
  401. }
  402. else{
  403. $('.IG_DWHISTORY_THUMBNAIL').remove();
  404. }
  405. }
  406. }
  407.  
  408. /**
  409. * onStory
  410. * Trigger user's story download event or button display event.
  411. *
  412. * @param {Boolean} isDownload - Check if it is a download operation
  413. * @return {void}
  414. */
  415. async function onStory(isDownload,isForce){
  416. if(isDownload){
  417. let date = new Date().getTime();
  418. let timestamp = Math.floor(date / 1000);
  419. let username = $("body > div section._ac0a header._ac0k ._ac0l a + div a").first().text() || location.pathname.split('/').at(2);
  420.  
  421. if(USER_SETTING.FORCE_RESOURCE_VIA_MEDIA){
  422. let mediaId = null;
  423.  
  424. let userInfo = await getUserId(username);
  425. let userId = userInfo.user.pk;
  426. let stories = await getStories(userId);
  427.  
  428. $('body > div section:visible div.x1ned7t2.x78zum5 > div').each(function(index){
  429. if($(this).hasClass('x1lix1fw')){
  430. if($(this).children().length > 0){
  431. mediaId = stories.data.reels_media[0].items[index].id;
  432. }
  433. }
  434. });
  435.  
  436. if(mediaId == null){
  437. mediaId = location.pathname.split('/').filter(s => s.length > 0).at(-1);
  438. }
  439.  
  440. let result = await getMediaInfo(mediaId);
  441.  
  442. if(result.status === 'ok'){
  443. if(result.items[0].video_versions){
  444. saveFiles(result.items[0].video_versions[0].url, username,"stories",timestamp,'mp4');
  445. }
  446. else{
  447. saveFiles(result.items[0].image_versions2.candidates[0].url, username,"stories",timestamp,'jpg');
  448. }
  449. }
  450. else{
  451. alert('fetch failed from Media API, ' + result.message);
  452. console.log(result);
  453. }
  454.  
  455. return;
  456. }
  457.  
  458. if($('body > div section:visible video[playsinline]').length > 0){
  459. // Download stories if it is video
  460. let type = "mp4";
  461. let videoURL = "";
  462. let targetURL = location.pathname.replace(/\/$/ig,'').split("/").at(-1);
  463.  
  464. if(GL_dataCache.stories[username] && !isForce){
  465. console.log('Fetch from memory cache:', username);
  466. GL_dataCache.stories[username].data.reels_media[0].items.forEach(item => {
  467. if(item.id == targetURL){
  468. videoURL = item.video_resources[0].src;
  469. }
  470. });
  471.  
  472. if(videoURL.length == 0){
  473. console.log('Memory cache not found, try fetch from API:', username);
  474. onStory(true,true);
  475. return;
  476. }
  477. }
  478. else{
  479. let userInfo = await getUserId(username);
  480. let userId = userInfo.user.pk;
  481. let stories = await getStories(userId);
  482.  
  483. stories.data.reels_media[0].items.forEach(item => {
  484. if(item.id == targetURL){
  485. videoURL = item.video_resources[0].src;
  486. }
  487. });
  488.  
  489. // GitHub issue #4: thinkpad4
  490. if(videoURL.length == 0){
  491. $('body > div section:visible div.x1ned7t2.x78zum5 > div').each(function(index){
  492. if($(this).hasClass('x1lix1fw')){
  493. if($(this).children().length > 0){
  494. videoURL = stories.data.reels_media[0].items[index].video_resources[0].src;
  495.  
  496. }
  497. }
  498. });
  499. }
  500.  
  501. GL_dataCache.stories[username] = stories;
  502. }
  503.  
  504. if(videoURL.length == 0){
  505. alert(_i18n("NO_VID_URL"));
  506. }
  507. else{
  508. saveFiles(videoURL,username,"stories",timestamp,type);
  509. }
  510.  
  511. }
  512. else{
  513. // Download stories if it is image
  514. let srcset = $('body > div section:visible img[referrerpolicy][class], body > div section:visible img[crossorigin][class]:not([alt])').attr('srcset')?.split(',')[0]?.split(' ')[0];
  515. let link = (srcset)?srcset:$('body > div section:visible img[referrerpolicy][class], body > div section:visible img[crossorigin][class]:not([alt])').attr('src');
  516.  
  517. if(!link){
  518. // _aa63 mean stories picture in stories page (not avatar)
  519. let $element = $('body > div section:visible img._aa63');
  520. link = ($element.attr('srcset'))?$element.attr('srcset')?.split(',')[0]?.split(' ')[0]:$element.attr('src');
  521. }
  522.  
  523. let downloadLink = link;
  524. let type = 'jpg';
  525.  
  526. saveFiles(downloadLink,username,"stories",timestamp,type);
  527. }
  528. }
  529. else{
  530. // Add the stories download button
  531. let style = "position: absolute;right:-40px;top:15px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  532. if(!$('.IG_DWSTORY').length){
  533. GL_dataCache.stories = {};
  534. let $element = null;
  535. // Default detecter (section layout mode)
  536. if($('body > div section._ac0a').length > 0){
  537. $element = $('body > div section:visible._ac0a');
  538. }
  539. // detecter (single story layout mode)
  540. else{
  541. $element = $('body > div section:visible > div > div[style]:not([class])');
  542. $element.css('position','relative');
  543. }
  544.  
  545.  
  546. // Detecter for div layout mode
  547. // GitHub issue #3: DiceMast3r
  548. if($element.length === 0){
  549. let $$element = $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div');
  550. let nowSize = 0;
  551.  
  552. $$element.each(function(){
  553. if($(this).width() > nowSize){
  554. nowSize = $(this).width();
  555. $element = $(this);
  556. }
  557. });
  558. }
  559.  
  560.  
  561. if($element != null){
  562. $element.css('position','relative');
  563. $element.append(`<div title="${_i18n("DW")}" class="IG_DWSTORY"><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>`);
  564. }
  565. }
  566. }
  567. }
  568.  
  569. /**
  570. * onStoryThumbnail
  571. * Trigger user's story video thumbnail download event or button display event.
  572. *
  573. * @param {Boolean} isDownload - Check if it is a download operation
  574. * @return {void}
  575. */
  576. async function onStoryThumbnail(isDownload,isForce){
  577. if(isDownload){
  578. // Download stories if it is video
  579. let date = new Date().getTime();
  580. let timestamp = Math.floor(date / 1000);
  581. let type = 'jpg';
  582. let username = $("body > div section._ac0a header._ac0k ._ac0l a + div a").first().text() || location.pathname.split('/').at(2);
  583. 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;';
  584. // Download thumbnail
  585. let targetURL = location.pathname.replace(/\/$/ig,'').split("/").at(-1);
  586. let videoThumbnailURL = "";
  587.  
  588. if(USER_SETTING.FORCE_RESOURCE_VIA_MEDIA){
  589. let mediaId = null;
  590.  
  591. let userInfo = await getUserId(username);
  592. let userId = userInfo.user.pk;
  593. let stories = await getStories(userId);
  594.  
  595. $('body > div section:visible div.x1ned7t2.x78zum5 > div').each(function(index){
  596. if($(this).hasClass('x1lix1fw')){
  597. if($(this).children().length > 0){
  598. mediaId = stories.data.reels_media[0].items[index].id;
  599. }
  600. }
  601. });
  602.  
  603. if(mediaId == null){
  604. mediaId = location.pathname.split('/').filter(s => s.length > 0).at(-1);
  605. }
  606.  
  607. let result = await getMediaInfo(mediaId);
  608.  
  609. if(result.status === 'ok'){
  610. saveFiles(result.items[0].image_versions2.candidates[0].url, username,"stories",timestamp,'jpg');
  611.  
  612. }
  613. else{
  614. alert('fetch failed from Media API, ' + result.message);
  615. console.log(result);
  616. }
  617.  
  618. return;
  619. }
  620.  
  621. if(GL_dataCache.stories[username] && !isForce){
  622. console.log('Fetch from memory cache:', username);
  623. GL_dataCache.stories[username].data.reels_media[0].items.forEach(item => {
  624. if(item.id == targetURL){
  625. videoThumbnailURL = item.display_url;
  626. }
  627. });
  628.  
  629. if(videoThumbnailURL.length == 0){
  630. console.log('Memory cache not found, try fetch from API:', username);
  631. onStoryThumbnail(true,true);
  632. return;
  633. }
  634. }
  635. else{
  636. let userInfo = await getUserId(username);
  637. let userId = userInfo.user.pk;
  638. let stories = await getStories(userId);
  639.  
  640. stories.data.reels_media[0].items.forEach(item => {
  641. if(item.id == targetURL){
  642. videoThumbnailURL = item.display_url;
  643. }
  644. });
  645.  
  646. // GitHub issue #4: thinkpad4
  647. if(videoThumbnailURL.length == 0){
  648. $('body > div section:visible div.x1ned7t2.x78zum5 > div').each(function(index){
  649. if($(this).hasClass('x1lix1fw')){
  650. if($(this).children().length > 0){
  651. videoThumbnailURL = stories.data.reels_media[0].items[index].display_url;
  652. }
  653. }
  654. });
  655. }
  656. }
  657.  
  658. saveFiles(videoThumbnailURL,username,"thumbnail",timestamp,type);
  659. }
  660. else{
  661. if($('body > div section video.xh8yej3').length){
  662. // Add the stories download button
  663. if(!$('.IG_DWSTORY_THUMBNAIL').length){
  664. let $element = null;
  665. // Default detecter (section layout mode)
  666. if($('body > div section._ac0a').length > 0){
  667. $element = $('body > div section:visible._ac0a');
  668. }
  669. // detecter (single story layout mode)
  670. else{
  671. $element = $('body > div section:visible > div > div[style]:not([class])');
  672. $element.css('position','relative');
  673. }
  674.  
  675. // Detecter for div layout mode
  676. // GitHub issue #3: DiceMast3r
  677. if($element.length === 0){
  678. let $$element = $('body > div div:not([hidden]) section:visible > div div[style]:not([class]) > div');
  679. let nowSize = 0;
  680.  
  681. $$element.each(function(){
  682. if($(this).width() > nowSize){
  683. nowSize = $(this).width();
  684. $element = $(this);
  685. }
  686. });
  687. }
  688.  
  689.  
  690. if($element != null){
  691. $element.css('position','relative');
  692. $element.append(`<div title="${_i18n("THUMBNAIL_INTRO")}" class="IG_DWSTORY_THUMBNAIL"><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>`);
  693. }
  694. }
  695. }
  696. else{
  697. $('.IG_DWSTORY_THUMBNAIL').remove();
  698. }
  699. }
  700. }
  701.  
  702. /**
  703. * onReels
  704. * Trigger user's reels download event or button display event.
  705. *
  706. * @param {Boolean} isDownload - Check if it is a download operation
  707. * @param {Boolean} isVideo - Check if reel is a video element
  708. * @return {void}
  709. */
  710. async function onReels(isDownload, isVideo){
  711. if(isDownload){
  712. let reelsPath = location.href.split('?').at(0).split('instagram.com/reels/').at(-1).replaceAll('/','');
  713. let data = await getBlobMedia(reelsPath);
  714. let timestamp = new Date().getTime();
  715.  
  716. if(isVideo && data.shortcode_media.is_video){
  717. let type = 'mp4';
  718. saveFiles(data.shortcode_media.video_url,data.shortcode_media.owner.username,"reels",timestamp,type,reelsPath);
  719. }
  720. else{
  721. let type = 'jpg';
  722. saveFiles(data.shortcode_media.display_resources.at(-1).src,data.shortcode_media.owner.username,"reels",timestamp,type,reelsPath);
  723. }
  724. }
  725. else{
  726. //$('.IG_REELS_THUMBNAIL, .IG_REELS').remove();
  727. var timer = setInterval(()=>{
  728. if($('section > main[role="main"] > div div.x1qjc9v5 video').length > 0){
  729. clearInterval(timer);
  730.  
  731. if(USER_SETTING.SCROLL_BUTTON){
  732. $('#scrollWrapper').remove();
  733. $('section > main[role="main"]').append('<section id="scrollWrapper"></section>');
  734. $('section > main[role="main"] > #scrollWrapper').append('<div class="button-up"><div></div></div>');
  735. $('section > main[role="main"] > #scrollWrapper').append('<div class="button-down"><div></div></div>');
  736.  
  737. $('section > main[role="main"] > #scrollWrapper > .button-up').on('click',function(){
  738. $('section > main[role="main"] > div')[0].scrollBy({top: -30, behavior: "smooth"});
  739. });
  740. $('section > main[role="main"] > #scrollWrapper > .button-down').on('click',function(){
  741. $('section > main[role="main"] > div')[0].scrollBy({top: 30, behavior: "smooth"});
  742. });
  743. }
  744.  
  745. $('section > main[role="main"] > div').children('div').each(function(){
  746. if($(this).children().length > 0){
  747. if(!$(this).children().find('.IG_REELS').length){
  748. $(this).children().css('position','relative');
  749.  
  750. $(this).children().append(`<div title="${_i18n("DW")}" class="IG_REELS"><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>`);
  751. $(this).children().append(`<div title="${_i18n("THUMBNAIL_INTRO")}" class="IG_REELS_THUMBNAIL"><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>`);
  752.  
  753. // Disable video autoplay
  754. if(USER_SETTING.DISABLE_VIDEO_LOOPING){
  755. $(this).find('video').each(function(){
  756. if(!$(this).data('loop')){
  757. console.log('(reel) Added video event listener #loop');
  758. $(this).on('ended',function(){
  759. $(this).attr('data-loop', true);
  760. let $element = $(this).next().find('div[role="presentation"] > div > div:last-child');
  761.  
  762. if($element.length > 0){
  763. $element.click();
  764. console.log('paused click()');
  765. }
  766. else{
  767. $(this).parent().find('.xpgaw4o').removeAttr('style');
  768. this.pause();
  769. console.log('paused pause()');
  770. }
  771. });
  772. }
  773. });
  774. }
  775. // Modify Video Volume
  776. if(USER_SETTING.MODIFY_VIDEO_VOLUME){
  777. $(this).find('video').each(function(){
  778. if(!$(this).data('modify')){
  779. console.log('(reel) Added video event listener #modify');
  780. this.volume = VIDEO_VOLUME;
  781.  
  782. $(this).on('play',function(){
  783. this.volume = VIDEO_VOLUME;
  784. });
  785. $(this).on('playing',function(){
  786. this.volume = VIDEO_VOLUME;
  787. });
  788.  
  789. $(this).attr('data-modify', true);
  790. }
  791. });
  792. }
  793. }
  794. }
  795. });
  796. }
  797. },250);
  798. }
  799. }
  800.  
  801. /**
  802. * getHighlightStories
  803. * Get a list of all stories in highlight Id.
  804. *
  805. * @param {Integer} highlightId
  806. * @return {Object}
  807. */
  808. function getHighlightStories(highlightId){
  809. return new Promise((resolve,reject)=>{
  810. 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`;
  811.  
  812. GM_xmlhttpRequest({
  813. method: "GET",
  814. url: getURL,
  815. onload: function(response) {
  816. let obj = JSON.parse(response.response);
  817. resolve(obj);
  818. },
  819. onerror: function(err){
  820. reject(err);
  821. }
  822. });
  823. });
  824. }
  825.  
  826. /**
  827. * getStories
  828. * Get a list of all stories in user Id.
  829. *
  830. * @param {Integer} userId
  831. * @return {Object}
  832. */
  833. function getStories(userId){
  834. return new Promise((resolve,reject)=>{
  835. 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`;
  836.  
  837. GM_xmlhttpRequest({
  838. method: "GET",
  839. url: getURL,
  840. onload: function(response) {
  841. let obj = JSON.parse(response.response);
  842. resolve(obj);
  843. },
  844. onerror: function(err){
  845. reject(err);
  846. }
  847. });
  848. });
  849. }
  850.  
  851. /**
  852. * getUserId
  853. * Get user's id with username
  854. *
  855. * @param {String} username
  856. * @return {Integer}
  857. */
  858. function getUserId(username){
  859. return new Promise((resolve,reject)=>{
  860. let getURL = `https://www.instagram.com/web/search/topsearch/?query=${username}`;
  861.  
  862. GM_xmlhttpRequest({
  863. method: "GET",
  864. url: getURL,
  865. onload: function(response) {
  866. // Fix search issue by Discord: sno_w_
  867. let obj = JSON.parse(response.response);
  868. let result = null;
  869. obj.users.forEach(pos => {
  870. if(pos.user.username === username){
  871. result = pos;
  872. }
  873. });
  874.  
  875. if(result != null){
  876. resolve(result);
  877. }
  878. else{
  879. alert("Can not find user info from getUserId()");
  880. }
  881. },
  882. onerror: function(err){
  883. reject(err);
  884. }
  885. });
  886. });
  887. }
  888.  
  889. /**
  890. * getUserHighSizeProfile
  891. * Get user's high quality avatar image.
  892. *
  893. * @param {Integer} userId
  894. * @return {String}
  895. */
  896. function getUserHighSizeProfile(userId){
  897. return new Promise((resolve,reject)=>{
  898. let getURL = `https://i.instagram.com/api/v1/users/${userId}/info/`;
  899.  
  900. GM_xmlhttpRequest({
  901. method: "GET",
  902. url: getURL,
  903. headers: {
  904. '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'
  905. },
  906. onload: function(response) {
  907. let obj = JSON.parse(response.response);
  908. if(obj.status !== 'ok'){
  909. reject('faild');
  910. }
  911. else{
  912. resolve(obj.user.hd_profile_pic_url_info?.url);
  913. }
  914. },
  915. onerror: function(err){
  916. reject(err);
  917. }
  918. });
  919. });
  920. }
  921.  
  922. /**
  923. * getPostOwner
  924. * Get post's author with post shortcode
  925. *
  926. * @param {String} postPath
  927. * @return {String}
  928. */
  929. function getPostOwner(postPath){
  930. return new Promise((resolve,reject)=>{
  931. if(!postPath) reject("NOPATH");
  932. let postShortCode = postPath;
  933. let getURL = `https://www.instagram.com/graphql/query/?query_hash=2c4c2e343a8f64c625ba02b2aa12c7f8&variables=%7B%22shortcode%22:%22${postShortCode}%22}`;
  934.  
  935. GM_xmlhttpRequest({
  936. method: "GET",
  937. url: getURL,
  938. onload: function(response) {
  939. let obj = JSON.parse(response.response);
  940. resolve(obj.data.shortcode_media.owner.username);
  941. },
  942. onerror: function(err){
  943. reject(err);
  944. }
  945. });
  946. });
  947. }
  948.  
  949. /**
  950. * getBlobMedia
  951. * Get list of all media files in post with post shortcode
  952. *
  953. * @param {String} postPath
  954. * @return {Object}
  955. */
  956. function getBlobMedia(postPath){
  957. return new Promise((resolve,reject)=>{
  958. if(!postPath) reject("NOPATH");
  959. let postShortCode = postPath;
  960. let getURL = `https://www.instagram.com/graphql/query/?query_hash=2c4c2e343a8f64c625ba02b2aa12c7f8&variables=%7B%22shortcode%22:%22${postShortCode}%22}`;
  961.  
  962. GM_xmlhttpRequest({
  963. method: "GET",
  964. url: getURL,
  965. onload: function(response) {
  966. let obj = JSON.parse(response.response);
  967. console.log(obj);
  968. resolve(obj.data);
  969. },
  970. onerror: function(err){
  971. reject(err);
  972. }
  973. });
  974. });
  975. }
  976.  
  977. /**
  978. * onReadyMyDW
  979. * Create an event entry point for the download button for the post
  980. *
  981. * @param {Boolean} NoDialog - Check if it not showing the dialog
  982. * @return {void}
  983. */
  984. function onReadyMyDW(NoDialog){
  985. // Whether is Instagram dialog?
  986. /*
  987. if(!NoDialog){
  988. // Running if it is dialog
  989. $('article, main > div > div.xdt5ytf > div').each(function(){
  990. $(this).removeAttr('data-snig');
  991. $(this).unbind('click');
  992. });
  993. $('.SNKMS_IG_DW_MAIN,.SNKMS_IG_DW_MAIN_VIDEO').remove();
  994. }
  995. */
  996.  
  997. if(NoDialog == false){
  998. var repeat = setInterval(() => {
  999. // div.xdt5ytf << (sigle post in top, not floating) >>
  1000. if($('article[data-snig="canDownload"], section:visible > main > div > div.xdt5ytf[data-snig="canDownload"], div[id^="mount"] > div > div > div.x1n2onr6.x1vjfegm div[data-snig="canDownload"]').length > 0) clearInterval(repeat);
  1001. createDownloadButton();
  1002. },5);
  1003. }
  1004. else{
  1005. createDownloadButton();
  1006. }
  1007. }
  1008.  
  1009. /**
  1010. * getAppID
  1011. * Get Instagram App ID
  1012. *
  1013. * @return {?integer}
  1014. */
  1015. function getAppID(){
  1016. let result = null;
  1017. $('script[type="application/json"]').each(function(){
  1018. const regexp = /"APP_ID":"([0-9]+)"/ig;
  1019. const matcher = $(this).text().match(regexp);
  1020. if(matcher != null && result == null){
  1021. result = [...$(this).text().matchAll(regexp)];
  1022. }
  1023. })
  1024.  
  1025. return (result)?result.at(0).at(-1):null;
  1026. }
  1027.  
  1028. /**
  1029. * getMediaInfo
  1030. * Get Instagram Media object
  1031. *
  1032. * @param {String} mediaId
  1033. * @return {Object}
  1034. */
  1035. function getMediaInfo(mediaId){
  1036. return new Promise((resolve,reject)=>{
  1037. let getURL = `https://i.instagram.com/api/v1/media/${mediaId}/info/`;
  1038.  
  1039. GM_xmlhttpRequest({
  1040. method: "GET",
  1041. url: getURL,
  1042. headers: {
  1043. "User-Agent": window.navigator.userAgent,
  1044. "Accept": "*/*",
  1045. 'X-IG-App-ID': getAppID()
  1046. },
  1047. onload: function(response) {
  1048. let obj = JSON.parse(response.response);
  1049. resolve(obj);
  1050. },
  1051. onerror: function(err){
  1052. reject(err);
  1053. }
  1054. });
  1055. });
  1056. }
  1057.  
  1058. /**
  1059. * createDownloadButton
  1060. * Create a download button in the upper right corner of each post
  1061. *
  1062. * @return {void}
  1063. */
  1064. function createDownloadButton(){
  1065. // Add download icon per each posts
  1066. $('article, section:visible > main > div > div.xdt5ytf, div._aap0[role="presentation"]').each(function(index){
  1067. // If it is have not download icon
  1068. // class x1iyjqo2 mean user profile pages post list container
  1069. if(!$(this).attr('data-snig') && !$(this).hasClass('x1iyjqo2') && !$(this).children('article')?.hasClass('x1iyjqo2')){
  1070. console.log("Found article");
  1071. var rightPos = 15;
  1072. var topPos = 15;
  1073. var $mainElement = $(this);
  1074.  
  1075. // not loop each in single top post
  1076. if(this.tagName === "DIV" && index != 0){
  1077. return;
  1078. }
  1079.  
  1080. // New post UI by Discord: ken
  1081. if(this.tagName === "DIV" && $(this).attr('role') === "presentation"){
  1082. rightPos = 28;
  1083. topPos = 75;
  1084. $mainElement = $('div._aap0[role="presentation"]').parents('div._aamm').parent().parent().parent().parent().parent();
  1085. }
  1086.  
  1087.  
  1088. // Add the download icon
  1089. let $childElement = $mainElement.children("div").children("div");
  1090. $childElement.eq((this.tagName === "DIV")? 0 : $childElement.length - 2).append(`<div title="${_i18n("DW")}" class="SNKMS_IG_DW_MAIN" style="right:${rightPos}px;top:${topPos}px;"><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>`);
  1091. $childElement.css('position','relative');
  1092.  
  1093. // Disable video autoplay
  1094. if(USER_SETTING.DISABLE_VIDEO_LOOPING){
  1095. $(this).find('video').each(function(){
  1096. if(!$(this).data('loop')){
  1097. console.log('(post) Added video event listener #loop');
  1098. $(this).on('ended',function(){
  1099. $(this).attr('data-loop', true);
  1100. this.pause();
  1101. });
  1102. }
  1103. });
  1104. }
  1105.  
  1106. // Modify Video Volume
  1107. if(USER_SETTING.MODIFY_VIDEO_VOLUME){
  1108. $(this).find('video').each(function(){
  1109. if(!$(this).data('modify')){
  1110. console.log('(post) Added video event listener #modify');
  1111. this.volume = VIDEO_VOLUME;
  1112.  
  1113. $(this).on('play',function(){
  1114. this.volume = VIDEO_VOLUME;
  1115. });
  1116. $(this).on('playing',function(){
  1117. this.volume = VIDEO_VOLUME;
  1118. });
  1119.  
  1120. $(this).attr('data-modify', true);
  1121. }
  1122. });
  1123. }
  1124.  
  1125. // Running if user click the download icon
  1126. $(this).on('click','.SNKMS_IG_DW_MAIN', async function(e){
  1127. GL_username = $(this).parent().parent().parent().attr('data-username');
  1128. 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);
  1129.  
  1130. // Create element that download dailog
  1131. IG_createDM(USER_SETTING.DIRECT_DOWNLOAD_ALL, true);
  1132.  
  1133. $("#article-id").html(`<a href="https://www.instagram.com/p/${GL_postPath}">${GL_postPath}</a>`);
  1134.  
  1135. if(!USER_SETTING.DIRECT_DOWNLOAD_ALL){
  1136. // Find video/image element and add the download icon
  1137. var s = 0;
  1138. var multiple = $(this).parent().parent().find('._aap0 ._acaz').length;
  1139. var pathname = window.location.pathname;
  1140. var fullpathname = "/"+pathname.split('/')[1]+"/"+pathname.split('/')[2]+"/";
  1141. var blob = USER_SETTING.FORCE_FETCH_ALL_RESOURCES;
  1142.  
  1143. // If posts have more than one images or videos.
  1144. if(multiple){
  1145. $(this).parent().find('._aap0 ._acaz').each(function(){
  1146. let element_videos = $(this).parent().parent().find('video');
  1147. //if(element_videos && element_videos.attr('src') && element_videos.attr('src').match(/^blob:/ig)){
  1148. if(element_videos && element_videos.attr('src')){
  1149. blob = true;
  1150. }
  1151. });
  1152.  
  1153.  
  1154. if(blob || USER_SETTING.FORCE_RESOURCE_VIA_MEDIA){
  1155. createMediaListDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",_i18n("LOAD_BLOB_MULTIPLE"));
  1156. }
  1157. else{
  1158. $(this).parent().find('._aap0 ._acaz').each(function(){
  1159. s++;
  1160. let element_videos = $(this).find('video');
  1161. let element_images = $(this).find('._aagv img');
  1162. let imgLink = (element_images.attr('srcset'))?element_images.attr('srcset').split(" ")[0]:element_images.attr('src');
  1163.  
  1164. if(element_videos && element_videos.attr('src')){
  1165. blob = true;
  1166. }
  1167. if(element_images && imgLink){
  1168. $('.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}" href="javascript:;" data-href="${imgLink}"><img width="100" src="${imgLink}" /><br/>- ${_i18n("IMG")} ${s} -</a>`);
  1169. }
  1170.  
  1171. });
  1172.  
  1173. if(blob){
  1174. createMediaListDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",_i18n("LOAD_BLOB_RELOAD"));
  1175. }
  1176. }
  1177. }
  1178. else{
  1179. if(USER_SETTING.FORCE_RESOURCE_VIA_MEDIA){
  1180. createMediaListDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",_i18n("LOAD_BLOB_MULTIPLE"));
  1181. }
  1182. else{
  1183. s++;
  1184. let element_videos = $(this).parent().parent().find('video');
  1185. let element_images = $(this).parent().parent().find('._aagv img');
  1186. let imgLink = (element_images.attr('srcset'))?element_images.attr('srcset').split(" ")[0]:element_images.attr('src');
  1187.  
  1188.  
  1189. if(element_videos && element_videos.attr('src')){
  1190. createMediaListDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",_i18n("LOAD_BLOB_ONE"));
  1191. }
  1192. if(element_images && imgLink){
  1193. $('.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}" href="javascript:;" href="" data-href="${imgLink}"><img width="100" src="${imgLink}" /><br/>- ${_i18n("IMG")} ${s} -</a>`);
  1194. }
  1195. }
  1196. }
  1197. }
  1198.  
  1199. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY a').each(function(){
  1200. $(this).wrap('<div></div>');
  1201. $(this).before('<label class="inner_box_wrapper"><input class="inner_box" type="checkbox"><span></span></label>');
  1202. });
  1203.  
  1204. if(USER_SETTING.DIRECT_DOWNLOAD_ALL){
  1205. createMediaListDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",_i18n("LOAD_BLOB_MULTIPLE"));
  1206. let checkBlob = setInterval(()=>{
  1207. if($('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY a').length > 0){
  1208. clearInterval(checkBlob);
  1209. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY a').each(function(){
  1210. $(this).click();
  1211. });
  1212.  
  1213. $('.IG_SN_DIG').remove();
  1214. }
  1215. },250);
  1216. }
  1217. else if(s === 1 && USER_SETTING.DIRECT_DOWNLOAD_WHEN_SINGLE){
  1218. IG_setDM(true);
  1219. let checkBlob = setInterval(()=>{
  1220. if($('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY a').length > 0){
  1221. clearInterval(checkBlob);
  1222. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY a').first()?.click();
  1223. $('.IG_SN_DIG').remove();
  1224. }
  1225. },250);
  1226. }
  1227. });
  1228.  
  1229. // Add the mark that download is ready
  1230. var username = $(this).find("header > div:last-child > div:first-child span a").first().text();
  1231.  
  1232. $(this).attr('data-snig','canDownload');
  1233. $(this).attr('data-username',username);
  1234. }
  1235. });
  1236. }
  1237.  
  1238. /**
  1239. * createMediaListDOM
  1240. * Create a list of media elements from post URLs
  1241. *
  1242. * @param {String} postURL
  1243. * @param {String} selector - Use CSS element selectors to choose where it appears.
  1244. * @param {String} message - i18n display loading message
  1245. * @return {void}
  1246. */
  1247. async function createMediaListDOM(postURL,selector,message){
  1248. $(`${selector} a`).remove();
  1249. $(selector).append('<p id="_SNLOAD">'+ message +'</p>');
  1250. let media = await getBlobMedia(postURL);
  1251.  
  1252. let idx = 1;
  1253. let resource = media.shortcode_media;
  1254.  
  1255. // GraphVideo
  1256. if(resource.__typename == "GraphVideo" && resource.video_url){
  1257. $(selector).append(`<a media-id="${resource.id}" data-blob="true" data-needed="direct" data-path="${resource.shortcode}" data-name="video" data-type="mp4" data-username="${resource.owner.username}" data-globalIndex="${idx}" href="javascript:;" data-href="${resource.video_url}"><img width="100" src="${resource.display_resources[1].src}" /><br/>- ${_i18n("VID")} ${idx} -</a>`);
  1258. idx++;
  1259. }
  1260. // GraphImage
  1261. if(resource.__typename == "GraphImage"){
  1262. $(selector).append(`<a media-id="${resource.id}" data-blob="true" data-needed="direct" data-path="${resource.shortcode}" data-name="photo" data-type="jpg" data-username="${resource.owner.username}" data-globalIndex="${idx}" href="javascript:;" data-href="${resource.display_resources[resource.display_resources.length - 1].src}"><img width="100" src="${resource.display_resources[1].src}" /><br/>- ${_i18n("IMG")} ${idx} -</a>`);
  1263. idx++;
  1264. }
  1265. // GraphSidecar
  1266. if(resource.__typename == "GraphSidecar" && resource.edge_sidecar_to_children){
  1267. for(let e of resource.edge_sidecar_to_children.edges){
  1268. if(e.node.__typename == "GraphVideo"){
  1269. $(selector).append(`<a media-id="${e.node.id}" data-blob="true" data-needed="direct" data-path="${resource.shortcode}" data-name="video" data-type="mp4" data-username="${resource.owner.username}" data-globalIndex="${idx}" href="javascript:;" data-href="${e.node.video_url}"><img width="100" src="${e.node.display_resources[1].src}" /><br/>- ${_i18n("VID")} ${idx} -</a>`);
  1270. }
  1271.  
  1272. if(e.node.__typename == "GraphImage"){
  1273. $(selector).append(`<a media-id="${e.node.id}" data-blob="true" data-needed="direct" data-path="${resource.shortcode}" data-name="photo" data-type="jpg" data-username="${resource.owner.username}" data-globalIndex="${idx}" 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>`);
  1274. }
  1275. idx++;
  1276. }
  1277. }
  1278.  
  1279. $("#_SNLOAD").remove();
  1280. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY a').each(function(){
  1281. $(this).wrap('<div></div>');
  1282. $(this).before('<label class="inner_box_wrapper"><input class="inner_box" type="checkbox"><span></span></label>');
  1283. });
  1284. }
  1285.  
  1286. /**
  1287. * IG_createDM
  1288. * A dialog showing a list of all media files in the post
  1289. *
  1290. * @param {Boolean} hasHidden
  1291. * @param {Boolean} hasCheckbox
  1292. * @return {void}
  1293. */
  1294. function IG_createDM(hasHidden, hasCheckbox){
  1295. let isHidden = (hasHidden)?"hidden":"";
  1296. $('body').append('<div class="IG_SN_DIG '+isHidden+'"><div class="IG_SN_DIG_BG"></div><div class="IG_SN_DIG_MAIN"><div class="IG_SN_DIG_TITLE"></div><div class="IG_SN_DIG_BODY"></div></div></div>');
  1297. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_TITLE').append('<div style="position:relative;height:36px;text-align:center;margin-bottom: 7px;"><div style="position:absolute;left:0px;line-height: 18px;"><kbd>Alt</kbd>+<kbd>Q</kbd> ['+_i18n("CLOSE")+']</div><div style="line-height: 18px;">IG Helper</div><div id="post_info" style="line-height: 14px;font-size:14px;">Post ID: <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;fill: rgb(var(--ig-primary-text));" 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>');
  1298.  
  1299. if(hasCheckbox){
  1300. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_TITLE').append(`<div style="text-align: center;" id="button_group"></div>`);
  1301. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_TITLE > div#button_group').append(`<button id="batch_download_selected">${_i18n('BATCH_DOWNLOAD_SELECTED')}</button>`);
  1302. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_TITLE > div#button_group').append(`<button id="batch_download_direct">${_i18n('BATCH_DOWNLOAD_DIRECT')}</button>`);
  1303. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_TITLE').append(`<br/><label class="checkbox"><input value="yes" type="checkbox" />${_i18n('ALL_CHECK')}</label>`);
  1304. }
  1305. }
  1306.  
  1307. /**
  1308. * IG_setDM
  1309. * Set a dialog status
  1310. *
  1311. * @param {Boolean} hasHidden
  1312. * @return {void}
  1313. */
  1314. function IG_setDM(hasHidden){
  1315. if($('.IG_SN_DIG').length){
  1316. if(hasHidden){
  1317. $('.IG_SN_DIG').addClass("hidden");
  1318. }
  1319. else{
  1320. $('.IG_SN_DIG').removeClass("hidden");
  1321. }
  1322. }
  1323. }
  1324.  
  1325. /**
  1326. * saveFiles
  1327. * Download the specified media URL to the computer
  1328. *
  1329. * @param {String} downloadLink
  1330. * @param {String} username
  1331. * @param {String} sourceType
  1332. * @param {Integer} timestamp
  1333. * @param {String} filetype
  1334. * @param {String} shortcode
  1335. * @return {void}
  1336. */
  1337. function saveFiles(downloadLink,username,sourceType,timestamp,filetype,shortcode){
  1338. $('div[id^="mount"] > div > div > div:first').removeClass('x1s85apg');
  1339. $('div[id^="mount"] > div > div > div:first').css('z-index','20000');
  1340. fetch(downloadLink).then(res => {
  1341. return res.blob().then(dwel => {
  1342. $('div[id^="mount"] > div > div > div:first').addClass('x1s85apg');
  1343. $('div[id^="mount"] > div > div > div:first').css('z-index','');
  1344. createSaveFileElement(downloadLink,dwel,username,sourceType,timestamp,filetype,shortcode);
  1345. });
  1346. });
  1347. }
  1348.  
  1349. /**
  1350. * createSaveFileElement
  1351. * Download the specified media with link element
  1352. *
  1353. * @param {String} downloadLink
  1354. * @param {Object} object
  1355. * @param {String} username
  1356. * @param {String} sourceType
  1357. * @param {Integer} timestamp
  1358. * @param {String} filetype
  1359. * @param {String} shortcode
  1360. * @return {void}
  1361. */
  1362. function createSaveFileElement(downloadLink,object,username,sourceType,timestamp,filetype,shortcode) {
  1363. const a = document.createElement("a");
  1364. const name = username+'-'+sourceType+'-'+((USER_SETTING.RENAME_SHORTCODE && shortcode)?shortcode+'-':'')+timestamp+'.'+filetype;
  1365. const originally = username + '_' + new URL(downloadLink).pathname.split('/').at(-1).split('.').slice(0,-1).join('.') + '.' + filetype;
  1366.  
  1367. a.href = URL.createObjectURL(object);
  1368. a.setAttribute("download", (USER_SETTING.AUTO_RENAME)?name:originally);
  1369. a.click();
  1370. a.remove();
  1371. }
  1372.  
  1373. /**
  1374. * triggerLinkElement
  1375. * Trigger the link element to start downloading the resource
  1376. *
  1377. * @param {Object} element
  1378. * @return {void}
  1379. */
  1380. async function triggerLinkElement(element) {
  1381. let date = new Date().getTime();
  1382. let timestamp = Math.floor(date / 1000);
  1383. let username = ($(element).attr('data-username')) ? $(element).attr('data-username') : GL_username;
  1384.  
  1385. if(!username && $(element).attr('data-path')){
  1386. console.log('catching owner name from shortcode:',$(element).attr('data-href'));
  1387. username = await getPostOwner($(element).attr('data-path'));
  1388. }
  1389.  
  1390. if(USER_SETTING.FORCE_RESOURCE_VIA_MEDIA){
  1391. let result = await getMediaInfo($(element).attr('media-id'));
  1392.  
  1393. if(result.status === 'ok'){
  1394. if(result.items[0].video_versions){
  1395. saveFiles(result.items[0].video_versions[0].url, username, $(element).attr('data-name'),timestamp, $(element).attr('data-type'), $(element).attr('data-path'));
  1396. }
  1397. else{
  1398. saveFiles(result.items[0].image_versions2.candidates[0].url, username, $(element).attr('data-name'),timestamp, $(element).attr('data-type'), $(element).attr('data-path'));
  1399. }
  1400. }
  1401. else{
  1402. alert('fetch failed from Media API, ' + result.message);
  1403. console.log(result);
  1404. }
  1405. }
  1406. else{
  1407. saveFiles($(element).attr('data-href'),username,$(element).attr('data-name'),timestamp,$(element).attr('data-type'), $(element).attr('data-path'));
  1408. }
  1409. }
  1410.  
  1411. /**
  1412. * translateText
  1413. * i18n translation text
  1414. *
  1415. * @param {String} lang
  1416. * @return {void}
  1417. */
  1418. function translateText(lang){
  1419. return {
  1420. "zh-TW": {
  1421. "SHOW_DOM_TREE": "顯示 DOM Tree",
  1422. "SELECT_AND_COPY": "全選並複製輸入框的內容",
  1423. "DOWNLOAD_DOM_TREE": "將 DOM Tree 下載為文字文件",
  1424. "REPORT_GITHUB": "在 GitHub 上回報問題",
  1425. "REPORT_DISCORD": "在 Discord 支援伺服器上回報問題",
  1426. "DEBUG": "偵錯視窗",
  1427. "CLOSE": "關閉",
  1428. "ALL_CHECK": "全選",
  1429. "BATCH_DOWNLOAD_SELECTED": "批次下載已勾選資源",
  1430. "BATCH_DOWNLOAD_DIRECT": "批次下載全部資源",
  1431. "IMG": "相片",
  1432. "VID": "影片",
  1433. "DDL": "快速下載",
  1434. "DDL_INTRO": "勾選後將直接下載點選當下位置的相片/影片",
  1435. "DW": "下載",
  1436. "THUMBNAIL_INTRO": "下載影片縮圖",
  1437. "LOAD_BLOB_ONE": "正在載入二進位大型物件...",
  1438. "LOAD_BLOB_MULTIPLE": "正在載入多個二進位大型物件...",
  1439. "LOAD_BLOB_RELOAD": "正在重新載入二進位大型物件...",
  1440. "NO_CHECK_RESOURCE": "您需要勾選資源才能下載。",
  1441. "NO_VID_URL": "找不到影片網址",
  1442. "SETTING": "設定",
  1443. "AUTO_RENAME": "自動重新命名檔案",
  1444. "RENAME_SHORTCODE": "重新命名檔案並包含 Shortcode",
  1445. "DISABLE_VIDEO_LOOPING": "關閉影片自動循環播放",
  1446. "REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE": "右鍵點擊使用者限時動態區域頭貼時重定向",
  1447. "FORCE_FETCH_ALL_RESOURCES": "強制提取貼文中所有資源",
  1448. "DIRECT_DOWNLOAD_WHEN_SINGLE": "直接下載貼文中的單一資源",
  1449. "DIRECT_DOWNLOAD_ALL": "直接下載貼文中的所有資源",
  1450. "MODIFY_VIDEO_VOLUME": "修改影片音量(右鍵設定)",
  1451. "SCROLL_BUTTON": "為連續短片頁面啟用捲動按鈕",
  1452. "FORCE_RESOURCE_VIA_MEDIA": "透過 Media API 強制提取資源",
  1453. "AUTO_RENAME_INTRO": "將檔案自動重新命名為以下格式:\n使用者名稱-類型-時間戳.檔案類型\n例如:instagram-photo-1670350000.jpg\n\n若設為 false,則檔案名稱將保持原始樣貌。 \n例如:instagram_321565527_679025940443063_4318007696887450953_n.jpg",
  1454. "RENAME_SHORTCODE_INTRO": "將檔案自動重新命名為以下格式:\n使用者名稱-類型-Shortcode-時間戳.檔案類型\n示例:instagram-photo-CwkxyiVynpW-1670350000.jpg\n\n此功能僅在[自動重新命名檔案]設定為 TRUE 時有效。",
  1455. "DISABLE_VIDEO_LOOPING_INTRO": "關閉連續短片和貼文中影片自動循環播放。",
  1456. "REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE_INTRO": "右鍵點選首頁限時動態區域中的使用者頭貼時,重新導向到使用者的個人資料頁面。",
  1457. "FORCE_FETCH_ALL_RESOURCES_INTRO": "透過 Instagram API 強制取得貼文中的所有資源(照片和影片),以取消每個貼文單次提取三個資源的限制。",
  1458. "DIRECT_DOWNLOAD_WHEN_SINGLE_INTRO": "當貼文僅有單一資源時直接下載。",
  1459. "DIRECT_DOWNLOAD_ALL_INTRO": "按下下載按鈕時將直接強制提取貼文中的所有資源並下載。",
  1460. "MODIFY_VIDEO_VOLUME_INTRO": "修改連續短片和貼文的影片播放音量(右鍵可開啟音量設定條)。",
  1461. "SCROLL_BUTTON_INTRO": "為連續短片頁面的右下角啟用上下捲動按鈕。",
  1462. "FORCE_RESOURCE_VIA_MEDIA_INTRO": "Media API 將嘗試獲取盡可能最高品質的照片或影片,但加載時間會更長。"
  1463. },
  1464. "zh-CN": {
  1465. "SHOW_DOM_TREE": "显示 DOM Tree",
  1466. "SELECT_AND_COPY": "全选并复制输入框的内容",
  1467. "DOWNLOAD_DOM_TREE": "将 DOM Tree 下载为文本文件",
  1468. "REPORT_GITHUB": "在 GitHub 上报告问题",
  1469. "REPORT_DISCORD": "在 Discord 支援服务器上报告问题",
  1470. "DEBUG": "调试窗口",
  1471. "CLOSE": "关闭",
  1472. "ALL_CHECK": "全选",
  1473. "BATCH_DOWNLOAD_SELECTED": "批量下载已勾选资源",
  1474. "BATCH_DOWNLOAD_DIRECT": "批量下载全部资源",
  1475. "IMG": "图像",
  1476. "VID": "视频",
  1477. "DDL": "便捷下载",
  1478. "DDL_INTRO": "勾选后将直接下载點擊當下位置的图像/视频",
  1479. "DW": "下载",
  1480. "THUMBNAIL_INTRO": "下载视频缩略图",
  1481. "LOAD_BLOB_ONE": "正在载入大型媒体对象...",
  1482. "LOAD_BLOB_MULTIPLE": "正在载入多个大型媒体对象...",
  1483. "LOAD_BLOB_RELOAD": "正在重新载入大型媒体对象...",
  1484. "NO_CHECK_RESOURCE": "您需要勾選资源才能下載。",
  1485. "NO_VID_URL": "找不到视频网址",
  1486. "SETTING": "设置",
  1487. "AUTO_RENAME": "自动重命名文件",
  1488. "RENAME_SHORTCODE": "重命名文件并包含物件短码",
  1489. "DISABLE_VIDEO_LOOPING": "禁用视频自动循环",
  1490. "REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE": "右键单击用户故事区域头像时重定向",
  1491. "FORCE_FETCH_ALL_RESOURCES": "强制抓取帖子中所有资源",
  1492. "DIRECT_DOWNLOAD_WHEN_SINGLE": "直接下载帖子中的单个资源",
  1493. "DIRECT_DOWNLOAD_ALL": "直接下载帖子中的所有资源",
  1494. "MODIFY_VIDEO_VOLUME": "修改视频音量(右击设置)",
  1495. "SCROLL_BUTTON": "为 Reels 页面启用卷动按钮",
  1496. "FORCE_RESOURCE_VIA_MEDIA": "通过 Media API 强制获取资源",
  1497. "AUTO_RENAME_INTRO": "将文件自动重新命名为以下格式类型:\n用户名-类型-时间戳.文件类型\n例如:instagram-photo-1670350000.jpg\n\n若设为false,则文件名将保持原样。 \n例如:instagram_321565527_679025940443063_4318007696887450953_n.jpg",
  1498. "RENAME_SHORTCODE_INTRO": "自动重命名文件为以下格式类型:\n用户名-类型-短码-时间戳.文件类型\n示例:instagram-photo-CwkxyiVynpW-1670350000.jpg\n\n它仅在[自动重命名文件]设置为 TRUE 时有效。",
  1499. "DISABLE_VIDEO_LOOPING_INTRO": "禁用 Reels 和帖子中的视频自动播放。",
  1500. "REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE_INTRO": "右键单击主页故事区域中的用户头像,重定向到用户的个人资料页面。",
  1501. "FORCE_FETCH_ALL_RESOURCES_INTRO": "通过 Instagram API 强制获取帖子中的所有资源(照片和视频),以取消每个帖子单次抓取三个资源的限制。",
  1502. "DIRECT_DOWNLOAD_WHEN_SINGLE_INTRO": "当帖子只有单一资源时直接下载。",
  1503. "DIRECT_DOWNLOAD_ALL_INTRO": "当您点击下载按钮时,帖子中的所有资源将被直接强制抓取并下载。",
  1504. "MODIFY_VIDEO_VOLUME_INTRO": "修改 Reels 和帖子中的视频播放音量(右击可开启音量设置滑条)。",
  1505. "SCROLL_BUTTON_INTRO": "为 Reels 页面的右下角启用上下卷动按钮。",
  1506. "FORCE_RESOURCE_VIA_MEDIA_INTRO": "Media API 将尝试获取尽可能最高质量的照片或视频,但加载时间会更长。"
  1507. },
  1508. "en-US": {
  1509. "SHOW_DOM_TREE": "Show DOM Tree",
  1510. "SELECT_AND_COPY": "Select All and Copy of the Input Box",
  1511. "DOWNLOAD_DOM_TREE": "Download DOM Tree as Text File",
  1512. "REPORT_GITHUB": "Report Issue On GitHub",
  1513. "REPORT_DISCORD": "Report Issue On Discord Support Server",
  1514. "DEBUG": "Debug Window",
  1515. "CLOSE": "Close",
  1516. "ALL_CHECK": "Select All",
  1517. "BATCH_DOWNLOAD_SELECTED": "Download Selected Resources",
  1518. "BATCH_DOWNLOAD_DIRECT": "Download All Resources",
  1519. "IMG": "Image",
  1520. "VID": "Video",
  1521. "DDL": "Quick Download",
  1522. "DDL_INTRO": "Checking it will direct download current photo/media in the posts.",
  1523. "DW": "Download",
  1524. "THUMBNAIL_INTRO": "Download video thumbnail.",
  1525. "LOAD_BLOB_ONE": "Loading Blob Media...",
  1526. "LOAD_BLOB_MULTIPLE": "Loading Blob Media and others...",
  1527. "LOAD_BLOB_RELOAD": "Detect Blob Media, now reloading...",
  1528. "NO_CHECK_RESOURCE": "You need to check resource to download.",
  1529. "NO_VID_URL": "Can not find video url.",
  1530. "SETTING": "Settings",
  1531. "AUTO_RENAME": "Automatically Rename Files",
  1532. "RENAME_SHORTCODE": "Rename The File and Include Shortcode",
  1533. "DISABLE_VIDEO_LOOPING": "Disable Video Auto-looping",
  1534. "REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE": "Redirect When Right-Clicking User Story Picture",
  1535. "FORCE_FETCH_ALL_RESOURCES": "Forcing Fetch All Resources In the Post",
  1536. "DIRECT_DOWNLOAD_WHEN_SINGLE": "Directly Download Single Resource In the Post",
  1537. "DIRECT_DOWNLOAD_ALL": "Directly Download All Resources In the Post",
  1538. "MODIFY_VIDEO_VOLUME": "Modify Video Volume (Right-Click To Set)",
  1539. "SCROLL_BUTTON": "Enable Scroll Buttons For Reels Page",
  1540. "FORCE_RESOURCE_VIA_MEDIA": "Force Fetch Resource via Media API",
  1541. "AUTO_RENAME_INTRO": "Auto rename file to format type following:\nUSERNAME-TYPE-TIMESTAMP.FILETYPE\nExample: instagram-photo-1670350000.jpg\n\nIf set to false, the file name will remain as it is.\nExample: instagram_321565527_679025940443063_4318007696887450953_n.jpg",
  1542. "RENAME_SHORTCODE_INTRO": "Auto rename file to format type following:\nUSERNAME-TYPE-SHORTCODE-TIMESTAMP.FILETYPE\nExample: instagram-photo-CwkxyiVynpW-1670350000.jpg\n\nIt will ONLY work in [Automatically Rename Files] setting to TRUE.",
  1543. "DISABLE_VIDEO_LOOPING_INTRO": "Disable video auto-looping in reels and posts.",
  1544. "REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE_INTRO": "Redirect to a user's profile page when right-clicking on their user avatar in the story area on the homepage.",
  1545. "FORCE_FETCH_ALL_RESOURCES_INTRO": "Force fetching of all resources (photos and videos) in a post via the Instagram API to remove the limit of three resources per post.",
  1546. "DIRECT_DOWNLOAD_WHEN_SINGLE_INTRO": "Download directly when the post only has a single resource.",
  1547. "DIRECT_DOWNLOAD_ALL_INTRO": "When you click the download button, all resources in the post will be directly forced to be fetched and downloaded.",
  1548. "MODIFY_VIDEO_VOLUME_INTRO": "Modify the video playback volume in Reels and Posts (right-click to open the volume setting slider).",
  1549. "SCROLL_BUTTON_INTRO": "Enable scroll buttons for the lower right corner of Reels page.",
  1550. "FORCE_RESOURCE_VIA_MEDIA_INTRO": "The Media API will try to get the highest quality photo or video possible, but it will take longer to load."
  1551. }
  1552. };
  1553. }
  1554.  
  1555. /**
  1556. * _i18n
  1557. * Perform i18n translation
  1558. *
  1559. * @param {String} text
  1560. * @return {void}
  1561. */
  1562. function _i18n(text){
  1563. let userLang = (lang)?lang:"en-US";
  1564. let translate = {
  1565. "zh-TW": function(){
  1566. return translateText()["zh-TW"];
  1567. },
  1568. "zh-HK": function(){
  1569. return translateText()["zh-TW"];
  1570. },
  1571. "zh-MO": function(){
  1572. return translateText()["zh-TW"];
  1573. },
  1574. "zh-CN": function(){
  1575. return translateText()["zh-CN"];
  1576. },
  1577. "en-US": function(){
  1578. return translateText()["en-US"];
  1579. }
  1580. }
  1581.  
  1582. try{
  1583. return translate[lang]()[text];
  1584. }
  1585. catch{
  1586. return translate["en-US"]()[text];
  1587. }
  1588. }
  1589.  
  1590. /**
  1591. * showSetting
  1592. * Show script settings window
  1593. *
  1594. * @return {void}
  1595. */
  1596. function showSetting(){
  1597. $('.IG_SN_DIG').remove();
  1598. IG_createDM();
  1599. $('.IG_SN_DIG #post_info').text('IG Helper Settings');
  1600.  
  1601.  
  1602. for(let name in USER_SETTING){
  1603. $('.IG_SN_DIG .IG_SN_DIG_BODY').append(`<label class="globalSettings" title="${_i18n(name+'_INTRO')}"><span>${_i18n(name)}</span> <input id="${name}" value="box" type="checkbox" ${(USER_SETTING[name] === true)?'checked':''}><div class="chbtn"><div class="rounds"></div></div></label>`);
  1604.  
  1605. if(name === 'MODIFY_VIDEO_VOLUME'){
  1606. $('.IG_SN_DIG .IG_SN_DIG_BODY input[id="'+name+'"]').parent('label').on('contextmenu', function(e){
  1607. e.preventDefault();
  1608. if($(this).find('#tempWrapper').length === 0){
  1609. $(this).append('<div id="tempWrapper"></div>');
  1610. $(this).children('#tempWrapper').append('<input value="' + VIDEO_VOLUME + '" type="range" min="0" max="1" step="0.05" />');
  1611. $(this).children('#tempWrapper').append('<input value="' + VIDEO_VOLUME + '" step="0.05" type="number" />');
  1612. $(this).children('#tempWrapper').append('<svg width="26" height="26" class="IG_SN_DIG_BTN" style="cursor:pointer;position:absolute;right:5px;top:0px;fill: rgb(var(--ig-primary-text));" 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>');
  1613. }
  1614. });
  1615. }
  1616. }
  1617. }
  1618.  
  1619. /**
  1620. * showDebugDOM
  1621. * Show full DOM tree
  1622. *
  1623. * @return {void}
  1624. */
  1625. function showDebugDOM(){
  1626. $('.IG_SN_DIG').remove();
  1627. IG_createDM();
  1628. $('.IG_SN_DIG #post_info').text('IG Debug DOM Tree');
  1629.  
  1630. $('.IG_SN_DIG .IG_SN_DIG_BODY').append(`<textarea style="width:100%;box-sizing: border-box;height:300px;" readonly></textarea>`);
  1631. $('.IG_SN_DIG .IG_SN_DIG_BODY').append(`<span style="display:block;text-align:center;">`);
  1632. $('.IG_SN_DIG .IG_SN_DIG_BODY span').append(`<button class="IG_DISPLAY_DOM_TREE"><a>${_i18n('SHOW_DOM_TREE')}</a></button>`);
  1633. $('.IG_SN_DIG .IG_SN_DIG_BODY span').append(`<button class="IG_SELECT_DOM_TREE"><a>${_i18n('SELECT_AND_COPY')}</a></button>`);
  1634. $('.IG_SN_DIG .IG_SN_DIG_BODY span').append(`<button class="IG_DOWNLOAD_DOM_TREE"><a>${_i18n('DOWNLOAD_DOM_TREE')}</a></button><br/>`);
  1635. $('.IG_SN_DIG .IG_SN_DIG_BODY span').append(`<button class="IG_REPORT_GITHUB"><a href="https://github.com/SN-Koarashi/ig-helper/issues" target="_blank">${_i18n('REPORT_GITHUB')}</a></button>`);
  1636. $('.IG_SN_DIG .IG_SN_DIG_BODY span').append(`<button class="IG_REPORT_DISCORD"><a href="https://discord.gg/Sh8HJ4d" target="_blank">${_i18n('REPORT_DISCORD')}</a></button>`);
  1637. }
  1638.  
  1639. // Running if document is ready
  1640. $(function(){
  1641. $('body').on('click','.IG_SN_DIG .IG_SN_DIG_BODY .IG_DISPLAY_DOM_TREE',function(){
  1642. let text = $('div[id^="mount"]')[0];
  1643. $('.IG_SN_DIG .IG_SN_DIG_BODY textarea').text("Location: " + location.pathname + "\nDOM Tree:\n" + text.innerHTML);
  1644. });
  1645.  
  1646. $('body').on('click','.IG_SN_DIG .IG_SN_DIG_BODY .IG_SELECT_DOM_TREE',function(){
  1647. $('.IG_SN_DIG .IG_SN_DIG_BODY textarea').select();
  1648. document.execCommand('copy');
  1649. });
  1650.  
  1651. $('body').on('click','.IG_SN_DIG .IG_SN_DIG_BODY .IG_DOWNLOAD_DOM_TREE',function(){
  1652. var text = ($('.IG_SN_DIG .IG_SN_DIG_BODY textarea').text().length > 0)?$('.IG_SN_DIG .IG_SN_DIG_BODY textarea').text():"Location: " + location.pathname + "\nDOM Tree:\n" +$('div[id^="mount"]')[0].innerHTML;
  1653. var a = document.createElement("a");
  1654. var file = new Blob([text], {type: "text/plain"});
  1655. a.href = URL.createObjectURL(file);
  1656. a.download = "DOMTree.txt";
  1657.  
  1658. document.body.appendChild(a);
  1659. a.click();
  1660. a.remove();
  1661. });
  1662.  
  1663. // Close the download dialog if user click the close icon
  1664. $('body').on('click','.IG_SN_DIG_BTN,.IG_SN_DIG_BG',function(){
  1665. if($(this).parent('#tempWrapper').length > 0){
  1666. $(this).parent('#tempWrapper').fadeOut(250, function(){
  1667. $(this).remove();
  1668. });
  1669. }
  1670. else{
  1671. $('.IG_SN_DIG').remove();
  1672. }
  1673. });
  1674.  
  1675. $(window).keydown(function(e){
  1676. // Hot key [Alt+Q] to close the download dialog
  1677. if (e.keyCode == '81' && e.altKey){
  1678. $('.IG_SN_DIG').remove();
  1679. e.preventDefault();
  1680. }
  1681. // Hot key [Alt+W] to open the settings dialog
  1682. if (e.keyCode == '87' && e.altKey){
  1683. showSetting();
  1684. e.preventDefault();
  1685. }
  1686.  
  1687. // Hot key [Alt+Z] to open the settings dialog
  1688. if (e.keyCode == '90' && e.altKey){
  1689. showDebugDOM();
  1690. e.preventDefault();
  1691. }
  1692. });
  1693.  
  1694. $('body').on('change', '.IG_SN_DIG input',function(e){
  1695. var name = $(this).attr('id');
  1696.  
  1697. if(name && USER_SETTING[name] !== undefined){
  1698. let isChecked = $(this).prop('checked');
  1699. GM_setValue(name, isChecked);
  1700. USER_SETTING[name] = isChecked;
  1701.  
  1702. console.log('user settings', name, isChecked);
  1703. }
  1704. });
  1705.  
  1706. $('body').on('click', '.IG_SN_DIG .globalSettings',function(e){
  1707. if($(this).find('#tempWrapper').length > 0){
  1708. e.preventDefault();
  1709. }
  1710. });
  1711.  
  1712. $('body').on('change', '.IG_SN_DIG #tempWrapper input',function(){
  1713. let value = $(this).val();
  1714.  
  1715. if($(this).attr('type') == 'range'){
  1716. $(this).next().val(value);
  1717. }
  1718. else{
  1719. $(this).prev().val(value);
  1720. }
  1721.  
  1722. if(value >= 0 && value <= 1){
  1723. VIDEO_VOLUME = value;
  1724. GM_setValue('G_VIDEO_VOLUME', value);
  1725. }
  1726. });
  1727.  
  1728. $('body').on('input', '.IG_SN_DIG #tempWrapper input',function(e){
  1729. if($(this).attr('type') == 'range'){
  1730. let value = $(this).val();
  1731. $(this).next().val(value);
  1732. }
  1733. else{
  1734. let value = $(this).val();
  1735. if(value >= 0 && value <= 1){
  1736. $(this).prev().val(value);
  1737. }
  1738. else{
  1739. if(value < 0){
  1740. $(this).val(0);
  1741. }
  1742. else{
  1743. $(this).val(1);
  1744. }
  1745. }
  1746. }
  1747. });
  1748.  
  1749.  
  1750. $('body').on('click','a[data-needed="direct"]',async function(){
  1751. triggerLinkElement(this);
  1752. });
  1753.  
  1754. // Running if user left-click download icon in stories
  1755. $('body').on('click','.IG_DWSTORY',function(){
  1756. onStory(true);
  1757. });
  1758.  
  1759. // Running if user left-click download icon in stories
  1760. $('body').on('click','.IG_DWSTORY_THUMBNAIL',function(){
  1761. onStoryThumbnail(true);
  1762. });
  1763.  
  1764. // Running if user left-click download icon in profile
  1765. $('body').on('click','.IG_DWPROFILE',function(e){
  1766. e.stopPropagation();
  1767. onProfileAvatar(true);
  1768. });
  1769.  
  1770. // Running if user left-click download icon in highlight stories
  1771. $('body').on('click','.IG_DWHISTORY',function(){
  1772. onHighlightsStory(true);
  1773. });
  1774.  
  1775. // Running if user left-click download icon in highlight stories
  1776. $('body').on('click','.IG_DWHISTORY_THUMBNAIL',function(){
  1777. onHighlightsStoryThumbnail(true);
  1778. });
  1779.  
  1780. // Running if user left-click download icon in reels
  1781. $('body').on('click','.IG_REELS',function(){
  1782. onReels(true,true);
  1783. });
  1784.  
  1785. // Running if user left-click download icon in reels
  1786. $('body').on('click','.IG_REELS_THUMBNAIL',function(){
  1787. onReels(true,false);
  1788. });
  1789.  
  1790. // Running if user right-click profile picture in stories area
  1791. $('body').on('contextmenu','button[role="menuitem"]',function(){
  1792. if(location.href === 'https://www.instagram.com/' && USER_SETTING.REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE){
  1793. if($(this).find('canvas._aarh').length > 0){
  1794. location.href = 'https://www.instagram.com/'+$(this).children('div').last().text();
  1795. }
  1796. }
  1797. });
  1798.  
  1799. $('body').on('change', '.IG_SN_DIG_TITLE .checkbox', function(){
  1800. var isChecked = $(this).find('input').prop('checked');
  1801. $('.IG_SN_DIG_BODY .inner_box').each(function(){
  1802. $(this).prop('checked', isChecked);
  1803. });
  1804. });
  1805.  
  1806. $('body').on('change', '.IG_SN_DIG_BODY .inner_box', function(){
  1807. var checked = $('.IG_SN_DIG_BODY .inner_box:checked').length;
  1808. var total = $('.IG_SN_DIG_BODY .inner_box').length;
  1809.  
  1810.  
  1811. $('.IG_SN_DIG_TITLE .checkbox').find('input').prop('checked', checked == total);
  1812. });
  1813.  
  1814. $('body').on('click', '.IG_SN_DIG_TITLE #batch_download_selected', function(){
  1815. let index = 0;
  1816. $('.IG_SN_DIG_BODY a[data-needed="direct"]').each(function(){
  1817. if($(this).prev().children('input').prop('checked')){
  1818. $(this).click();
  1819. index++;
  1820. }
  1821. });
  1822.  
  1823. if(index == 0){
  1824. alert(_i18n('NO_CHECK_RESOURCE'));
  1825. }
  1826. });
  1827.  
  1828. $('body').on('click', '.IG_SN_DIG_TITLE #batch_download_direct', function(){
  1829. $('.IG_SN_DIG_BODY a[data-needed="direct"]').each(function(){
  1830. $(this).click();
  1831. });
  1832. });
  1833. });
  1834. })(jQuery);