`);
$('.IG_SN_DIG .IG_SN_DIG_BODY div').append(`
`);
$('.IG_SN_DIG .IG_SN_DIG_BODY div').append(`
`);
$('.IG_SN_DIG .IG_SN_DIG_BODY div').append(`
`);
}
// Running if document is ready
$(function(){
$('body').on('click','.IG_SN_DIG .IG_SN_DIG_BODY .IG_DISPLAY_DOM_TREE',function(){
let text = $('div[id^="mount"]')[0];
$('.IG_SN_DIG .IG_SN_DIG_BODY textarea').text(text.innerHTML);
});
// Close the download dialog if user click the close icon
$('body').on('click','.IG_SN_DIG_BTN,.IG_SN_DIG_BG',function(){
$('.IG_SN_DIG').remove();
});
$(window).keydown(function(e){
// Hot key [Alt+Q] to close the download dialog
if (e.keyCode == '81' && e.altKey){
$('.IG_SN_DIG').remove();
e.preventDefault();
}
// Hot key [Alt+W] to open the settings dialog
if (e.keyCode == '87' && e.altKey){
showSetting();
e.preventDefault();
}
// Hot key [Alt+Z] to open the settings dialog
if (e.keyCode == '90' && e.altKey){
showDebugDOM();
e.preventDefault();
}
});
$('body').on('change', '.IG_SN_DIG input',function(){
var isChecked = $(this).prop('checked');
var name = $(this).attr('id');
GM_setValue(name, isChecked);
USER_SETTING[name] = isChecked;
});
$('body').on('click','a[data-needed="direct"]',async function(){
let date = new Date().getTime();
let timestamp = Math.floor(date / 1000);
let username = ($(this).attr('data-username')) ? $(this).attr('data-username') : GL_username;
if(!username && $(this).attr('data-path')){
console.log('catching owner name from shortcode:',$(this).attr('data-href'));
username = await getPostOwner($(this).attr('data-path'));
}
saveFiles($(this).attr('data-href'),username,$(this).attr('data-name'),timestamp,$(this).attr('data-type'), $(this).attr('data-path'));
});
// Running if user left-click download icon in stories
$('body').on('click','.IG_DWSTORY',function(){
onStory(true);
});
// Running if user left-click download icon in stories
$('body').on('click','.IG_DWSTORY_THUMBNAIL',function(){
onStoryThumbnail(true);
});
// Running if user left-click download icon in profile
$('body').on('click','.IG_DWPROFILE',function(e){
e.stopPropagation();
onProfileAvatar(true);
});
// Running if user left-click download icon in highlight stories
$('body').on('click','.IG_DWHISTORY',function(){
onHighlightsStory(true);
});
// Running if user left-click download icon in highlight stories
$('body').on('click','.IG_DWHISTORY_THUMBNAIL',function(){
onHighlightsStoryThumbnail(true);
});
// Running if user left-click download icon in reels
$('body').on('click','.IG_REELS',function(){
onReels(true,true);
});
// Running if user left-click download icon in reels
$('body').on('click','.IG_REELS_THUMBNAIL',function(){
onReels(true,false);
});
// Running if user right-click profile picture in stories area
$('body').on('contextmenu','button[role="menuitem"]',function(){
if(location.href === 'https://www.instagram.com/' && USER_SETTING.REDIRECT_RIGHT_CLICK_USER_STORY_PICTURE){
if($(this).find('canvas._aarh').length > 0){
location.href = 'https://www.instagram.com/'+$(this).children('div').last().text();
}
}
});
$('body').on('change', '.IG_SN_DIG_TITLE .checkbox', function(){
var isChecked = $(this).find('input').prop('checked');
$('.IG_SN_DIG_BODY .inner_box').each(function(){
$(this).prop('checked', isChecked);
});
});
$('body').on('change', '.IG_SN_DIG_BODY .inner_box', function(){
var checked = $('.IG_SN_DIG_BODY .inner_box:checked').length;
var total = $('.IG_SN_DIG_BODY .inner_box').length;
$('.IG_SN_DIG_TITLE .checkbox').find('input').prop('checked', checked == total);
});
$('body').on('click', '.IG_SN_DIG_TITLE #batch_download_selected', function(){
let index = 0;
$('.IG_SN_DIG_BODY a[data-needed="direct"]').each(function(){
if($(this).prev().prop('checked')){
$(this).click();
index++;
}
});
if(index == 0){
alert(_i18n('NO_CHECK_RESOURCE'));
}
});
$('body').on('click', '.IG_SN_DIG_TITLE #batch_download_direct', function(){
$('.IG_SN_DIG_BODY a[data-needed="direct"]').each(function(){
$(this).click();
});
});
});
})(jQuery);