// ==UserScript==
// @name 微博图片批量下载
// @author Shawlj
// @namespace http://tampermonkey.net/
// @description 本程序支持新版微博图片批量下载功能
// @version v1.3
// @match https://weibo.com/*
// @match https://d.weibo.com/*
// @match https://s.weibo.com/*
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.0/jszip.min.js
// @require https://cdn.staticfile.org/mustache.js/3.1.0/mustache.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.10/dayjs.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js
// @resource xinfo https://cdn.jsdelivr.net/gh/Mr-Po/weibo-resource-download/out/media/info.png
// @resource xsuccess https://cdn.jsdelivr.net/gh/Mr-Po/weibo-resource-download/out/media/success.png
// @resource xerror https://cdn.jsdelivr.net/gh/Mr-Po/weibo-resource-download/out/media/error.png
// @connect sinaimg.cn
// @connect weibo.com
// @compatible chrome
// @compatible firefox
// @license MIT
// @grant GM_xmlhttpRequest
// @grant GM_getResourceURL
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_notification
// @grant GM_setClipboard
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_addStyle
// @grant GM_addElement
// @grant GM_deleteValue
// @grant GM_openInTab
// @grant GM_download
// @grant window.onurlchange
// @downloadURL none
// ==/UserScript==
(function() {
"use strict";const i={0:"xerror",1:"xsuccess",2:"xinfo"},n={attributes:!1,childList:!0,subtree:!0},m={t:"https://{0}weibo.com/",i:"https://wx{0}.sinaimg.cn",o:"https://greasyfork.org/zh-CN/scripts/478066"},f={c:{l:"#eb7340",u:"#0000FF",m:"#02A642",$:"woo-font woo-font--imgSave"},p:{v:"vue-recycle-scroller__item-wrapper",h:'[class^="Feed_body"]',g:'[class*="picture-tool-bar_toolbarSpin"]',_:"picture-viewer_previewList",M:"picture-viewer_listContentAnimate",A:"picture-viewer_imgWrap",G:"picture-viewer_showPictureViewer",Y:"a[usercard]>span,a[class^=head-info_time]",S:'[class^="picture-viewer_imgWrap"] img'},s:{C:"pl_feedlist_index",g:"ul.tab",j:"media-pic-zoom",R:"content",k:"choose-pic",D:"card-comment",Y:"a.name,.from a",H:"[suda-data^=key]",S:'[node-type="imgBox"]>img'}};function t(){if(M.L(48)){var t=new MutationObserver((t,e)=>{for(var r of t){var i;"childList"===r.type&&(i=r.addedNodes[0])&&l(f.s.j+"|"+f.p.G,i.className)&&s(r.target,"xwb_btn")}}),e=document.querySelectorAll(`.${f.p.v}, ${f.p.h}, #`+f.s.C);if(!v(e)){h(`\u5fae\u535a\u56fe\u7247\u6279\u91cf\u4e0b\u8f7d\u7a0b\u5e8f\u51c6\u5907\u5c31\u7eea(${e.length})`);for(var r of e)t.observe(r,n)}}}$(document).ready(t),window.addEventListener("urlchange",()=>{setTimeout(()=>t(),2e3)});const s=(t,e)=>{let r,i=[];var n=l(_(m.t,"s."),location.href),s=t.querySelector((n?f.s:f.p).g);if(n){r=f.s.k;var a=$(t).closest("."+f.s.D).length;if((i=(i=$(t).closest("."+f.s.R).find(f.s.Y).filter(f.s.H).toArray()).slice(0,a?4:2)).length){const o="YYYYMMDDHHmm";i=i.map((t,e)=>{let r=t.innerText;return e%2!=0?(e=(t=(r=r.replace(/[\u4e00-\u9fa5:\s]/g,"")).length)<3?o:t<5?o.slice(0,8):t<9?o.slice(0,4):null,(r=e?dayjs().format(e)+r:r).padEnd(14,0)):r.replace("@","")})}}else s&&v($(s).attr(e))&&((i=$(t).closest("article").find(f.p.Y).toArray()).length&&(i=i.map(t=>(t.title||t.textContent).replace(/[@\-\:\s]/g,""))),a=$(t).find(`[class*="${f.p.M}"]`).length,r=0{var a="{1}",o=$($(e.lastChild).context.outerHTML).empty()[0].outerHTML,i=$(t).find(`div[class*="${i}"] img`).toArray();const c=new Set(i.map((t,e)=>t.src.split("/").pop()));let l="";n||(l=$(e.children[1]).context.outerHTML,$(e).append(l).attr(s,s)),$(e).append($(o).append(_(a,f.c.u,"\u4e0b\u8f7d\u56fe\u7247")).click(()=>u(t,r,c,!0))).append(l),$(e).append($(o).append(_(a,f.c.l,`\u4e0b\u8f7d\u5168\u90e8(${c.size})`)).click(()=>u(t,r,c))).append(l),$(e).append($(o).append(_(a,f.c.m,`\u590d\u5236\u94fe\u63a5(${c.size})`)).click(()=>w(c)))};async function u(t,i,e,r){let n,s=[...e];if(r){if(!(e=$(t).find(f.p.S+","+f.s.S)))return g("\u4e0b\u8f7d\u53d1\u751f\u9519\u8bef\uff0c\u9875\u9762\u5143\u7d20\u5df2\u53d8\u66f4\uff0c\u8bf7\u524d\u5f80\u5b98\u65b9\u5347\u7ea7\u6700\u65b0\u7248");r=d(/\/([^\/?#]+)[^\/]*$/,e[0].src),n=s.indexOf(r),s=[r],h(r)}try{{var a=s,o=p(i),c=n,l=encodeURIComponent(_(m.t,""));let e,r;try{for(let t=0;t{e([...t].map(t=>_(m.i,b(4))+"/large/"+t).join("\n"))},p=r=>{const i=new Array,n=M.L(54);return Object.values(M.F).forEach((t,e)=>{11<(e=e.match(t)).length?e[1]:null,e=t=>{navigator.clipboard.writeText(t).then(function(){h("\u590d\u5236\u6210\u529f\uff01")},function(t){h("\u590d\u5236\u5931\u8d25\uff1a",t)})},v=t=>null==t||"undefined"==t||void 0===t||null==t||t.length<1||""===t||"object"==typeof t&&0==t.length,a=(t,e)=>(GM_setValue(t,e),e),o=t=>GM_getValue(t),l=(t,e)=>new RegExp(t).test(e),h=(...t)=>console.log(...t),g=(...t)=>{console.log(...t),alert(t[0])},x=(t,e,r)=>{M.L(49)&&GM_notification({title:r,text:t,O:GM_getResourceURL(i[e]),timeout:3e3})},b=t=>Math.floor(Math.random()*t)+1,_=function(){if(0==arguments.length)return null;for(var t=arguments[0],e=1;eGM_unregisterMenuCommand(t)),Object.values(this.F).forEach((t,e)=>{var r,i;t.splice(2,1,(r=t[0],i=t[2],v(o(r))&&a(r,i),o(r))),this.T[e]=GM_registerMenuCommand(`${t[2]?"\u2705":"\u274c"} ${t[1]} `+t[3],()=>this.U(t)),6GM_openInTab(m.o)))}),this}U(t){t&&this.I(a(t[0],!t[2]))}V(){return $(document).keydown(t=>{var e=(t=t||window.event).keyCode||t.which;return t.altKey&&e&&this.U(this.F[e]),!0}),this}L(t){return o(this.F[t][0])}}).I().V();
})();