IG小助手

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

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

  1. // ==UserScript==
  2. // @name IG Helper
  3. // @name:zh-TW IG小精靈
  4. // @name:zh-CN IG小助手
  5. // @name:ja IG助手
  6. // @name:ko IG조수
  7. // @namespace https://github.snkms.com/
  8. // @version 2.3.6.1
  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. // @require https://code.jquery.com/jquery-3.6.0.min.js
  20. // @supportURL https://www.facebook.com/smileopwe/
  21. // @icon https://www.google.com/s2/favicons?domain=instagram.com
  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. const $ = window.jQuery;
  33. const checkInterval = 250;
  34.  
  35. var currentURL = location.href;
  36. var currentHeight = $(document).height();
  37. var firstStarted = false;
  38. var pageLoaded = false;
  39.  
  40. var GL_postPath;
  41. var GL_username;
  42.  
  43. // Main Timer
  44. var timer = setInterval(function(){
  45. currentHeight = $(document).height();
  46.  
  47. // Call Instagram dialog function if url changed.
  48. if(currentURL != location.href || !firstStarted || !pageLoaded){
  49. pageLoaded = false;
  50. firstStarted = true;
  51. currentURL = location.href;
  52.  
  53. if($('div.sspdcydq[role="dialog"]').length || $('main._a993[role="main"]').length){
  54. console.log('isDialog');
  55. setTimeout(()=>{
  56. onReadyMyDW(false);
  57. },150);
  58. pageLoaded = true;
  59. }
  60.  
  61. if(location.href == "https://www.instagram.com/"){
  62. console.log('isHomepage');
  63. setTimeout(()=>{
  64. onReadyMyDW(false);
  65. },150);
  66. pageLoaded = true;
  67. }
  68.  
  69. if(!pageLoaded){
  70. // Call Instagram stories function
  71. if(location.href.match(/^(https:\/\/www\.instagram\.com\/stories\/)/ig)){
  72. console.log('isStory');
  73. onStoryDW(false);
  74. onStoryThumbnailDW(false);
  75.  
  76. if($(".IG_DWSTORY").length) setTimeout(()=>{pageLoaded = true;},150);
  77. }
  78. else{
  79. pageLoaded = false;
  80. // Remove the download icon
  81. $('.IG_DWSTORY').remove();
  82. $('.IG_DWSTORY_THUMBNAIL').remove();
  83. }
  84. }
  85.  
  86. }
  87.  
  88. // Direct Download Checkbox
  89. if(!$('.AutoDownload_dom').length){
  90. let ckValue = (GM_getValue('AutoDownload'))?'checked':'';
  91. $('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>');
  92. }
  93. },checkInterval);
  94.  
  95. // Call general function when user scroll the page
  96. $(document).scroll(function(){
  97. if(currentHeight != $(this).height()){
  98. onReadyMyDW();
  99. }
  100. });
  101.  
  102. // Stories funcion
  103. function onStoryDW(isDownload){
  104. if(isDownload){
  105. let date = new Date().getTime();
  106. let timestamp = Math.floor(date / 1000);
  107. let username = $("body > div section._ac0a header._ac0k ._ac0l div ._ac0q > a").text();
  108.  
  109. if($('body > div section._ac0a video._aa63').length){
  110. // Download stories if it is video
  111. let downloadLink = $('video._aa63 source').attr('src')+'&dl=1';
  112. let type = 'mp4';
  113.  
  114. saveFiles(downloadLink,username,"stories",timestamp,type);
  115. }
  116. else{
  117. // Download stories if it is image
  118. let srcset = $('section._ac0a ._aa64 img._aa63').attr('srcset').split(',')[0].split(' ')[0];
  119. let link = (srcset)?srcset:$('section._ac0a ._aa64 img._aa63').attr('src');
  120.  
  121. let downloadLink = link+'&dl=1';
  122. let type = 'jpg';
  123.  
  124. saveFiles(downloadLink,username,"stories",timestamp,type);
  125. }
  126. }
  127. else{
  128. // Add the stories download button
  129. let style = "position: absolute;right:-40px;top:15px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  130. if(!$('.IG_DWSTORY').length){
  131. $('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>');
  132. return true;
  133. }
  134. }
  135. }
  136.  
  137. // Stories Thumbnail funcion
  138. function onStoryThumbnailDW(isDownload){
  139. if(isDownload){
  140. // Download stories if it is video
  141. let srcset = $('section._ac0a ._aa64 img._aa63').attr('srcset').split(',')[0].split(' ')[0];
  142. let downloadLink = (srcset)?srcset:$('section._ac0a ._aa64 img._aa63').attr('src');
  143.  
  144. let date = new Date().getTime();
  145. let timestamp = Math.floor(date / 1000);
  146. let type = 'jpg';
  147. let username = $("body > div section._ac0a header._ac0k ._ac0l div ._ac0q > a").text();
  148. 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;';
  149.  
  150. // Download thumbnail
  151. saveFiles(downloadLink,username,"thumbnail",timestamp,type);
  152. }
  153. else{
  154. if($('body > div section._ac0a video._aa63').length){
  155. // Add the stories download button
  156. let style = "position: absolute;right:-40px;top:45px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
  157. if(!$('.IG_DWSTORY_THUMBNAIL').length){
  158. $('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>');
  159. }
  160. }
  161. else{
  162. $('.IG_DWSTORY_THUMBNAIL').remove();
  163. }
  164. }
  165. }
  166.  
  167. // Prepare promise to cache article which contains blob media
  168. function getBlobMedia(postPath){
  169. return new Promise((resolve,reject)=>{
  170. if(!postPath) reject("NOPATH");
  171. let postShortCode = postPath.substring(3, postPath.length - 1);
  172. let getURL = `https://www.instagram.com/graphql/query/?query_hash=2c4c2e343a8f64c625ba02b2aa12c7f8&variables=%7B%22shortcode%22:%22${postShortCode}%22}`;
  173.  
  174. GM_xmlhttpRequest({
  175. method: "GET",
  176. url: getURL,
  177. onload: function(response) {
  178. let obj = JSON.parse(response.response);
  179. resolve(obj.data);
  180. },
  181. onerror: function(err){
  182. reject(err);
  183. }
  184. });
  185. });
  186. }
  187.  
  188. // Main function
  189. function onReadyMyDW(NoDialog){
  190. // Whether is Instagram dialog?
  191. if(!NoDialog){
  192. // Running if it is dialog
  193. $('article[role="presentation"]').each(function(){
  194. $(this).removeAttr('data-snig');
  195. $(this).unbind('click');
  196. });
  197. $('.SNKMS_IG_DW_MAIN,.SNKMS_IG_DW_MAIN_VIDEO').remove();
  198. }
  199. if(NoDialog == false){
  200. var repeat = setInterval(() => {
  201. if($('article[data-snig="canDownload"]').length > 0) clearInterval(repeat);
  202. createArtBtn();
  203. },250);
  204. }
  205. else{
  206. createArtBtn();
  207. }
  208. }
  209.  
  210. function createArtBtn(){
  211. // Add download icon per each posts
  212. $('article[role="presentation"]').each(function(){
  213. // If it is have not download icon
  214. if(!$(this).attr('data-snig')){
  215. console.log("Found article");
  216. var style = "position: absolute;right:15px;top:15px;padding:6px;line-height:1;background:#fff;border-radius: 50%;cursor:pointer;";
  217.  
  218. // Add the download icon
  219. $(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>');
  220.  
  221. // Running if user click the download icon
  222. $(this).on('click','.SNKMS_IG_DW_MAIN', async function(e){
  223. GL_username = $(this).parent().parent().parent().attr('data-username');
  224. GL_postPath = $(this).parent().parent().parent().find("._ab8w div._aast ._aat8 a").attr("href");
  225.  
  226. // Create element that download dailog
  227. IG_createDM(GM_getValue('AutoDownload'));
  228.  
  229. 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;';
  230.  
  231. // Find video/image element and add the download icon
  232. var s = 0;
  233. var multiple = $(this).parent().parent().find('._aap0 ._acaz').length;
  234. var pathname = window.location.pathname;
  235. var fullpathname = "/"+pathname.split('/')[1]+"/"+pathname.split('/')[2]+"/";
  236.  
  237. // If posts have more than one images or videos.
  238. if(multiple){
  239. var blob = false;
  240. $(this).parent().parent().find('._aap0 ._acaz').each(function(){
  241. let element_videos = $(this).parent().parent().find('video._ab1d');
  242. if(element_videos && element_videos.attr('src') && element_videos.attr('src').match(/^blob:/ig)){
  243. blob = true;
  244. }
  245. });
  246.  
  247.  
  248. if(blob){
  249. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<p style="text-align:center;font-size:20px;" id="_SNLOAD">Loading Blob Media and others...</p>');
  250. let media = await getBlobMedia(GL_postPath);
  251. let idx = 1;
  252. let resource = media.shortcode_media;
  253.  
  254. // GraphVideo
  255. if(resource.__typename == "GraphVideo" && resource.video_url){
  256. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-blob="true" data-needed="direct" data-name="video" data-type="mp4" data-globalIndex="'+idx+'" style="'+style+'" href="javascript:;" data-href="'+resource.video_url+'"><img width="100" src="'+resource.display_resources[1].src+'" /><br/>- Video '+idx+' -</a>');
  257. idx++;
  258. }
  259. // GraphSidecar
  260. if(resource.__typename == "GraphSidecar" && resource.edge_sidecar_to_children){
  261.  
  262. for(let e of resource.edge_sidecar_to_children.edges){
  263. if(e.node.__typename == "GraphVideo"){
  264. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-blob="true" data-needed="direct" data-name="video" data-type="mp4" data-globalIndex="'+idx+'" style="'+style+'" href="javascript:;" data-href="'+e.node.video_url+'"><img width="100" src="'+e.node.display_resources[1].src+'" /><br/>- Video '+idx+' -</a>');
  265. }
  266.  
  267. if(e.node.__typename == "GraphImage"){
  268. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-blob="true" data-needed="direct" data-name="photo" data-type="jpg" data-globalIndex="'+idx+'" style="'+style+'" href="javascript:;" data-href="'+e.node.display_resources[e.node.display_resources.length - 1].src+'"><img width="100" src="'+e.node.display_resources[1].src+'" /><br/>- Image '+idx+' -</a>');
  269. }
  270. idx++;
  271. }
  272. }
  273.  
  274. $("#_SNLOAD").remove();
  275. }
  276. else{
  277. $(this).parent().find('._aap0 ._acaz').each(function(){
  278. s++;
  279. let element_videos = $(this).find('video._ab1d');
  280. let element_images = $(this).find('._aagv img');
  281. let imgLink = (element_images.attr('srcset'))?element_images.attr('srcset').split(" ")[0]:element_images.attr('src');
  282.  
  283. if(element_videos && element_videos.attr('src')){
  284. let video_image = element_videos.attr('poster');
  285. let video_url = element_videos.attr('src');
  286.  
  287. $('.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>');
  288. }
  289. if(element_images && imgLink){
  290. $('.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>');
  291. }
  292. });
  293. }
  294. }
  295. else{
  296. s++;
  297. let element_videos = $(this).parent().parent().find('video._ab1d');
  298. let element_images = $(this).parent().parent().find('._aagv img');
  299. let imgLink = (element_images.attr('srcset'))?element_images.attr('srcset').split(" ")[0]:element_images.attr('src');
  300.  
  301.  
  302. if(element_videos && element_videos.attr('src')){
  303. let video_image = element_videos.attr('poster');
  304. let video_url = element_videos.attr('src');
  305.  
  306. if(element_videos.attr('src').match(/^blob:/ig)){
  307. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<p style="text-align:center;font-size:20px;" id="_SNLOAD">Loading Blob Media...</p>');
  308.  
  309. let media = await getBlobMedia(GL_postPath);
  310. let idx = 1;
  311. let resource = media.shortcode_media;
  312.  
  313. // GraphVideo
  314. if(resource.__typename == "GraphVideo" && resource.video_url){
  315. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-blob="true" data-needed="direct" data-name="video" data-type="mp4" data-globalIndex="'+idx+'" style="'+style+'" href="javascript:;" data-href="'+resource.video_url+'"><img width="100" src="'+resource.display_resources[1].src+'" /><br/>- Video '+idx+' -</a>');
  316. idx++;
  317. }
  318. // GraphSidecar
  319. if(resource.__typename == "GraphSidecar" && resource.edge_sidecar_to_children){
  320.  
  321. for(let e of resource.edge_sidecar_to_children.edges){
  322. if(e.node.__typename == "GraphVideo"){
  323. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-blob="true" data-needed="direct" data-name="video" data-type="mp4" data-globalIndex="'+idx+'" style="'+style+'" href="javascript:;" data-href="'+e.node.video_url+'"><img width="100" src="'+e.node.display_resources[1].src+'" /><br/>- Video '+idx+' -</a>');
  324. }
  325.  
  326. if(e.node.__typename == "GraphImage"){
  327. $('.IG_SN_DIG .IG_SN_DIG_MAIN').append('<a data-blob="true" data-needed="direct" data-name="photo" data-type="jpg" data-globalIndex="'+idx+'" style="'+style+'" href="javascript:;" data-href="'+e.node.display_resources[e.node.display_resources.length - 1].src+'"><img width="100" src="'+e.node.display_resources[1].src+'" /><br/>- Image '+idx+' -</a>');
  328. }
  329. idx++;
  330. }
  331. }
  332.  
  333. $("#_SNLOAD").remove();
  334. }
  335. else{
  336. $('.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>');
  337. }
  338. }
  339. if(element_images && imgLink){
  340. $('.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>');
  341. }
  342. }
  343.  
  344.  
  345. if(GM_getValue('AutoDownload')){
  346. var autoTimer = setInterval(()=>{
  347. if($('a[data-type]').length > 0){
  348. var GB_Index = 1;
  349.  
  350. if(!$('a[data-blob="true"]').length){
  351. let selectionArr = [...$(this).parent().find('._aamk').children('._acnb')];
  352.  
  353. let LeftButton = $(this).parent().parent().find('button._aahh').length;
  354. let RightButton = $(this).parent().parent().find('button._aahi').length;
  355.  
  356. if(LeftButton && !RightButton){ // Left Only
  357. GB_Index = 2;
  358. console.log('Left Only');
  359. }
  360. else if(!LeftButton && RightButton){ // Right Only
  361. GB_Index = 1;
  362. console.log('Right Only');
  363. }
  364. else if(!LeftButton && !RightButton){ // Both Not Exist
  365. GB_Index = 1;
  366. console.log('Both Not Exist');
  367. }
  368. else{ // Both Exist
  369. GB_Index = 2;
  370. console.log('Both Exist');
  371. }
  372. }
  373. else{
  374. console.log('Blob Media');
  375. let selectionArr = ($(this).parent().find('._aamk').children('._acnb').length)?[...$(this).parent().find('._aamk').children('._acnb')]:[...$(this).parent().find('._aamj').children('._acnb')];
  376. let idx = 0;
  377.  
  378. for(let element of selectionArr){
  379. idx++;
  380. if($(element).attr('class').match(/_acnf/g)){
  381. GB_Index = idx;
  382. }
  383. }
  384. }
  385.  
  386. let downloadLink = $('.IG_SN_DIG').find('a[data-globalindex="'+GB_Index+'"]').attr('data-href');
  387. let date = new Date().getTime();
  388. let timestamp = Math.floor(date / 1000);
  389. let type = $('.IG_SN_DIG').find('a[data-globalindex="'+GB_Index+'"]').attr('data-type');
  390. let name = $('.IG_SN_DIG').find('a[data-globalindex="'+GB_Index+'"]').attr('data-name');
  391.  
  392. saveFiles(downloadLink,GL_username,name,timestamp,type);
  393. $('.IG_SN_DIG').remove();
  394. clearInterval(autoTimer);
  395. }
  396. },500);
  397. }
  398. });
  399.  
  400. // Add the mark that download is ready
  401. var username = $(this).find("._aasi header._aaqw span > a").text();
  402.  
  403. $(this).attr('data-snig','canDownload');
  404. $(this).attr('data-username',(username)?username:$(this).find("._aasi header._aaqw span > a").text());
  405. }
  406. });
  407. }
  408.  
  409. // Download and rename files
  410. function saveFiles(downloadLink,username,index,timestamp,type){
  411. fetch(downloadLink).then(res => {
  412. return res.blob().then(dwel => {
  413. const a = document.createElement("a");
  414. const name = username+'-'+index+'-'+timestamp+'.'+type;
  415. a.href = URL.createObjectURL(dwel);
  416. a.setAttribute("download", name);
  417. a.click();
  418. a.remove();
  419. });
  420. });
  421. }
  422.  
  423. // Create the download dialog element funcion
  424. function IG_createDM(a){
  425. let style = (!a)?"position: fixed;left: 0px;right: 0px;bottom: 0px;top: 0px;":"display:none;";
  426. $('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>');
  427. $('.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>');
  428. }
  429.  
  430. // Running if document is ready
  431. $(function(){
  432. // Ready~? GO!!
  433. onReadyMyDW();
  434.  
  435. // Close the download dialog if user click the close icon
  436. $('body').on('click','.IG_SN_DIG_BTN,.IG_SN_DIG_BG',function(){
  437. $('.IG_SN_DIG').remove();
  438. });
  439.  
  440. // Hot key [Alt+Q] to close the download dialog
  441. $(window).keydown(function(e){
  442. if (e.keyCode == '81' && e.altKey){
  443. $('.IG_SN_DIG').remove();
  444. e.preventDefault();
  445. }
  446. });
  447. $('body').on('click','.AutoDownload',function(){
  448. if($('.AutoDownload:checked').length){
  449. GM_setValue('AutoDownload',true);
  450. }
  451. else{
  452. GM_setValue('AutoDownload',false);
  453. }
  454. });
  455.  
  456. $('body').on('click','a[data-needed="direct"]',function(){
  457. let date = new Date().getTime();
  458. let timestamp = Math.floor(date / 1000);
  459. saveFiles($(this).attr('data-href'),GL_username,$(this).attr('data-name'),timestamp,$(this).attr('data-type'));
  460. });
  461.  
  462. // Running if user left-click download icon in stories
  463. $('body').on('click','.IG_DWSTORY',function(){
  464. onStoryDW(true);
  465. });
  466.  
  467. // Running if user left-click download icon in stories
  468. $('body').on('click','.IG_DWSTORY_THUMBNAIL',function(){
  469. onStoryThumbnailDW(true);
  470. });
  471. });
  472.  
  473. })();