// ==UserScript==
// @name 微信公众号推文图片一键下载
// @namespace http://tampermonkey.net/
// @version 1.1.1
// @description 一键下载微信公众号推文内的图片到本地保存
// @author Ray++
// @match https://mp.weixin.qq.com/s/*
// @match https://mp.weixin.qq.com/s?__biz=*
// @require http://libs.baidu.com/jquery/1.9.0/jquery.js
// @require http://libs.baidu.com/bootstrap/3.1.1/js/bootstrap.min.js
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM_download
// @resource Bootstrap http://libs.baidu.com/bootstrap/3.1.1/css/bootstrap.min.css
// @downloadURL none
// ==/UserScript==
var body_data={
"isuse":1,
"title":"",
"copyright":"",
"post_date":"",
"post_user":"",
"post_auth":"",
"js_content":"",
"wx_code":"",
"wx_desc":"",
"imgs":Array()
};
var dl_count=0;
function dl(m)
{
var ext=".jpg";
if (body_data.imgs[m].indexOf('wx_fmt=gif')>0 || body_data.imgs[m].indexOf('mmbiz_gif')>0) { ext=".gif"; }
if (body_data.imgs[m].indexOf('wx_fmt=png')>0 || body_data.imgs[m].indexOf('mmbiz_png')>0) { ext=".png"; }
if (body_data.imgs[m].indexOf('wx_fmt=bmp')>0 || body_data.imgs[m].indexOf('mmbiz_bmp')>0) { ext=".bmp"; }
var fn=body_data.title+m.toString()+ext;
GM_download({
url:body_data.imgs[m],
name:fn,
onload:function(){
if (m<(body_data.imgs.length-1)) {
m++;
dl(m);
m_s=(m+1);
$("#cnum")[0].innerText=m_s+"/"+body_data.imgs.length;
// console.log(m);
}
else {
$("#cnum")[0].innerText="";
}
}
});
}
function download_fn(){
dl(0);
}
(function() {
'use strict';
var Bootstrap=GM_getResourceText("Bootstrap");
GM_addStyle(Bootstrap);
var $btn1=$('');
$btn1.click(download_fn);
$("#img-content").prepend($btn1);
var getElm = document.getElementsByTagName("title");
body_data.title=getElm[0].innerText;
var gs=$("#js_content")[0].getElementsByTagName("img");
var imgs=Array();
for (var i=0;i