IG小助手

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

当前为 2022-06-04 提交的版本,查看 最新版本

  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.3.4.5
  9. // @description Downloading Instagram posts photos and videos or their stories!
  10. // @description:zh-TW 一鍵下載對方 Instagram 貼文中的相片、影片甚至是他們的限時動態!
  11. // @description:zh-CN 一键下载对方 Instagram 帖子中的相片、视频甚至是他们的快拍!
  12. // @description:ja 写真、ビデオ、そしてお互いの Instagram 投稿からのストーリーずズのワンクリックダウンロード!
  13. // @description:ko Instagram 게시물에서 사진, 비디오 또는 이야기를 다운로드하십시오.
  14. // @author SN-Koarashi (5026)
  15. // @match https://*.instagram.com/*
  16. // @grant GM_setValue
  17. // @grant GM_getValue
  18. // @grant GM_xmlhttpRequest
  19. // @grant unsafeWindow
  20. // @require https://code.jquery.com/jquery-3.6.0.min.js
  21. // @supportURL https://www.facebook.com/smileopwe/
  22. // @compatible firefox >= 87
  23. // @compatible chrome >= 90
  24. // @compatible edge >= 90
  25. // @license GPLv3
  26. // ==/UserScript==
  27.  
  28. (function() {
  29. 'use strict';
  30. // Icon download by https://www.flaticon.com/authors/pixel-perfect
  31.  
  32. // Global variable
  33. GM_setValue('currnetURL',location.href);
  34.  
  35. const $ = window.jQuery;
  36. const checkInterval = 250;
  37.  
  38. var __additionalData = unsafeWindow.__additionalData;
  39. var currentURL = location.href;
  40. var currentHeight = $(document).height();
  41. var firstStarted = false;
  42. var pageLoaded = false;
  43.  
  44. // Main Timer
  45. var timer = setInterval(function(){
  46. currentHeight = $(document).height();
  47.  
  48. // Call Instagram dialog function if url changed.
  49. if(currentURL != location.href || GM_getValue('currnetURL') != location.href || !firstStarted || !pageLoaded){
  50. pageLoaded = false;
  51. firstStarted = true;
  52. currentURL = location.href;
  53. GM_setValue('currnetURL',location.href);
  54.  
  55. if($('div.sspdcydq[role="dialog"]').length){
  56. console.log('isDialog');
  57. onReadyMyDW(false);
  58. pageLoaded = true;
  59. }
  60.  
  61. if(location.href == "https://www.instagram.com/"){
  62. console.log('isHomepage');
  63. onReadyMyDW(false);
  64. pageLoaded = true;
  65. }
  66.  
  67. if(!pageLoaded){
  68. // Call Instagram stories function
  69. if(location.href.match(/^(https:\/\/www\.instagram\.com\/stories\/)/ig)){
  70. console.log('isStory');
  71. onStoryDW(false);
  72. onStoryThumbnailDW(false);
  73.  
  74. if($(".IG_DWSTORY").length) setTimeout(()=>{pageLoaded = true;},150);
  75. }
  76. else{
  77. pageLoaded = false;
  78. // Remove the download icon
  79. $('.IG_DWSTORY').remove();
  80. $('.IG_DWSTORY_THUMBNAIL').remove();
  81. }
  82. }
  83.  
  84. }
  85.  
  86. // Direct Download Checkbox
  87. if(!$('.AutoDownload_dom').length){
  88. let ckValue = (GM_getValue('AutoDownload'))?'checked':'';
  89. $('body ._acuq._acur').append('<div class="AutoDownload_dom" style="position: absolute;left:15px;top:0px;padding:6px;line-height:1;background:#fff;border-radius: 50%;"><label title="Checking it will direct download current photos in the posts." style="cursor:help;"><input type="checkbox" value="1" class="AutoDownload" name="AutoDownload" '+ckValue+' />DDL</label></div>');
  90. }
  91. },checkInterval);
  92.  
  93. // Call general function when user scroll the page
  94. $(document).scroll(function(){
  95. if(currentHeight != $(this).height()){
  96. onReadyMyDW();
  97. }
  98. });
  99.  
  100. // Stories funcion
  101. function onStoryDW(isDownload){
  102. if(isDownload){
  103. let date = new Date().getTime();
  104. let timestamp = Math.floor(date / 1000);
  105. let username = $("body > div section._ac0a header._ac0k ._ac0l div ._ac0q > a").text();
  106.  
  107. if($('body > div section._ac0a video._aa63').length){
  108. // Download stories if it is video
  109. let downloadLink = $('video._aa63 source').attr('src')+'&dl=1';
  110. let type = 'mp4';
  111.  
  112. saveFiles(downloadLink,username,"stories",timestamp,type);
  113. }
  114. else{
  115. // Download stories if it is image
  116. let srcset = $('section._ac0a ._aa64 img._aa63').attr('srcset').split(',')[0].split(' ')[0];
  117. let link = (srcset)?srcset:$('section._ac0a ._aa64 img._aa63').attr('src');
  118.  
  119. let downloadLink = link+'&dl=1';
  120. let type = 'jpg';
  121.  
  122. saveFiles(downloadLink,username,"stories",timestamp,type);
  123. }
  124. }
  125. else{
  126. // Add the stories download button
  127. let style = "position: absolute;right:-40px;top:15px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  128. if(!$('.IG_DWSTORY').length){
  129. $('body > div section._ac0a').append('<div title="Download" class="IG_DWSTORY" style="'+style+'"><svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"><g><g><path d="M382.56,233.376C379.968,227.648,374.272,224,368,224h-64V16c0-8.832-7.168-16-16-16h-64c-8.832,0-16,7.168-16,16v208h-64 c-6.272,0-11.968,3.68-14.56,9.376c-2.624,5.728-1.6,12.416,2.528,17.152l112,128c3.04,3.488,7.424,5.472,12.032,5.472 c4.608,0,8.992-2.016,12.032-5.472l112-128C384.192,245.824,385.152,239.104,382.56,233.376z"/></g></g><g><g><path d="M432,352v96H80v-96H16v128c0,17.696,14.336,32,32,32h416c17.696,0,32-14.304,32-32V352H432z"/></g></g></div>');
  130. return true;
  131. }
  132. }
  133. }
  134.  
  135. // Stories Thumbnail funcion
  136. function onStoryThumbnailDW(isDownload){
  137. if(isDownload){
  138. // Download stories if it is video
  139. let srcset = $('section._ac0a ._aa64 img._aa63').attr('srcset').split(',')[0].split(' ')[0];
  140. let downloadLink = (srcset)?srcset:$('section._ac0a ._aa64 img._aa63').attr('src');
  141.  
  142. let date = new Date().getTime();
  143. let timestamp = Math.floor(date / 1000);
  144. let type = 'jpg';
  145. let username = $("body > div section._ac0a header._ac0k ._ac0l div ._ac0q > a").text();
  146. 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;';
  147.  
  148. // Download thumbnail
  149. saveFiles(downloadLink,username,"thumbnail",timestamp,type);
  150. }
  151. else{
  152. if($('body > div section._ac0a video._aa63').length){
  153. // Add the stories download button
  154. let style = "position: absolute;right:-40px;top:45px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  155. if(!$('.IG_DWSTORY_THUMBNAIL').length){
  156. $('body > div section._ac0a').append('<div title="Download video thumbnail" class="IG_DWSTORY_THUMBNAIL" style="'+style+'"><svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="512" viewBox="0 0 24 24" width="512"><circle cx="8.25" cy="5.25" r=".5"/><path d="m8.25 6.5c-.689 0-1.25-.561-1.25-1.25s.561-1.25 1.25-1.25 1.25.561 1.25 1.25-.561 1.25-1.25 1.25zm0-1.5c-.138 0-.25.112-.25.25 0 .275.5.275.5 0 0-.138-.112-.25-.25-.25z"/><path d="m7.25 11.25 2-2.5 2.25 1.5 2.25-3.5 3 4.5z"/><path d="m16.75 12h-9.5c-.288 0-.551-.165-.676-.425s-.09-.568.09-.793l2-2.5c.243-.304.678-.372 1.002-.156l1.616 1.077 1.837-2.859c.137-.212.372-.342.625-.344.246-.026.49.123.63.334l3 4.5c.153.23.168.526.037.77-.13.244-.385.396-.661.396zm-4.519-1.5h3.118l-1.587-2.381zm-3.42 0h1.712l-1.117-.745z"/><path d="m22.25 14h-2.756c-.778 0-1.452.501-1.676 1.247l-.859 2.862c-.16.533-.641.891-1.197.891h-7.524c-.556 0-1.037-.358-1.197-.891l-.859-2.861c-.224-.747-.897-1.248-1.676-1.248h-2.756c-.965 0-1.75.785-1.75 1.75v5.5c0 1.517 1.233 2.75 2.75 2.75h18.5c1.517 0 2.75-1.233 2.75-2.75v-5.5c0-.965-.785-1.75-1.75-1.75z"/><path d="m4 12c-.552 0-1-.448-1-1v-8c0-1.654 1.346-3 3-3h12c1.654 0 3 1.346 3 3v8c0 .552-.448 1-1 1s-1-.448-1-1v-8c0-.551-.449-1-1-1h-12c-.551 0-1 .449-1 1v8c0 .552-.448 1-1 1z"/></svg></div>');
  157. }
  158. }
  159. else{
  160. $('.IG_DWSTORY_THUMBNAIL').remove();
  161. }
  162. }
  163. }
  164.  
  165. // Prepare promise to cache article which contains blob media
  166. function getBlobMedia(){
  167. return new Promise((resolve,reject)=>{
  168. if(!GM_getValue('postpath')) reject("NOPATH");
  169.  
  170. GM_xmlhttpRequest({
  171. method: "GET",
  172. url: "https://www.instagram.com"+GM_getValue('postpath'),
  173. onload: function(response) {
  174. let result = response.response;
  175. let mediaArr = [...result.matchAll(/<script type="text\/javascript">window\.__additionalDataLoaded\('(.*?)',(.*?)\);<\/script>/sg)];
  176. let resultJSON = JSON.parse(`${mediaArr[0][2]}`);
  177.  
  178. let media = resultJSON.items[0].carousel_media;
  179.  
  180. resolve((media)?media:resultJSON.items[0]);
  181. },
  182. onerror: function(err){
  183. reject(err);
  184. }
  185. });
  186. });
  187. }
  188.  
  189. // Main function
  190. function onReadyMyDW(NoDialog){
  191. // Whether is Instagram dialog?
  192. if(!NoDialog){
  193. // Running if it is dialog
  194. $('article[role="presentation"]').each(function(){
  195. $(this).removeAttr('data-snig');
  196. $(this).unbind('click');
  197. });
  198. $('.SNKMS_IG_DW_MAIN,.SNKMS_IG_DW_MAIN_VIDEO').remove();
  199. }
  200. if(NoDialog == false){
  201. var repeat = setInterval(() => {
  202. if($('article[role="presentation"]').length > 0) clearInterval(repeat);
  203. createArtBtn();
  204. },250);
  205. }
  206. else{
  207. createArtBtn();
  208. }
  209. }
  210.  
  211. function createArtBtn(){
  212. // Add download icon per each posts
  213. $('article[role="presentation"]').each(function(){
  214. // If it is have not download icon
  215. if(!$(this).attr('data-snig')){
  216. console.log("Found article");
  217. var style = "position: absolute;right:15px;top:15px;padding:6px;line-height:1;background:#fff;border-radius: 50%;cursor:pointer;";
  218.  
  219. // Add the download icon
  220. $(this).find("div._aatk").append('<div title="Download" class="SNKMS_IG_DW_MAIN" style="'+style+'"><svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"><g><g><path d="M382.56,233.376C379.968,227.648,374.272,224,368,224h-64V16c0-8.832-7.168-16-16-16h-64c-8.832,0-16,7.168-16,16v208h-64 c-6.272,0-11.968,3.68-14.56,9.376c-2.624,5.728-1.6,12.416,2.528,17.152l112,128c3.04,3.488,7.424,5.472,12.032,5.472 c4.608,0,8.992-2.016,12.032-5.472l112-128C384.192,245.824,385.152,239.104,382.56,233.376z"/></g></g><g><g><path d="M432,352v96H80v-96H16v128c0,17.696,14.336,32,32,32h416c17.696,0,32-14.304,32-32V352H432z"/></g></g></div>');
  221.  
  222. // Running if user click the download icon
  223. $(this).on('click','.SNKMS_IG_DW_MAIN', async function(e){
  224. GM_setValue('username',$(this).parent().parent().parent().attr('data-username'));
  225. GM_setValue('postpath',$(this).parent().parent().parent().find("._ab8w div._aast ._aat8 a").attr("href"));
  226.  
  227. // Create element that download dailog
  228. IG_createDM(GM_getValue('AutoDownload'));
  229.  
  230. var style = 'display:block;margin:5px 0px;padding:5px 0px;color:#111;font-size:1rem;line-height:1rem;text-align:center;border:1px solid #000;border-radius: 5px;';
  231.  
  232. // Find video/image element and add the download icon
  233. var s = 0;
  234. var multiple = $(this).parent().parent().find('._aap0 ._acaz').length;
  235. var pathname = window.location.pathname;
  236. var fullpathname = "/"+pathname.split('/')[1]+"/"+pathname.split('/')[2]+"/";
  237.  
  238. // If posts have more than one images or videos.
  239. if(multiple){
  240. var blob = false;
  241. $(this).parent().parent().find('._aap0 ._acaz').each(function(){
  242. let element_videos = $(this).parent().parent().find('video.tWeCl');
  243. if(element_videos && element_videos.attr('src') && element_videos.attr('src').match(/^blob:/ig)){
  244. blob = true;
  245. }
  246. });
  247.  
  248.  
  249. if(blob){
  250. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<p style="text-align:center;font-size:20px;" id="_SNLOAD">Loading Blob Media and others...</p>');
  251. let media = await getBlobMedia();
  252. var idx = 1;
  253. media.forEach(e => {
  254. if(e.media_type == 2){ // Videos
  255. let element_videos = e.video_versions[0].url.replace(new RegExp(`^(https://instagram.ftpe8-2.fna.fbcdn.net/v/)`,"ig"),'https://scontent.cdninstagram.com/v/');
  256. let element_images = e.image_versions2.candidates[0].url;
  257. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-needed="direct" data-name="video" data-type="mp4" data-globalIndex="'+s+'" style="'+style+'" href="javascript:;" data-href="'+element_videos+'"><img width="100" src="'+element_images+'" /><br/>- Video '+idx+' -</a>');
  258. }
  259. else{ // Images
  260. let element_images = e.image_versions2.candidates[0].url;
  261. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-needed="direct" data-type="jpg" data-name="photo" data-globalIndex="'+idx+'" style="'+style+'" href="javascript:;" data-href="'+element_images+'"><img width="100" src="'+element_images+'" /><br/>- Image '+idx+' -</a>');
  262. }
  263. idx++;
  264. });
  265.  
  266. $("#_SNLOAD").remove();
  267. }
  268. else{
  269. $(this).parent().find('._aap0 ._acaz').each(function(){
  270. s++;
  271. let element_videos = $(this).find('video._ab1d');
  272. let element_images = $(this).find('._aagv img');
  273. let imgLink = (element_images.attr('srcset'))?element_images.attr('srcset').split(" ")[0]:element_images.attr('src');
  274.  
  275. if(element_videos && element_videos.attr('src')){
  276. let video_image = element_videos.attr('poster');
  277. let video_url = element_videos.attr('src');
  278.  
  279. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-needed="direct" data-name="IGTV" data-type="mp4" data-globalIndex="'+s+'" style="'+style+'" href="javascript:;" data-href="'+video_url+'"><img width="100" src="'+video_image+'" /><br/>- Videos '+s+' -</a>');
  280. }
  281. if(element_images && imgLink){
  282. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-needed="direct" data-name="photo" data-type="jpg" data-globalIndex="'+s+'" style="'+style+'" href="javascript:;" data-href="'+imgLink+'"><img width="100" src="'+imgLink+'" /><br/>- Image '+s+' -</a>');
  283. }
  284. });
  285. }
  286. }
  287. else{
  288. s++;
  289. let element_videos = $(this).parent().parent().find('video._ab1d');
  290. let element_images = $(this).parent().parent().find('._aagv img');
  291. let imgLink = (element_images.attr('srcset'))?element_images.attr('srcset').split(" ")[0]:element_images.attr('src');
  292.  
  293.  
  294. if(element_videos && element_videos.attr('src')){
  295. let video_image = element_videos.attr('poster');
  296. let video_url = element_videos.attr('src');
  297.  
  298. if(element_videos.attr('src').match(/^blob:/ig)){
  299. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<p style="text-align:center;font-size:20px;" id="_SNLOAD">Loading Blob Media...</p>');
  300. let media = await getBlobMedia();
  301. let element_videos = media.video_versions[0].url.replace(new RegExp(`^(https://instagram.ftpe8-2.fna.fbcdn.net/v/)`,"ig"),'https://scontent.cdninstagram.com/v/');
  302. let element_images = media.image_versions2.candidates[0].url;
  303. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-needed="direct" data-name="video" data-type="mp4" data-globalIndex="'+s+'" style="'+style+'" href="javascript:;" data-href="'+element_videos+'"><img width="100" src="'+element_images+'" /><br/>- Video 1 -</a>');
  304.  
  305. $("#_SNLOAD").remove();
  306. }
  307. else{
  308. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-needed="direct" data-name="video" data-type="mp4" data-globalIndex="'+s+'" style="'+style+'" href="javascript:;" data-href="'+video_url+'"><img width="100" src="'+video_image+'" /><br/>- Video '+s+' -</a>');
  309. }
  310. }
  311. if(element_images && imgLink){
  312. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-needed="direct" data-name="photo" data-type="jpg" data-globalIndex="'+s+'" style="'+style+'" href="javascript:;" href="" data-href="'+imgLink+'"><img width="100" src="'+imgLink+'" /><br/>- Image '+s+' -</a>');
  313. }
  314. }
  315.  
  316.  
  317. if(GM_getValue('AutoDownload')){
  318. var autoTimer = setInterval(()=>{
  319. if($('a[data-type]').length > 0){
  320. GM_setValue('GB_Index',1);
  321.  
  322. if(!$('a[data-blob="true"]').length){
  323. let selectionArr = [...$(this).parent().find('._aamk').children('._acnb')];
  324.  
  325. let LeftButton = $(this).parent().parent().find('button._aahh').length;
  326. let RightButton = $(this).parent().parent().find('button._aahi').length;
  327.  
  328. if(LeftButton && !RightButton){ // Left Only
  329. GM_setValue('GB_Index',2);
  330. console.log('Left Only');
  331. }
  332. else if(!LeftButton && RightButton){ // Right Only
  333. GM_setValue('GB_Index',1);
  334. console.log('Right Only');
  335. }
  336. else if(!LeftButton && !RightButton){ // Both Not Exist
  337. GM_setValue('GB_Index',1);
  338. console.log('Both Not Exist');
  339. }
  340. else{ // Both Exist
  341. GM_setValue('GB_Index',2);
  342. console.log('Both Exist');
  343. }
  344. }
  345. else{
  346. console.log('Blob Media');
  347. let selectionArr = [...$(this).parent().find('._aamk').children('._acnb')];
  348. let idx = 0;
  349. for(let element of selectionArr){
  350. idx++;
  351. if($(element).attr('class').match(/_acnf/g)){
  352. GM_setValue('GB_Index',idx);
  353. }
  354. }
  355. }
  356.  
  357.  
  358. let downloadLink = $('.IG_SN_DIG').find('a[data-globalindex="'+GM_getValue('GB_Index')+'"]').attr('data-href');
  359. let date = new Date().getTime();
  360. let timestamp = Math.floor(date / 1000);
  361. let type = $('.IG_SN_DIG').find('a[data-globalindex="'+GM_getValue('GB_Index')+'"]').attr('data-type');
  362. let name = $('.IG_SN_DIG').find('a[data-globalindex="'+GM_getValue('GB_Index')+'"]').attr('data-name');
  363. console.log(GM_getValue('GB_Index'));
  364. saveFiles(downloadLink,GM_getValue('username'),name,timestamp,type);
  365. $('.IG_SN_DIG').remove();
  366. clearInterval(autoTimer);
  367. }
  368. },500);
  369. /*
  370. GM_setValue('GB_Index',0);
  371. let LeftButton = $(this).parent().parent().find('button._aahh').length;
  372. let RightButton = $(this).parent().parent().find('button._aahi').length;
  373.  
  374. if(LeftButton && !RightButton){ // Far Right
  375. GM_setValue('GB_Index',2);
  376. }
  377. else if(!LeftButton && RightButton){ // Far Left
  378. GM_setValue('GB_Index',1);
  379. }
  380. else if(!LeftButton && !RightButton){ // Both Not Exist
  381. GM_setValue('GB_Index',1);
  382. }
  383. else{ // Both Exist
  384. GM_setValue('GB_Index',2);
  385. }
  386.  
  387.  
  388. let downloadLink = $('.IG_SN_DIG').find('a[data-globalindex="'+GM_getValue('GB_Index')+'"]').attr('data-href');
  389. let date = new Date().getTime();
  390. let timestamp = Math.floor(date / 1000);
  391. let type = $('.IG_SN_DIG').find('a[data-globalindex="'+GM_getValue('GB_Index')+'"]').attr('data-type');
  392.  
  393. saveFiles(downloadLink,GM_getValue('username'),GM_getValue('GB_Index'),timestamp,type);
  394. $('.IG_SN_DIG').remove();
  395. */
  396. }
  397. });
  398.  
  399. // Add the mark that download is ready
  400. var username = $(this).find("._aasi header._aaqw span > a").text();
  401.  
  402. $(this).attr('data-snig','canDownload');
  403. $(this).attr('data-username',(username)?username:$(this).find("._aasi header._aaqw span > a").text());
  404. }
  405. });
  406. }
  407.  
  408. // Download and rename files
  409. function saveFiles(downloadLink,username,index,timestamp,type){
  410. fetch(downloadLink).then(res => {
  411. return res.blob().then(dwel => {
  412. const a = document.createElement("a");
  413. const name = username+'-'+index+'-'+timestamp+'.'+type;
  414. a.href = URL.createObjectURL(dwel);
  415. a.setAttribute("download", name);
  416. a.click();
  417. a.remove();
  418. });
  419. });
  420. }
  421.  
  422. // Create the download dialog element funcion
  423. function IG_createDM(a){
  424. let style = (!a)?"position: fixed;left: 0px;right: 0px;bottom: 0px;top: 0px;":"display:none;";
  425. $('body').append('<div class="IG_SN_DIG" style="'+style+';z-index: 500;"><div class="IG_SN_DIG_BG" style="'+style+'z-index:502;background: rgba(0,0,0,.75);"></div><div class="IG_SN_DIG_MAIN" style="z-index: 510;padding:10px 15px;top:7%;position: absolute;left: 50%;transform: translateX(-50%);width: 500px;min-height: 200px;max-height: 550px;overflow-y:auto;background:#fff;border-radius: 15px;"></div></div>');
  426. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<div style="position:relative;height:36px;line-height:36px;">Alt+Q [Close]<svg width="26" height="26" class="IG_SN_DIG_BTN" style="cursor:pointer;position:absolute;right:0px;" xmlns="http://www.w3.org/2000/svg" id="bold" enable-background="new 0 0 24 24" height="512" viewBox="0 0 24 24" width="512"><path d="m14.828 12 5.303-5.303c.586-.586.586-1.536 0-2.121l-.707-.707c-.586-.586-1.536-.586-2.121 0l-5.303 5.303-5.303-5.304c-.586-.586-1.536-.586-2.121 0l-.708.707c-.586.586-.586 1.536 0 2.121l5.304 5.304-5.303 5.303c-.586.586-.586 1.536 0 2.121l.707.707c.586.586 1.536.586 2.121 0l5.303-5.303 5.303 5.303c.586.586 1.536.586 2.121 0l.707-.707c.586-.586.586-1.536 0-2.121z"/></svg></div>');
  427. }
  428.  
  429. // Running if document is ready
  430. $(function(){
  431. // Ready~? GO!!
  432. onReadyMyDW();
  433.  
  434. // Close the download dialog if user click the close icon
  435. $('body').on('click','.IG_SN_DIG_BTN,.IG_SN_DIG_BG',function(){
  436. $('.IG_SN_DIG').remove();
  437. });
  438.  
  439. // Hot key [Alt+Q] to close the download dialog
  440. $(window).keydown(function(e){
  441. if (e.keyCode == '81' && e.altKey){
  442. $('.IG_SN_DIG').remove();
  443. e.preventDefault();
  444. }
  445. });
  446. $('body').on('click','.AutoDownload',function(){
  447. if($('.AutoDownload:checked').length){
  448. GM_setValue('AutoDownload',true);
  449. }
  450. else{
  451. GM_setValue('AutoDownload',false);
  452. }
  453. });
  454.  
  455. $('body').on('click','a[data-needed="direct"]',function(){
  456. let date = new Date().getTime();
  457. let timestamp = Math.floor(date / 1000);
  458. saveFiles($(this).attr('data-href'),GM_getValue('username'),$(this).attr('data-name'),timestamp,$(this).attr('data-type'));
  459. });
  460.  
  461. // Running if user left-click download icon in stories
  462. $('body').on('click','.IG_DWSTORY',function(){
  463. onStoryDW(true);
  464. });
  465.  
  466. // Running if user left-click download icon in stories
  467. $('body').on('click','.IG_DWSTORY_THUMBNAIL',function(){
  468. onStoryThumbnailDW(true);
  469. });
  470. });
  471.  
  472. })();