// ==UserScript==
// @name IG小精靈
// @namespace https://github.snkms.com/
// @version 2.0.4
// @description 一鍵下載對方 Instagram 貼文中的相片、影片甚至是限時動態!
// @author 5026
// @match https://*.instagram.com/*
// @grant GM_setValue
// @grant GM_getValue
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
// @supportURL https://www.facebook.com/smileopwe/
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
GM_setValue('dialog',true);
GM_setValue('URLs',location.href);
var $ = window.jQuery;
var timer = setInterval(function(){
GM_setValue('oldHeight',$(document).height());
if(GM_getValue('URLs') != location.href && $('div.PdwC2.fXiEu.s2MYR').length && onChangeURL()){
console.log('aas');
onReadyMyDW(false);
GM_setValue('URLs',location.href);
}
if($('article ._97aPb[data-snig="canDownload"]').length==0 && onChangeURL() && !$('div._2dDPU[role="dialog"]').length){
console.log(true);
onReadyMyDW(true);
}
if($('div#react-root section._9eogI._01nki.lXJWB').length && onChangeStoryURL()){
onStoryDW(false);
}
else{
$('.IG_DWSTORY').remove();
}
},200);
$(document).scroll(function(){
if(GM_getValue('oldHeight') != $(this).height()){
console.log('onChange');
onReadyMyDW();
}
});
function onStoryDW(a){
if(a){
if($('video.y-yJ5').length){
window.open($('video.y-yJ5 source').attr('src')+'&dl=1');
}
else{
window.open($('img.y-yJ5').attr('src')+'&dl=1');
}
}
else{
var style = "position: absolute;right:15px;top:15px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
if(!$('.IG_DWSTORY').length){
$('div#react-root').append('
下載這則限時動態
')
}
}
}
function onChangeURL(){
var reA = /^(https:\/\/www.instagram.com\/p\/)/g;
var reB = /^(https:\/\/www.instagram.com\/)$/g;
var URLs = location.href;
if(URLs.match(reA) || URLs.match(reB)){
return true;
}
}
function onChangeStoryURL(){
var re = /^(https:\/\/www.instagram.com\/stories\/)/g;
var URLs = location.href;
if(URLs.match(re)){
return true;
}
}
function onReadyMyDW(NoDialog){
if(!NoDialog){
$('article ._97aPb').each(function(){
$(this).removeAttr('data-snig');
$(this).unbind('click');
});
$('.SNKMS_IG_DW_MAIN,.SNKMS_IG_DW_MAIN_VIDEO').remove();
}
$('article ._97aPb').each(function(){
if(!$(this).attr('data-snig')){
var style = "position: absolute;right:15px;top:15px;padding:5px;line-height:1;background:#fff;border-radius: 5px;cursor:pointer;";
if($(this).find('video.tWeCl').length){
$(this).append('提取影片資料
');
$(this).on('click','.SNKMS_IG_DW_MAIN_VIDEO',function(e){
IG_createDM();
var i = 0;
$(this).parent().find('video.tWeCl').each(function(){
i++;
console.log($(this).attr('src'));
$('.IG_SN_DIG>div').append('.next().attr('src')+')
影片'+i+'');
});
});
}
else{
$(this).append('提取圖片資料
');
$(this).on('click','.SNKMS_IG_DW_MAIN',function(e){
IG_createDM();
var i = 0;
$(this).parent().find('.FFVAD').each(function(){
i++;
console.log($(this).attr('src'));
$('.IG_SN_DIG>div').append('.attr('src')+')
圖片'+i+'');
});
});
}
$(this).attr('data-snig','canDownload');
}
});
}
function IG_createDM(){
$('body').append('');
$('.IG_SN_DIG>div').append('');
}
$(function(){
onReadyMyDW();
$('body').on('click','.IG_SN_DIG_BTN',function(){
$('.IG_SN_DIG').remove();
});
$('body').on('click','.IG_DWSTORY',function(){
onStoryDW(true);
});
});
})();