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

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

  1. // ==UserScript==
  2. // @name 微信公众号推文图片一键下载
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.1
  5. // @description 一键下载微信公众号推文内的图片到本地保存
  6. // @author LeO
  7. // @match https://mp.weixin.qq.com/s/*
  8. // @match https://mp.weixin.qq.com/s?__biz=*
  9. // @require http://libs.baidu.com/jquery/1.9.0/jquery.js
  10. // @grant GM_addStyle
  11. // @grant GM_download
  12. // @grant GM_xmlhttpRequest
  13. // @grant GM_getResourceText
  14. // @resource Bootstrap http://libs.baidu.com/bootstrap/3.1.1/css/bootstrap.min.css
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18.  
  19. var body_data={
  20. "isuse":1,
  21. "title":"",
  22. "copyright":"",
  23. "post_date":"",
  24. "post_user":"",
  25. "post_auth":"",
  26. "js_content":"",
  27. "wx_code":"",
  28. "wx_desc":"",
  29. "imgs":Array(),
  30. "imgs_tag":Array()
  31. };
  32.  
  33.  
  34. function dl(m)
  35. {
  36. var ext=".jpg";
  37. if (body_data.imgs[m].indexOf('wx_fmt=gif')>0 || body_data.imgs[m].indexOf('mmbiz_gif')>0)
  38. { ext=".gif"; }
  39. if (body_data.imgs[m].indexOf('wx_fmt=png')>0 || body_data.imgs[m].indexOf('mmbiz_png')>0)
  40. { ext=".png"; }
  41. if (body_data.imgs[m].indexOf('wx_fmt=bmp')>0 || body_data.imgs[m].indexOf('mmbiz_bmp')>0)
  42. { ext=".bmp"; }
  43.  
  44. var fn=body_data.title+m.toString()+ext;
  45.  
  46. GM_xmlhttpRequest({
  47. method: 'GET',
  48. url: body_data.imgs[m],
  49. responseType: 'blob',
  50. onload:function (xhr) {
  51. var blobURL=window.URL.createObjectURL(xhr.response);
  52. if (body_data.imgs_tag[m]==1)
  53. {
  54. let download_a = document.querySelector('.download_a');
  55. download_a.href = blobURL;
  56. download_a.setAttribute('download', fn);
  57. download_a.click();
  58. window.URL.revokeObjectURL(blobURL);
  59. body_data.imgs_tag[m]=0;
  60.  
  61. if (m<(body_data.imgs.length-1)) {
  62. m++;
  63. dl(m);
  64. $("#cnum")[0].innerText=m+"/"+body_data.imgs.length;
  65. }
  66. else
  67. {
  68. $("#cnum")[0].innerText="";
  69. }
  70. }
  71. }
  72. });
  73. }
  74.  
  75.  
  76. function download_fn(){
  77. dl(0);
  78. }
  79.  
  80. (function() {
  81. 'use strict';
  82. var Bootstrap=GM_getResourceText("Bootstrap");
  83. GM_addStyle(Bootstrap);
  84.  
  85. var $btn1=$('<button class="btn btn-success" id="btn1"><small>一键下载所有图片</small> <span id=cnum></span></button><a class="download_a" style="display:none;" download=""></a>');
  86.  
  87.  
  88. $btn1.click(download_fn);
  89. $("#img-content").prepend($btn1);
  90.  
  91. var title = $('meta[property="twitter:title"]').attr("content");
  92. if (title.length==0) {
  93. title=$("title").text();
  94. }
  95. body_data.title=title;
  96.  
  97. var gs=$("#js_content")[0].getElementsByTagName("img");
  98. var imgs=Array();
  99. var imgs_tag=Array();
  100. for (var i=0;i<gs.length;i++)
  101. {
  102. if (gs[i].dataset.src) {imgs.push(gs[i].dataset.src);}
  103. else if (gs[i].src)
  104. {
  105. var tmp=gs[i].src;
  106. tmp=tmp.replace("//res.wx.qq.com/mmbizwap","http://res.wx.qq.com/mmbizwap");
  107. imgs.push(tmp);
  108. }
  109. imgs_tag.push(1);
  110. }
  111. body_data.imgs=imgs;
  112. body_data.imgs_tag=imgs_tag;
  113. $("#cnum")[0].innerText=imgs.length;
  114. console.log(body_data);
  115.  
  116. // Your code here...
  117. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址