Greasy Fork

Greasy Fork is available in English.

Convert WebP to JPG & Automatically Downloading the photos in WeChat Official Account Articles

微信公众号文章webp图片格式转换为jpg, 并浏览时自动下载图片 downloadImg函数参考自https://blog.csdn.net/hope93/article/details/83446758

目前为 2019-04-17 提交的版本。查看 最新版本

// ==UserScript==
// @name           Convert WebP to JPG & Automatically Downloading the photos in WeChat Official Account Articles 
// @author         Lepturus
// @description    微信公众号文章webp图片格式转换为jpg, 并浏览时自动下载图片 downloadImg函数参考自https://blog.csdn.net/hope93/article/details/83446758
// @include        *://mp.weixin.qq.com/*
// @include        *://mmbiz.qpic.cn/*
// @version     1.1
// @namespace http://greasyfork.icu/users/213516
// ==/UserScript==
var imgs = document.getElementsByTagName("img")

function downloadImg(url, name) {
  fetch(url).then(res => res.blob()).then((blob) => {
    const a = document.createElement('a');
    a.style.display = 'none';
    a.href = URL.createObjectURL(blob);
    a.download = name;
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
  });
}

function convert(){
for (var i=0;i<imgs.length;i++)
{
if(imgs[i].src.includes('tp=webp')){
  imgs[i].src = imgs[i].src.replace(/tp=webp/g,"tp=jpg")
  imgs[i].src = imgs[i].src.replace(/http:/g,"https:")
  downloadImg(imgs[i].src, i +".jpg")
  console.log(i)
  console.log(imgs[i].src)}
}
}
setInterval(convert,1000);