Greasy Fork

去掉WEBP - 转换WEBP图片到源格式(JPG PNG GIF)用于Onenote与Evernote剪藏

将豆瓣、微信公众号、简书的webp图片转换为通常格式(JPG PNG GIF),用于Onenote、Evernote剪辑,可自行添加生效网站。已兼容保留GIF动图,豆瓣动图自动加载。欢迎反馈建议。

目前为 2020-02-14 提交的版本。查看 最新版本

// ==UserScript==
// @name           去掉WEBP - 转换WEBP图片到源格式(JPG PNG GIF)用于Onenote与Evernote剪藏
// @name:zh-CN     去掉WEBP - 转换WEBP图片到源格式(JPG PNG GIF)用于Onenote与Evernote剪藏
// @name:en        NO WEBP - Convert WEBP Pics To Common Formats(JPG PNG GIF) For Onenote & Evernote Clip
// @version        1.4
// @author         Black Rabbit
// @namespace      Black Rabbit
// @description    将豆瓣、微信公众号、简书的webp图片转换为通常格式(JPG PNG GIF),用于Onenote、Evernote剪辑,可自行添加生效网站。已兼容保留GIF动图,豆瓣动图自动加载。欢迎反馈建议。
// @description:zh-cn 将豆瓣、微信公众号、简书的webp图片转换为通常格式(JPG PNG GIF),用于Onenote、Evernote剪辑,可自行添加生效网站。已兼容保留GIF动图,豆瓣动图自动加载。欢迎反馈建议。
// @description:en Convert the webp pictures of Douban, WeChat public account and Jianshu into common formats(JPG PNG GIF) for editing in Evernote and Onenote. You can also try to add included urls by yourself. GIF kept and worked in new version. GIF in Douban autoloads. Welcome feedback and suggestions.
// @icon           https://railsware.com/blog/wp-content/uploads/2013/11/24823-picture1.png
// @supportURL     https://greasyfork.org/scripts/396210
// @include        *://mp.weixin.qq.com/*
// @include        *://mmbiz.qpic.cn/*
// @include        *://www.jianshu.com/*
// @include        *://www.douban.com/*
// @include        *://*.douban.com/*
// ==/UserScript==
var img = document.getElementsByTagName('img');
//Douban Convert
function douban_convert(){
    'use strict';
    var img_class = document.getElementsByClassName('image-wrapper');
    for(var i=0;i<img_class.length;i++){
        var img = img_class[i].getElementsByTagName('img');
        img = img[0];
        var img_url = img.src;
        var img_width = img.width;
        //fix & get raw url for GIF
        if (img.outerHTML.toLowerCase().includes('gif')){
            img_url = img_url.replace(/large/g,'raw');
            img_url = img_url.replace(/l\/public/g,'raw/public');
            img_url = img_url.replace(/jpg/g,'gif');
            img_url = img_url.replace(/webp/g,'gif');
            img_class[i].innerHTML = '<img src="' + img_url + '" width="' + img_width + '">';
        }
        else if(img_url.toLowerCase().includes('webp')){
            img.src = img_url.replace(/webp/g,'jpg');}
    }
    setInterval(douban_remains);
}
function douban_remains(){
    for (var i=0;i<img.length;i++){
        if(img[i].outerHTML.toLowerCase().includes('gif')){
            img[i].src = img[i].src.replace(/large/g,'raw');
            img[i].src = img[i].src.replace(/l\/public/g,'raw/public');
            img[i].src = img[i].src.replace(/jpg/g,'gif');
            img[i].src = img[i].src.replace(/webp/g,'gif');}
        else if(img[i].src.toLowerCase().includes('webp')){
            img[i].src = img[i].src.replace(/webp/g,'jpg');}
    }
    clearInterval(douban_remains);
}
//Jianshu & Wechat & Other Convert
function fkwebp(){
    'use strict';
    for (var i=0;i<img.length;i++){
        if(img[i].src.toLowerCase().includes('webp')){
            if(img[i].outerHTML.toLowerCase().includes('jpeg')){
                img[i].src = img[i].src.replace(/webp/g,'jpeg');}
            else if(img[i].outerHTML.toLowerCase().includes('jpg')){
                img[i].src = img[i].src.replace(/webp/g,'jpg');}
            else if(img[i].outerHTML.toLowerCase().includes('png')){
                img[i].src = img[i].src.replace(/webp/g,'png');}
            else if(img[i].outerHTML.toLowerCase().includes('gif')){
                img[i].src = img[i].src.replace(/webp/g,'gif');}
            else{
                img[i].src = img[i].src.replace(/webp/g,'jpg');}
        }
        else{
            clearInterval(fkwebp);}
    }
}

if (document.getElementsByTagName('body')[0].baseURI.toLowerCase().includes('douban')){
    douban_convert();
}
else{
    setInterval(fkwebp);}
clearInterval(fkwebp);
clearInterval(douban_remains);