Greasy Fork

Greasy Fork is available in English.

微博图片批量下载

本程序支持新版微博图片批量下载功能

目前为 2024-01-01 提交的版本,查看 最新版本

// ==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
// ==/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:"http://greasyfork.icu/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<a?f.p.M:f.p.A);v(i)||c(t,s,i,r,n,e)},c=(t,e,r,i,n,s)=>{var a="<a style='color:{0}'>{1}</a>",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<a.length;t++){e=`${_(m.i,b(4))}/large/${a[t]}?referer=`+l;var u=await(await fetch(e)).blob();r=v(c)?t:c,saveAs(u,o+"-"+String(r+1).padStart(2,0))}}catch(t){throw h("\u5f53\u524d\u670d\u52a1\u5668\u8bbf\u95ee\u5931\u8d25\uff0c\u8bf7\u518d\u6b21\u5c1d\u8bd5\u4e0b\u8f7d",e,t),t}}await 0,x("\u56fe\u7247\u4e0b\u8f7d\u5b8c\u6210",1)}catch(t){x(t.message,0)}}const w=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)=>{1<e&&o(t[0])&&(t=r[e-2])&&e<6&&(e%2!=0?i.push(n?t:t.slice(0,8)):i.push(t))}),M.L(55)&&i.push(dayjs().format("YYYYMMDDHHmmssSSS")),i.join("-")},d=(t,e)=>1<(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;e<arguments.length;e++)var r=new RegExp("\\{"+(e-1)+"\\}","gm"),t=t.replace(r,arguments[e]);return t},M=(new class{constructor(){this.T=new Array(9),this.F={48:["$xwbp-xdn","\u811a\u672c\u542f\u7528",!0,"(Alt+0)"],49:["$xwbn-xms","\u6d88\u606f\u901a\u77e5",!0,"(Alt+1)"],50:["$xwbf-xn1","\u6587\u4ef6\u540d\uff1a\u6635\u79f0 (\u539f)",!0,"(Alt+2)"],51:["$xwbf-xt1","\u6587\u4ef6\u540d\uff1a\u65f6\u95f4 (\u539f)",!0,"(Alt+3)"],52:["$xwbf-xn2","\u6587\u4ef6\u540d\uff1a\u6635\u79f0 (\u8f6c)",!1,"(Alt+4)"],53:["$xwbf-xt2","\u6587\u4ef6\u540d\uff1a\u65f6\u95f4 (\u8f6c)",!1,"(Alt+5)"],54:["$xwbf-sfm","\u6587\u4ef6\u540d\uff1a\u65f6\u5206\u79d2",!0,"(Alt+6)"],55:["$xwbf-stm","\u6587\u4ef6\u540d\uff1a\u65f6\u95f4\u6233",!0,"(Alt+7)"]}}I(){return this.T.forEach(t=>GM_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)),6<e&&this.T.push(GM_registerMenuCommand("\ud83d\udcac \u53cd\u9988 & \u5efa\u8bae",()=>GM_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();
})();