IG小助手

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

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

  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.10.1
  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. // @connect i.instagram.com
  22. // @require https://code.jquery.com/jquery-3.6.3.min.js#sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=
  23. // @supportURL https://discord.gg/Sh8HJ4d
  24. // @contributionURL https://ko-fi.com/snkoarashi
  25. // @icon https://www.google.com/s2/favicons?domain=www.instagram.com
  26. // @compatible firefox >= 87
  27. // @compatible chrome >= 90
  28. // @compatible edge >= 90
  29. // @license GPLv3
  30. // ==/UserScript==
  31.  
  32. (function($) {
  33. 'use strict';
  34. // Icon download by https://www.flaticon.com/authors/pixel-perfect
  35.  
  36. /******** USER SETTINGS ********/
  37. // !!! DO NOT CHANGE THIS AREA !!!
  38. // PLEASE CHANGE SETTING WITH MENU
  39. const USER_SETTING = {
  40. 'AUTO_RENAME': (GM_getValue('AUTO_RENAME'))?GM_getValue('AUTO_RENAME'):true,
  41. 'RENAME_SHORTCODE': (GM_getValue('RENAME_SHORTCODE'))?GM_getValue('RENAME_SHORTCODE'):true,
  42. 'DISABLE_VIDEO_LOOPING': (GM_getValue('DISABLE_VIDEO_LOOPING'))?GM_getValue('DISABLE_VIDEO_LOOPING'):false,
  43. 'REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE': (GM_getValue('REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE'))?GM_getValue('REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE'):false,
  44. 'FORCE_FETCH_ALL_RESOURCES': (GM_getValue('FORCE_FETCH_ALL_RESOURCES'))?GM_getValue('FORCE_FETCH_ALL_RESOURCES'):false
  45. };
  46. /*******************************/
  47.  
  48. const checkInterval = 250;
  49. const lang = navigator.language || navigator.userLanguage;
  50.  
  51. var currentURL = location.href;
  52. var currentHeight = $(document).height();
  53. var firstStarted = false;
  54. var pageLoaded = false;
  55.  
  56. var GL_postPath;
  57. var GL_username;
  58. var GL_repeat
  59. var GL_dataCache = {
  60. stories: {},
  61. highlights: {}
  62. };
  63.  
  64. // Main Timer
  65. var timer = setInterval(function(){
  66. currentHeight = $(document).height();
  67. // Call Instagram dialog function if url changed.
  68. if(currentURL != location.href || !firstStarted || !pageLoaded){
  69. clearInterval(GL_repeat);
  70. pageLoaded = false;
  71. firstStarted = true;
  72. currentURL = location.href;
  73.  
  74. if(location.href.startsWith("https://www.instagram.com/p/") || location.href.startsWith("https://www.instagram.com/reel/")){
  75. GL_dataCache.stories = {};
  76.  
  77. console.log('isDialog');
  78. setTimeout(()=>{
  79. onReadyMyDW(false);
  80. },150);
  81. pageLoaded = true;
  82. }
  83.  
  84. if(location.href.startsWith("https://www.instagram.com/reels/")){
  85. console.log('isReels');
  86. setTimeout(()=>{
  87. onReelsDW(false);
  88. },150);
  89. pageLoaded = true;
  90. }
  91.  
  92. if(location.href.split("?")[0] == "https://www.instagram.com/"){
  93. GL_dataCache.stories = {};
  94.  
  95. console.log('isHomepage');
  96. setTimeout(()=>{
  97. onReadyMyDW(false);
  98. },150);
  99. pageLoaded = true;
  100. }
  101. if($('div[id^="mount"] > div > div > div').first().is(':hidden') && $('canvas._aarh').length && location.href.match(/^(https:\/\/www\.instagram\.com\/)([0-9A-Za-z\.\-_]+)\/?$/ig) && !location.href.match(/^(https:\/\/www\.instagram\.com\/(stories|explore)\/?)/ig)){
  102. console.log('isProfile');
  103. setTimeout(()=>{
  104. onProfileDW(false);
  105. },150);
  106. pageLoaded = true;
  107. }
  108.  
  109. if(!pageLoaded){
  110. // Call Instagram stories function
  111. if(location.href.match(/^(https:\/\/www\.instagram\.com\/stories\/highlights\/)/ig)){
  112. GL_dataCache.highlights = {};
  113.  
  114. console.log('isHighlightsStory');
  115. onHighlightsStoryDW(false);
  116. GL_repeat = setInterval(()=>{
  117. onHighlightsStoryThumbnailDW(false);
  118. },checkInterval);
  119.  
  120. if($(".IG_DWHISTORY").length) setTimeout(()=>{pageLoaded = true;},150);
  121. }
  122. else if(location.href.match(/^(https:\/\/www\.instagram\.com\/stories\/)/ig)){
  123. console.log('isStory');
  124. onStoryDW(false);
  125. onStoryThumbnailDW(false);
  126.  
  127. if($(".IG_DWSTORY").length) setTimeout(()=>{pageLoaded = true;},150);
  128. }
  129. else{
  130. pageLoaded = false;
  131. // Remove the download icon
  132. $('.IG_DWSTORY').remove();
  133. $('.IG_DWSTORY_THUMBNAIL').remove();
  134. }
  135. }
  136.  
  137. }
  138.  
  139. // Direct Download Checkbox
  140. /*
  141. if(!$('.AutoDownload_dom').length){
  142. let ckValue = (GM_getValue('AutoDownload'))?'checked':'';
  143. $('body div.mfclru0v.astyfpdk.om3e55n1.jez8cy9q').css('position','relative');
  144. $('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>`);
  145. }
  146. */
  147. },checkInterval);
  148.  
  149. // Call general function when user scroll the page
  150. $(document).scroll(function(){
  151. if(currentHeight != $(this).height() && location.href.split("?")[0] == "https://www.instagram.com/"){
  152. onReadyMyDW();
  153. }
  154. });
  155.  
  156. // Profile funcion
  157. async function onProfileDW(isDownload){
  158. if(isDownload){
  159. let date = new Date().getTime();
  160. let timestamp = Math.floor(date / 1000);
  161. let username = location.href.replace(/\/$/ig,'').split('/').at(-1);
  162. let userInfo = await getUserId(username);
  163. try{
  164. let dataURL = await getUserHighSizeProfile(userInfo.user.pk);
  165. saveFiles(dataURL,username,"avatar",timestamp,'jpg');
  166. }
  167. catch(err){
  168. saveFiles(userInfo.user.profile_pic_url,username,"avatar",timestamp,'jpg');
  169. }
  170. }
  171. else{
  172. // Add the profile download button
  173. if(!$('.IG_DWPROFILE').length){
  174. let profileTimer = setInterval(()=>{
  175. if($('.IG_DWPROFILE').length) clearInterval(profileTimer);
  176.  
  177. $('body > div main canvas._aarh').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>`);
  178. },150);
  179.  
  180. return true;
  181. }
  182. }
  183. }
  184.  
  185. // Highlight Stories funcion
  186. async function onHighlightsStoryDW(isDownload){
  187. if(isDownload){
  188. let date = new Date().getTime();
  189. let timestamp = Math.floor(date / 1000);
  190. let highlightId = location.href.replace(/\/$/ig,'').split('/').at(-1);
  191. let nowIndex = $("body > div section._ac0a header._ac0k > ._ac3r ._ac3n ._ac3p[style]").length;
  192. let username = "";
  193. let target = 0;
  194.  
  195. if(GL_dataCache.highlights[highlightId]){
  196. console.log('Fetch from memory cache:', highlightId);
  197.  
  198. let totIndex = GL_dataCache.highlights[highlightId].data.reels_media[0].items.length;
  199. username = GL_dataCache.highlights[highlightId].data.reels_media[0].owner.username;
  200. target = GL_dataCache.highlights[highlightId].data.reels_media[0].items[totIndex-nowIndex];
  201. }
  202. else{
  203. let highStories = await getHighlightsStories(highlightId);
  204. let totIndex = highStories.data.reels_media[0].items.length;
  205. username = highStories.data.reels_media[0].owner.username;
  206. target = highStories.data.reels_media[0].items[totIndex-nowIndex];
  207.  
  208. GL_dataCache.highlights[highlightId] = highStories;
  209. }
  210.  
  211. if(target.is_video){
  212. saveFiles(target.video_resources.at(-1).src,username,"highlights",timestamp,'mp4', highlightId);
  213. }
  214. else{
  215. saveFiles(target.display_resources.at(-1).src,username,"highlights",timestamp,'jpg', highlightId);
  216. }
  217. }
  218. else{
  219. // Add the stories download button
  220. if(!$('.IG_DWHISTORY').length){
  221. $('body > div section._ac0a').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>`);
  222. return true;
  223. }
  224. }
  225. }
  226.  
  227. // Highlight Stories Thumbnail funcion
  228. async function onHighlightsStoryThumbnailDW(isDownload){
  229. if(isDownload){
  230. let date = new Date().getTime();
  231. let timestamp = Math.floor(date / 1000);
  232. let highlightId = location.href.replace(/\/$/ig,'').split('/').at(-1);
  233. let username = "";
  234. let nowIndex = $("body > div section._ac0a header._ac0k > ._ac3r ._ac3n ._ac3p[style]").length;
  235. let target = "";
  236.  
  237. if(GL_dataCache.highlights[highlightId]){
  238. console.log('Fetch from memory cache:', highlightId);
  239.  
  240. let totIndex = GL_dataCache.highlights[highlightId].data.reels_media[0].items.length;
  241. username = GL_dataCache.highlights[highlightId].data.reels_media[0].owner.username;
  242. target = GL_dataCache.highlights[highlightId].data.reels_media[0].items[totIndex-nowIndex];
  243. }
  244. else{
  245. let highStories = await getHighlightsStories(highlightId);
  246. let totIndex = highStories.data.reels_media[0].items.length;
  247. username = highStories.data.reels_media[0].owner.username;
  248. target = highStories.data.reels_media[0].items[totIndex-nowIndex];
  249.  
  250. GL_dataCache.highlights[highlightId] = highStories;
  251. }
  252.  
  253. saveFiles(target.display_resources.at(-1).src,username,"highlights",timestamp,'jpg', highlightId);
  254. }
  255. else{
  256. if($('body > div section._ac0a video.xh8yej3').length){
  257. // Add the stories download button
  258. if(!$('.IG_DWHISTORY_THUMBNAIL').length){
  259. $('body > div section._ac0a').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>`);
  260. }
  261. }
  262. else{
  263. $('.IG_DWHISTORY_THUMBNAIL').remove();
  264. }
  265. }
  266. }
  267.  
  268. // Stories funcion
  269. async function onStoryDW(isDownload,isForce){
  270. if(isDownload){
  271. let date = new Date().getTime();
  272. let timestamp = Math.floor(date / 1000);
  273. let username = $("body > div section._ac0a header._ac0k ._ac0l a + div a").first().text() || location.pathname.split('/').at(2);
  274.  
  275. if($('body > div section._ac0a div._ac0b video.x1lliihq').length){
  276. // Download stories if it is video
  277. let type = "mp4";
  278. let videoURL = "";
  279. let targetURL = location.href.replace(/\/$/ig,'').split("/").at(-1);
  280.  
  281. if(GL_dataCache.stories[username] && !isForce){
  282. console.log('Fetch from memory cache:', username);
  283. GL_dataCache.stories[username].data.reels_media[0].items.forEach(item => {
  284. if(item.id == targetURL){
  285. videoURL = item.video_resources[0].src;
  286. }
  287. });
  288.  
  289. if(videoURL.length == 0){
  290. console.log('Memory cache not found, try fetch from API:', username);
  291. onStoryDW(true,true);
  292. return;
  293. }
  294. }
  295. else{
  296. let userInfo = await getUserId(username);
  297. let userId = userInfo.user.pk;
  298. let stories = await getStories(userId);
  299.  
  300. stories.data.reels_media[0].items.forEach(item => {
  301. if(item.id == targetURL){
  302. videoURL = item.video_resources[0].src;
  303. }
  304. });
  305.  
  306. GL_dataCache.stories[username] = stories;
  307. }
  308.  
  309. if(videoURL.length == 0){
  310. alert(_i18n("NO_VID_URL"));
  311. }
  312. else{
  313. saveFiles(videoURL,username,"stories",timestamp,type);
  314. }
  315.  
  316. }
  317. else{
  318. // Download stories if it is image
  319. let srcset = $('section._ac0a ._aa64 img._aa63').attr('srcset').split(',')[0].split(' ')[0];
  320. let link = (srcset)?srcset:$('section._ac0a ._aa64 img._aa63').attr('src');
  321.  
  322. let downloadLink = link;
  323. let type = 'jpg';
  324.  
  325. saveFiles(downloadLink,username,"stories",timestamp,type);
  326. }
  327. }
  328. else{
  329. // Add the stories download button
  330. let style = "position: absolute;right:-40px;top:15px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  331. if(!$('.IG_DWSTORY').length){
  332. GL_dataCache.stories = {};
  333. $('body > div section._ac0a').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>`);
  334. return true;
  335. }
  336. }
  337. }
  338.  
  339. // Stories Thumbnail funcion
  340. async function onStoryThumbnailDW(isDownload,isForce){
  341. if(isDownload){
  342. // Download stories if it is video
  343. let date = new Date().getTime();
  344. let timestamp = Math.floor(date / 1000);
  345. let type = 'jpg';
  346. let username = $("body > div section._ac0a header._ac0k ._ac0l a + div a").first().text() || location.pathname.split('/').at(2);
  347. 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;';
  348. // Download thumbnail
  349. let targetURL = location.href.replace(/\/$/ig,'').split("/").at(-1);
  350. let videoThumbnailURL = "";
  351.  
  352.  
  353. if(GL_dataCache.stories[username] && !isForce){
  354. console.log('Fetch from memory cache:', username);
  355. GL_dataCache.stories[username].data.reels_media[0].items.forEach(item => {
  356. if(item.id == targetURL){
  357. videoThumbnailURL = item.display_url;
  358. }
  359. });
  360.  
  361. if(videoThumbnailURL.length == 0){
  362. console.log('Memory cache not found, try fetch from API:', username);
  363. onStoryThumbnailDW(true,true);
  364. return;
  365. }
  366. }
  367. else{
  368. let userInfo = await getUserId(username);
  369. let userId = userInfo.user.pk;
  370. let stories = await getStories(userId);
  371.  
  372. stories.data.reels_media[0].items.forEach(item => {
  373. if(item.id == targetURL){
  374. videoThumbnailURL = item.display_url;
  375. }
  376. });
  377. }
  378.  
  379. saveFiles(videoThumbnailURL,username,"thumbnail",timestamp,type);
  380. }
  381. else{
  382. if($('body > div section._ac0a video.xh8yej3').length){
  383. // Add the stories download button
  384. if(!$('.IG_DWSTORY_THUMBNAIL').length){
  385. $('body > div section._ac0a').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>`);
  386. }
  387. }
  388. else{
  389. $('.IG_DWSTORY_THUMBNAIL').remove();
  390. }
  391. }
  392. }
  393.  
  394. // Reels funcion
  395. async function onReelsDW(isDownload, isVideo){
  396. if(isDownload){
  397. let reelsPath = location.href.split('?').at(0).split('instagram.com/reels/').at(-1).replaceAll('/','');
  398. let data = await getBlobMedia(reelsPath);
  399. let timestamp = new Date().getTime();
  400.  
  401. if(isVideo && data.shortcode_media.is_video){
  402. let type = 'mp4';
  403. saveFiles(data.shortcode_media.video_url,data.shortcode_media.owner.username,"reels",timestamp,type,reelsPath);
  404. }
  405. else{
  406. let type = 'jpg';
  407. saveFiles(data.shortcode_media.display_resources.at(-1).src,data.shortcode_media.owner.username,"reels",timestamp,type,reelsPath);
  408. }
  409. }
  410. else{
  411. //$('.IG_REELS_THUMBNAIL, .IG_REELS').remove();
  412. var timer = setInterval(()=>{
  413. if($('section > main[role="main"] > div div.x1qjc9v5 video').length > 0){
  414. clearInterval(timer);
  415. $('section > main[role="main"] > div').children('div').each(function(){
  416. if($(this).children().length > 0){
  417. if(!$(this).children().find('.IG_REELS').length){
  418. $(this).children().css('position','relative');
  419.  
  420. $(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>`);
  421. $(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>`);
  422.  
  423. // Disable video autoplay
  424. if(USER_SETTING.DISABLE_VIDEO_LOOPING){
  425. $(this).find('video').each(function(){
  426. if(!$(this).data('loop')){
  427. console.log('Added video event listener');
  428. $(this).on('ended',function(){
  429. $(this).attr('data-loop', true);
  430. $(this).parent().find('.xpgaw4o').removeAttr('style');
  431. console.log('paused');
  432.  
  433. this.pause();
  434. });
  435. }
  436. });
  437. }
  438. }
  439. }
  440. });
  441. }
  442. },250);
  443. }
  444. }
  445.  
  446. // Prepare promise to fetch user stories
  447. function getHighlightsStories(highlightId){
  448. return new Promise((resolve,reject)=>{
  449. 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`;
  450.  
  451. GM_xmlhttpRequest({
  452. method: "GET",
  453. url: getURL,
  454. onload: function(response) {
  455. let obj = JSON.parse(response.response);
  456. resolve(obj);
  457. },
  458. onerror: function(err){
  459. reject(err);
  460. }
  461. });
  462. });
  463. }
  464.  
  465. // Prepare promise to fetch user stories
  466. function getStories(userId){
  467. return new Promise((resolve,reject)=>{
  468. 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`;
  469.  
  470. GM_xmlhttpRequest({
  471. method: "GET",
  472. url: getURL,
  473. onload: function(response) {
  474. let obj = JSON.parse(response.response);
  475. resolve(obj);
  476. },
  477. onerror: function(err){
  478. reject(err);
  479. }
  480. });
  481. });
  482. }
  483.  
  484. // Prepare promise to fetch user id by username
  485. function getUserId(username){
  486. return new Promise((resolve,reject)=>{
  487. let getURL = `https://www.instagram.com/web/search/topsearch/?query=${username}`;
  488.  
  489. GM_xmlhttpRequest({
  490. method: "GET",
  491. url: getURL,
  492. onload: function(response) {
  493. let obj = JSON.parse(response.response);
  494. resolve(obj.users[0]);
  495. },
  496. onerror: function(err){
  497. reject(err);
  498. }
  499. });
  500. });
  501. }
  502.  
  503. // Prepare promise to fetch user profile picture by user id
  504. function getUserHighSizeProfile(userId){
  505. return new Promise((resolve,reject)=>{
  506. let getURL = `https://i.instagram.com/api/v1/users/${userId}/info/`;
  507.  
  508. GM_xmlhttpRequest({
  509. method: "GET",
  510. url: getURL,
  511. headers: {
  512. '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'
  513. },
  514. onload: function(response) {
  515. let obj = JSON.parse(response.response);
  516. if(obj.status !== 'ok'){
  517. reject('faild');
  518. }
  519. else{
  520. resolve(obj.user.hd_profile_pic_url_info?.url);
  521. }
  522. },
  523. onerror: function(err){
  524. reject(err);
  525. }
  526. });
  527. });
  528. }
  529.  
  530. // Prepare promise to catch article author using shortcode
  531. function getPostOwner(postPath){
  532. return new Promise((resolve,reject)=>{
  533. if(!postPath) reject("NOPATH");
  534. let postShortCode = postPath;
  535. let getURL = `https://www.instagram.com/graphql/query/?query_hash=2c4c2e343a8f64c625ba02b2aa12c7f8&variables=%7B%22shortcode%22:%22${postShortCode}%22}`;
  536.  
  537. GM_xmlhttpRequest({
  538. method: "GET",
  539. url: getURL,
  540. onload: function(response) {
  541. let obj = JSON.parse(response.response);
  542. resolve(obj.data.shortcode_media.owner.username);
  543. },
  544. onerror: function(err){
  545. reject(err);
  546. }
  547. });
  548. });
  549. }
  550.  
  551. // Prepare promise to cache article which contains blob media
  552. function getBlobMedia(postPath){
  553. return new Promise((resolve,reject)=>{
  554. if(!postPath) reject("NOPATH");
  555. let postShortCode = postPath;
  556. let getURL = `https://www.instagram.com/graphql/query/?query_hash=2c4c2e343a8f64c625ba02b2aa12c7f8&variables=%7B%22shortcode%22:%22${postShortCode}%22}`;
  557.  
  558. GM_xmlhttpRequest({
  559. method: "GET",
  560. url: getURL,
  561. onload: function(response) {
  562. let obj = JSON.parse(response.response);
  563. console.log(obj);
  564. resolve(obj.data);
  565. },
  566. onerror: function(err){
  567. reject(err);
  568. }
  569. });
  570. });
  571. }
  572.  
  573. // Main function
  574. function onReadyMyDW(NoDialog){
  575. // Whether is Instagram dialog?
  576. if(!NoDialog){
  577. // Running if it is dialog
  578. $('article, main > div > div.xdt5ytf > div').each(function(){
  579. $(this).removeAttr('data-snig');
  580. $(this).unbind('click');
  581. });
  582. $('.SNKMS_IG_DW_MAIN,.SNKMS_IG_DW_MAIN_VIDEO').remove();
  583. }
  584. if(NoDialog == false){
  585. var repeat = setInterval(() => {
  586. // div.x13ehr01 << (sigle post in top, not floating) >>
  587. if($('article[data-snig="canDownload"], main > div > div.xdt5ytf > div[data-snig="canDownload"]').length > 0) clearInterval(repeat);
  588. createDownloadButton();
  589. },250);
  590. }
  591. else{
  592. createDownloadButton();
  593. }
  594. }
  595.  
  596. function createDownloadButton(){
  597. // Add download icon per each posts
  598. $('article, main > div > div.xdt5ytf > div').each(function(){
  599. // If it is have not download icon
  600. if(!$(this).attr('data-snig') && !$(this).hasClass('x1iyjqo2')){
  601. console.log("Found article");
  602. var rightPos = 15;
  603. if(this.tagName === "DIV"){
  604. rightPos = ($(this).children('div:last-child').width() !== undefined) ? $(this).children('div:last-child').width()+15 : 335+15
  605. }
  606.  
  607. // Add the download icon
  608. let $childElement = $(this).children("div").children("div");
  609. $childElement.eq((this.tagName === "DIV")? 0 : $childElement.length - 2).append(`<div title="${_i18n("DW")}" class="SNKMS_IG_DW_MAIN" style="right:${rightPos}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>`);
  610.  
  611. // Disable video autoplay
  612. if(USER_SETTING.DISABLE_VIDEO_LOOPING){
  613. $(this).find('video').each(function(){
  614. if(!$(this).data('loop')){
  615. console.log('Added video event listener');
  616. $(this).on('ended',function(){
  617. $(this).attr('data-loop', true);
  618. this.pause();
  619. });
  620. }
  621. });
  622. }
  623.  
  624. // Running if user click the download icon
  625. $(this).on('click','.SNKMS_IG_DW_MAIN', async function(e){
  626. GL_username = $(this).parent().parent().parent().attr('data-username');
  627. 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);
  628.  
  629. // Create element that download dailog
  630. IG_createDM(GM_getValue('AutoDownload'), true);
  631.  
  632. $("#article-id").text(GL_postPath);
  633.  
  634. // Find video/image element and add the download icon
  635. var s = 0;
  636. var multiple = $(this).parent().parent().find('._aap0 ._acaz').length;
  637. var pathname = window.location.pathname;
  638. var fullpathname = "/"+pathname.split('/')[1]+"/"+pathname.split('/')[2]+"/";
  639. var blob = USER_SETTING.FORCE_FETCH_ALL_RESOURCES;
  640.  
  641. // If posts have more than one images or videos.
  642. if(multiple){
  643. $(this).parent().find('._aap0 ._acaz').each(function(){
  644. let element_videos = $(this).parent().parent().find('video');
  645. //if(element_videos && element_videos.attr('src') && element_videos.attr('src').match(/^blob:/ig)){
  646. if(element_videos && element_videos.attr('src')){
  647. blob = true;
  648. }
  649. });
  650.  
  651.  
  652. if(blob){
  653. createMediaCacheDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",_i18n("LOAD_BLOB_MULTIPLE"));
  654. }
  655. else{
  656. $(this).parent().find('._aap0 ._acaz').each(function(){
  657. s++;
  658. let element_videos = $(this).find('video');
  659. let element_images = $(this).find('._aagv img');
  660. let imgLink = (element_images.attr('srcset'))?element_images.attr('srcset').split(" ")[0]:element_images.attr('src');
  661.  
  662. if(element_videos && element_videos.attr('src')){
  663. blob = true;
  664. /*
  665. let video_image = element_videos.attr('poster');
  666. let video_url = element_videos.attr('src');
  667.  
  668. $('.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}" href="javascript:;" data-href="${video_url}"><img width="100" src="${video_image}" /><br/>- ${_i18n("VID")} ${s} -</a>`);
  669.  
  670. if(video_url.match(/^blob:/ig)) blob = true;
  671. */
  672. }
  673. if(element_images && imgLink){
  674. $('.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>`);
  675. }
  676.  
  677. });
  678.  
  679. if(blob){
  680. createMediaCacheDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",_i18n("LOAD_BLOB_RELOAD"));
  681. }
  682. }
  683. }
  684. else{
  685. s++;
  686. let element_videos = $(this).parent().parent().find('video');
  687. let element_images = $(this).parent().parent().find('._aagv img');
  688. let imgLink = (element_images.attr('srcset'))?element_images.attr('srcset').split(" ")[0]:element_images.attr('src');
  689.  
  690.  
  691. if(element_videos && element_videos.attr('src')){
  692. createMediaCacheDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",_i18n("LOAD_BLOB_ONE"));
  693.  
  694. /*
  695. let video_image = element_videos.attr('poster');
  696. let video_url = element_videos.attr('src');
  697.  
  698. if(element_videos.attr('src').match(/^blob:/ig)){
  699. createMediaCacheDOM(GL_postPath,".IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY",_i18n("LOAD_BLOB_ONE"));
  700. }
  701. else{
  702. $('.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}" href="javascript:;" data-href="${video_url}"><img width="100" src="${video_image}" /><br/>- ${_i18n("VID")} ${s} -</a>`);
  703. }
  704. */
  705. }
  706. if(element_images && imgLink){
  707. $('.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>`);
  708. }
  709. }
  710.  
  711.  
  712. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_BODY a').each(function(){
  713. $(this).wrap('<div></div>');
  714. $(this).before('<input class="inner_box" type="checkbox">');
  715. });
  716. });
  717.  
  718. // Add the mark that download is ready
  719. var username = $(this).find("header > div:last-child > div:first-child span > a").first().text();
  720.  
  721. $(this).attr('data-snig','canDownload');
  722. $(this).attr('data-username',username);
  723. }
  724. });
  725. }
  726.  
  727. // Create media element from blob media
  728. async function createMediaCacheDOM(postURL,selector,message){
  729. $(`${selector} a`).remove();
  730. $(selector).append('<p id="_SNLOAD">'+ message +'</p>');
  731. let media = await getBlobMedia(postURL);
  732. let idx = 1;
  733. let resource = media.shortcode_media;
  734.  
  735. // GraphVideo
  736. if(resource.__typename == "GraphVideo" && resource.video_url){
  737. $(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}" href="javascript:;" data-href="${resource.video_url}"><img width="100" src="${resource.display_resources[1].src}" /><br/>- ${_i18n("VID")} ${idx} -</a>`);
  738. idx++;
  739. }
  740. // GraphSidecar
  741. if(resource.__typename == "GraphSidecar" && resource.edge_sidecar_to_children){
  742. for(let e of resource.edge_sidecar_to_children.edges){
  743. if(e.node.__typename == "GraphVideo"){
  744. $(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}" href="javascript:;" data-href="${e.node.video_url}"><img width="100" src="${e.node.display_resources[1].src}" /><br/>- ${_i18n("VID")} ${idx} -</a>`);
  745. }
  746.  
  747. if(e.node.__typename == "GraphImage"){
  748. $(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}" 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>`);
  749. }
  750. idx++;
  751. }
  752. }
  753. $("#_SNLOAD").remove();
  754. }
  755.  
  756. // Create the download dialog element funcion
  757. function IG_createDM(hasHidden, hasCheckbox){
  758. let isHidden = (hasHidden)?"hidden":"";
  759. $('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>');
  760. $('.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;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>');
  761.  
  762. if(hasCheckbox){
  763. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_TITLE').append(`<label class="checkbox"><input value="yes" type="checkbox" />${_i18n('ALL_CHECK')}</label>`);
  764. $('.IG_SN_DIG .IG_SN_DIG_MAIN .IG_SN_DIG_TITLE').append(`<button id="batch_download">${_i18n('BATCH_DOWNLOAD')}</button>`);
  765. }
  766. }
  767.  
  768. // Download and rename files
  769. function saveFiles(downloadLink,username,index,timestamp,type,shortcode){
  770. fetch(downloadLink).then(res => {
  771. return res.blob().then(dwel => {
  772. const a = document.createElement("a");
  773. const name = username+'-'+index+'-'+((USER_SETTING.RENAME_SHORTCODE && shortcode)?shortcode+'-':'')+timestamp+'.'+type;
  774. const originally = username + '_' + downloadLink.split('/').at(-1).split('?').at(0);
  775.  
  776. a.href = URL.createObjectURL(dwel);
  777. a.setAttribute("download", (USER_SETTING.AUTO_RENAME)?name:originally);
  778. a.click();
  779. a.remove();
  780. });
  781. });
  782. }
  783.  
  784. // Supported language list
  785. function translateText(lang){
  786. return {
  787. "zh-TW": {
  788. "CLOSE": "關閉",
  789. "ALL_CHECK": "全選",
  790. "BATCH_DOWNLOAD": "批次下載",
  791. "IMG": "相片",
  792. "VID": "影片",
  793. "DDL": "快速下載",
  794. "DDL_INTRO": "勾選後將直接下載點選當下位置的相片/影片",
  795. "DW": "下載",
  796. "THUMBNAIL_INTRO": "下載影片縮圖",
  797. "LOAD_BLOB_ONE": "正在載入二進位大型物件...",
  798. "LOAD_BLOB_MULTIPLE": "正在載入多個二進位大型物件...",
  799. "LOAD_BLOB_RELOAD": "正在重新載入二進位大型物件...",
  800. "NO_VID_URL": "找不到影片網址",
  801. "SETTING": "設定",
  802. "AUTO_RENAME": "自動重新命名檔案",
  803. "RENAME_SHORTCODE": "重新命名檔案並包含 Shortcode",
  804. "DISABLE_VIDEO_LOOPING": "關閉影片自動循環播放",
  805. "REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE": "右鍵點擊使用者限時動態區域頭貼時重定向",
  806. "FORCE_FETCH_ALL_RESOURCES": "強制提取貼文中所有資源",
  807. "AUTO_RENAME_INTRO": "將檔案自動重新命名為以下格式:\n使用者名稱-類型-時間戳.檔案類型\n例如:instagram-photo-1670350000.jpg\n\n若設為 false,則檔案名稱將保持原始樣貌。 \n例如:instagram_321565527_679025940443063_4318007696887450953_n.jpg",
  808. "RENAME_SHORTCODE_INTRO": "將檔案自動重新命名為以下格式:\n使用者名稱-類型-Shortcode-時間戳.檔案類型\n示例:instagram-photo-CwkxyiVynpW-1670350000.jpg\n\n此功能僅在[自動重新命名檔案]設定為 TRUE 時有效。",
  809. "DISABLE_VIDEO_LOOPING_INTRO": "關閉連續短片和貼文中影片自動循環播放。",
  810. "REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE_INTRO": "右鍵點選首頁限時動態區域中的使用者頭貼時,重新導向到使用者的個人資料頁面。",
  811. "FORCE_FETCH_ALL_RESOURCES_INTRO": "透過 Instagram API 強制取得貼文中的所有資源(照片和影片),以取消每個貼文單次提取三個資源的限制。",
  812. },
  813. "zh-CN": {
  814. "CLOSE": "关闭",
  815. "ALL_CHECK": "全选",
  816. "BATCH_DOWNLOAD": "批量下载",
  817. "IMG": "图像",
  818. "VID": "视频",
  819. "DDL": "便捷下载",
  820. "DDL_INTRO": "勾选后将直接下载點擊當下位置的图像/视频",
  821. "DW": "下载",
  822. "THUMBNAIL_INTRO": "下载视频缩略图",
  823. "LOAD_BLOB_ONE": "正在载入大型媒体对象...",
  824. "LOAD_BLOB_MULTIPLE": "正在载入多个大型媒体对象...",
  825. "LOAD_BLOB_RELOAD": "正在重新载入大型媒体对象...",
  826. "NO_VID_URL": "找不到视频网址",
  827. "SETTING": "设置",
  828. "AUTO_RENAME": "自动重命名文件",
  829. "RENAME_SHORTCODE": "重命名文件并包含物件短码",
  830. "DISABLE_VIDEO_LOOPING": "禁用视频自动循环",
  831. "REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE": "右键单击用户故事区域头像时重定向",
  832. "FORCE_FETCH_ALL_RESOURCES": "强制抓取帖子中所有资源",
  833. "AUTO_RENAME_INTRO": "将文件自动重新命名为以下格式类型:\n用户名-类型-时间戳.文件类型\n例如:instagram-photo-1670350000.jpg\n\n若设为false,则文件名将保持原样。 \n例如:instagram_321565527_679025940443063_4318007696887450953_n.jpg",
  834. "RENAME_SHORTCODE_INTRO": "自动重命名文件为以下格式类型:\n用户名-类型-短码-时间戳.文件类型\n示例:instagram-photo-CwkxyiVynpW-1670350000.jpg\n\n它仅在[自动重命名文件]设置为 TRUE 时有效。",
  835. "DISABLE_VIDEO_LOOPING_INTRO": "禁用 Reels 和帖子中的视频自动播放。",
  836. "REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE_INTRO": "右键单击主页故事区域中的用户头像,重定向到用户的个人资料页面。",
  837. "FORCE_FETCH_ALL_RESOURCES_INTRO": "通过 Instagram API 强制获取帖子中的所有资源(照片和视频),以取消每个帖子单次抓取三个资源的限制。"
  838. },
  839. "en-US": {
  840. "CLOSE": "Close",
  841. "ALL_CHECK": "Select All",
  842. "BATCH_DOWNLOAD": "Batch-download",
  843. "IMG": "Image",
  844. "VID": "Video",
  845. "DDL": "Quick Download",
  846. "DDL_INTRO": "Checking it will direct download current photo/media in the posts.",
  847. "DW": "Download",
  848. "THUMBNAIL_INTRO": "Download video thumbnail.",
  849. "LOAD_BLOB_ONE": "Loading Blob Media...",
  850. "LOAD_BLOB_MULTIPLE": "Loading Blob Media and others...",
  851. "LOAD_BLOB_RELOAD": "Detect Blob Media, now reloading...",
  852. "NO_VID_URL": "Can not find video url.",
  853. "SETTING": "Settings",
  854. "AUTO_RENAME": "Automatically Rename Files",
  855. "RENAME_SHORTCODE": "Rename The File and Include Shortcode",
  856. "DISABLE_VIDEO_LOOPING": "Disable Video Auto-looping",
  857. "REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE": "Redirect When Right-Clicking User Story Picture",
  858. "FORCE_FETCH_ALL_RESOURCES": "Forcing Fetch All Resources In the Post",
  859. "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",
  860. "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.",
  861. "DISABLE_VIDEO_LOOPING_INTRO": "Disable video auto-looping in reels and posts.",
  862. "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.",
  863. "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."
  864. }
  865. };
  866. }
  867.  
  868. // Translate display text to user country
  869. function _i18n(text){
  870. let userLang = (lang)?lang:"en-US";
  871. let translate = {
  872. "zh-TW": function(){
  873. return translateText()["zh-TW"];
  874. },
  875. "zh-HK": function(){
  876. return translateText()["zh-TW"];
  877. },
  878. "zh-MO": function(){
  879. return translateText()["zh-TW"];
  880. },
  881. "zh-CN": function(){
  882. return translateText()["zh-CN"];
  883. },
  884. "en-US": function(){
  885. return translateText()["en-US"];
  886. }
  887. }
  888.  
  889. try{
  890. return translate[lang]()[text];
  891. }
  892. catch{
  893. return translate["en-US"]()[text];
  894. }
  895. }
  896.  
  897. function showSetting(){
  898. $('.IG_SN_DIG').remove();
  899. IG_createDM();
  900. $('.IG_SN_DIG #article-id').text('IG Helper Settings');
  901.  
  902. $('.IG_SN_DIG .IG_SN_DIG_BODY').append(`<label class="globalSettings" title="${_i18n('AUTO_RENAME_INTRO')}"><span>${_i18n('AUTO_RENAME')}</span> <input id="AUTO_RENAME" value="box" type="checkbox" ${(USER_SETTING.AUTO_RENAME)?'checked':''}><div class="chbtn"><div class="rounds"></div></div></label>`);
  903. $('.IG_SN_DIG .IG_SN_DIG_BODY').append(`<label class="globalSettings" title="${_i18n('RENAME_SHORTCODE_INTRO')}"><span>${_i18n('RENAME_SHORTCODE')}</span> <input id="RENAME_SHORTCODE" value="box" type="checkbox" ${(USER_SETTING.RENAME_SHORTCODE)?'checked':''}><div class="chbtn"><div class="rounds"></div></div></label>`);
  904. $('.IG_SN_DIG .IG_SN_DIG_BODY').append(`<label class="globalSettings" title="${_i18n('DISABLE_VIDEO_LOOPING_INTRO')}"><span>${_i18n('DISABLE_VIDEO_LOOPING')}</span> <input id="DISABLE_VIDEO_LOOPING" value="box" type="checkbox" ${(USER_SETTING.DISABLE_VIDEO_LOOPING)?'checked':''}><div class="chbtn"><div class="rounds"></div></div></label>`);
  905. $('.IG_SN_DIG .IG_SN_DIG_BODY').append(`<label class="globalSettings" title="${_i18n('REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE_INTRO')}"><span>${_i18n('REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE')}</span> <input id="REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE" value="box" type="checkbox" ${(USER_SETTING.REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE)?'checked':''}><div class="chbtn"><div class="rounds"></div></div></label>`);
  906. $('.IG_SN_DIG .IG_SN_DIG_BODY').append(`<label class="globalSettings" title="${_i18n('FORCE_FETCH_ALL_RESOURCES_INTRO')}"><span>${_i18n('FORCE_FETCH_ALL_RESOURCES')}</span> <input id="FORCE_FETCH_ALL_RESOURCES" value="box" type="checkbox" ${(USER_SETTING.FORCE_FETCH_ALL_RESOURCES)?'checked':''}><div class="chbtn"><div class="rounds"></div></div></label>`);
  907. }
  908.  
  909. // Running if document is ready
  910. $(function(){
  911. // Close the download dialog if user click the close icon
  912. $('body').on('click','.IG_SN_DIG_BTN,.IG_SN_DIG_BG',function(){
  913. $('.IG_SN_DIG').remove();
  914. });
  915.  
  916. $(window).keydown(function(e){
  917. // Hot key [Alt+Q] to close the download dialog
  918. if (e.keyCode == '81' && e.altKey){
  919. $('.IG_SN_DIG').remove();
  920. e.preventDefault();
  921. }
  922. // Hot key [Alt+W] to open the settings dialog
  923. if (e.keyCode == '87' && e.altKey){
  924. showSetting();
  925. e.preventDefault();
  926. }
  927. });
  928. $('body').on('click','.AutoDownload',function(){
  929. if($('.AutoDownload:checked').length){
  930. GM_setValue('AutoDownload',true);
  931. }
  932. else{
  933. GM_setValue('AutoDownload',false);
  934. }
  935. });
  936.  
  937. $('body').on('change', '.IG_SN_DIG input',function(){
  938. var isChecked = $(this).prop('checked');
  939. var name = $(this).attr('id');
  940.  
  941. GM_setValue(name, isChecked);
  942. USER_SETTING[name] = isChecked;
  943. });
  944.  
  945. $('body').on('click','a[data-needed="direct"]',async function(){
  946. let date = new Date().getTime();
  947. let timestamp = Math.floor(date / 1000);
  948. let username = ($(this).attr('data-username')) ? $(this).attr('data-username') : GL_username;
  949.  
  950. if(!username && $(this).attr('data-path')){
  951. console.log('catching owner name from shortcode:',$(this).attr('data-href'));
  952. username = await getPostOwner($(this).attr('data-path'));
  953. }
  954. saveFiles($(this).attr('data-href'),username,$(this).attr('data-name'),timestamp,$(this).attr('data-type'), $(this).attr('data-path'));
  955. });
  956.  
  957. // Running if user left-click download icon in stories
  958. $('body').on('click','.IG_DWSTORY',function(){
  959. onStoryDW(true);
  960. });
  961.  
  962. // Running if user left-click download icon in stories
  963. $('body').on('click','.IG_DWSTORY_THUMBNAIL',function(){
  964. onStoryThumbnailDW(true);
  965. });
  966.  
  967. // Running if user left-click download icon in profile
  968. $('body').on('click','.IG_DWPROFILE',function(e){
  969. e.stopPropagation();
  970. onProfileDW(true);
  971. });
  972.  
  973. // Running if user left-click download icon in highlight stories
  974. $('body').on('click','.IG_DWHISTORY',function(){
  975. onHighlightsStoryDW(true);
  976. });
  977.  
  978. // Running if user left-click download icon in highlight stories
  979. $('body').on('click','.IG_DWHISTORY_THUMBNAIL',function(){
  980. onHighlightsStoryThumbnailDW(true);
  981. });
  982.  
  983. // Running if user left-click download icon in reels
  984. $('body').on('click','.IG_REELS',function(){
  985. onReelsDW(true,true);
  986. });
  987.  
  988. // Running if user left-click download icon in reels
  989. $('body').on('click','.IG_REELS_THUMBNAIL',function(){
  990. onReelsDW(true,false);
  991. });
  992.  
  993. // Running if user right-click profile picture in stories area
  994. $('body').on('contextmenu','button[role="menuitem"]',function(){
  995. if(location.href === 'https://www.instagram.com/' && USER_SETTING.REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE){
  996. if($(this).find('canvas._aarh').length > 0){
  997. location.href = 'https://www.instagram.com/'+$(this).children('div').last().text();
  998. }
  999. }
  1000. });
  1001.  
  1002. $('body').on('change', '.IG_SN_DIG_TITLE .checkbox', function(){
  1003. var isChecked = $(this).find('input').prop('checked');
  1004. $('.IG_SN_DIG_BODY .inner_box').each(function(){
  1005. $(this).prop('checked', isChecked);
  1006. });
  1007. });
  1008.  
  1009. $('body').on('click', '.IG_SN_DIG_TITLE #batch_download', function(){
  1010. $('.IG_SN_DIG_BODY a[data-needed="direct"]').each(function(){
  1011. if($(this).prev().prop('checked')){
  1012. $(this).click();
  1013. }
  1014. });
  1015. });
  1016. });
  1017.  
  1018. GM_addStyle(`
  1019. .IG_SN_DIG{
  1020. position: fixed;
  1021. left: 0px;
  1022. right: 0px;
  1023. bottom: 0px;
  1024. top: 0px;
  1025. z-index: 500;
  1026. }
  1027. .IG_SN_DIG.hidden{
  1028. display:none;
  1029. }
  1030. .IG_SN_DIG_BG{
  1031. position: fixed;
  1032. left: 0px;
  1033. right: 0px;
  1034. bottom: 0px;
  1035. top: 0px;
  1036. z-index:502;
  1037. background: rgba(0,0,0,.75);
  1038. }
  1039. .IG_SN_DIG_MAIN{
  1040. z-index: 510;
  1041. padding:10px 15px;
  1042. top:7%;
  1043. position: absolute;
  1044. left: 50%;
  1045. transform: translateX(-50%);
  1046. width: 500px;
  1047. background:#fff;
  1048. background: rgb(var(--ig-secondary-background));
  1049. color: #000;
  1050. color: rgb(var(--ig-primary-text));
  1051. border-radius: 7px;
  1052. }
  1053. .IG_SN_DIG_BODY{
  1054. min-height: 100px;
  1055. max-height: 80vh;
  1056. overflow-y:auto;
  1057. }
  1058. .IG_SN_DIG_BODY a{
  1059. display:block;
  1060. margin:5px 0px;
  1061. padding:5px 0px;
  1062. color: #111;
  1063. color: rgb(var(--ig-primary-text));
  1064. font-size:1rem;
  1065. line-height:1rem;
  1066. text-align:center;
  1067. border:1px solid #000;
  1068. border:1px solid rgb(var(--ig-primary-text));
  1069. border-radius: 5px;
  1070. }
  1071. .SNKMS_IG_DW_MAIN{
  1072. position: absolute;
  1073. top:15px;
  1074. padding:6px;
  1075. line-height:1;
  1076. background:#fff;
  1077. border-radius: 50%;
  1078. cursor:pointer;
  1079. }
  1080. #_SNLOAD{
  1081. text-align:center;
  1082. font-size:20px;
  1083. }
  1084. .IG_REELS, .IG_DWSTORY, .IG_DWHISTORY{
  1085. position: absolute;
  1086. right:40px;
  1087. top:15px;
  1088. padding:5px;
  1089. line-height:1;
  1090. background:#fff;
  1091. border-radius: 5px;
  1092. cursor:pointer;
  1093. }
  1094.  
  1095. .IG_REELS_THUMBNAIL, .IG_DWSTORY_THUMBNAIL, .IG_DWHISTORY_THUMBNAIL{
  1096. position: absolute;
  1097. right:40px;
  1098. top:45px;
  1099. padding:5px;
  1100. line-height:1;
  1101. background:#fff;
  1102. border-radius: 5px;
  1103. cursor:pointer;
  1104. }
  1105. .IG_DWSTORY, .IG_DWHISTORY, .IG_DWSTORY_THUMBNAIL, .IG_DWHISTORY_THUMBNAIL{
  1106. right:-40px;
  1107. }
  1108. .IG_DWPROFILE{
  1109. position: absolute;
  1110. right:0px;
  1111. top:0px;
  1112. padding:5px;
  1113. line-height:1;
  1114. background:#fff;
  1115. border-radius: 50%;
  1116. cursor:pointer;
  1117. border: 1px solid #ccc
  1118. }
  1119. .globalSettings{
  1120. position:relative;
  1121. display:inline-block;
  1122. color: #000;
  1123. color: rgb(var(--ig-primary-text));
  1124. text-decoration:none;
  1125. text-align:left;
  1126. width:100%;
  1127. height:30px;
  1128. padding:5px;
  1129. line-height:18px;
  1130. font-size:18px;
  1131. box-sizing: border-box;
  1132. border-radius:5px;
  1133. vertical-align:middle;
  1134. outline:none;
  1135. cursor:pointer;
  1136. -ms-user-select: none;
  1137. -moz-user-select: none;
  1138. -webkit-user-select: none;
  1139. user-select: none;
  1140. margin: 5px 0px;
  1141. }
  1142. .globalSettings:hover{
  1143. background: #e7e7e7;
  1144. background: rgb(var(--ig-secondary-button-hover));
  1145. }
  1146. .globalSettings:hover > span{
  1147. cursor: help;
  1148. }
  1149. .globalSettings input {
  1150. display: none;
  1151. }
  1152. .globalSettings .chbtn {
  1153. width: 40px;
  1154. height: 15px;
  1155. background: #9c9c9c;
  1156. display: inline-block;
  1157. vertical-align: middle;
  1158. border-radius: 7px;
  1159. position: absolute;
  1160. right: 15px;
  1161. top: 7px;
  1162. transition: background 0.2s;
  1163. }
  1164. .globalSettings .chbtn .rounds {
  1165. width: 20px;
  1166. height: 20px;
  1167. background: #777;
  1168. display: inline-block;
  1169. vertical-align: middle;
  1170. border-radius: 50%;
  1171. position: absolute;
  1172. left: 0px;
  1173. top: -3px;
  1174. transition: left 0.15s,background 0.15s;
  1175. }
  1176. .globalSettings input:checked ~ .chbtn{
  1177. background: #004c5a;
  1178. }
  1179. .globalSettings input:checked ~ .chbtn .rounds{
  1180. left: 20px;
  1181. background: #048aa4;
  1182. }
  1183. .checkbox{
  1184. font-size: 18px;
  1185. vertical-align: middle;
  1186. margin: 0px 7px;
  1187. user-select: none;
  1188. margin-left: 0px;
  1189. }
  1190. .inner_box{
  1191. position: absolute;
  1192. top: 5px;
  1193. left: 5px;
  1194. transform: scale(1.5);
  1195. cursor: pointer;
  1196. }
  1197. .IG_SN_DIG_BODY > div{
  1198. position: relative;
  1199. }
  1200. .IG_SN_DIG_TITLE button{
  1201. font-size: 14px;
  1202. vertical-align: middle;
  1203. margin: 0px 7px;
  1204. }
  1205. `);
  1206. GM_registerMenuCommand(_i18n('SETTING'), () => {
  1207. showSetting();
  1208. });
  1209. })(jQuery);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址