Greasy Fork

Greasy Fork is available in English.

微信公众号推文图片一键下载

一键下载微信公众号推文内的图片到本地保存

当前为 2018-04-16 提交的版本,查看 最新版本

// ==UserScript==
// @name         微信公众号推文图片一键下载
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  一键下载微信公众号推文内的图片到本地保存
// @author       Ray++
// @match        https://mp.weixin.qq.com/s/*
// @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
// ==/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)  {	ext=".gif"; }
        if (body_data.imgs[m].indexOf('wx_fmt=png')>0)  {	ext=".png"; }
        if (body_data.imgs[m].indexOf('wx_fmt=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=$('<button class="btn btn-success" id="btn1"><small>一键下载所有图片</small> <span id=cnum></span></button>');


    $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<gs.length;i++)
	{
		if (gs[i].dataset.src) {imgs.push(gs[i].dataset.src);}
		else if (gs[i].src)
			{
				tmp=gs[i].src;
				tmp=tmp.replace("//res.wx.qq.com/mmbizwap","http://res.wx.qq.com/mmbizwap");
				imgs.push(tmp);
			}
	}
body_data.imgs=imgs;
//$("#cnum")[0].innerText=imgs.length;
 // console.log(body_data);
    dl_count=0;
    // Your code here...
})();