Greasy Fork

Greasy Fork is available in English.

【泛用-图片】原图替换

原图替换

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         【泛用-图片】原图替换
// @namespace    http://tampermonkey.net/
// @version      1.00
// @description  原图替换
// @author       You
// @match        *://*.bilibili.com/*
// @match        *://*.taptap.cn/*







// @grant        none
// @run-at       document-start
// @license      MIT

// ==/UserScript==

(function() {

    //18109384135把蜜蜂当宠物
    'use strict';

    let url = window.location.href;
    let domain = document.domain;
    let rules = [];
    let dels = [];
    console.log('url:' + url);

    if (domain.match("bilibili.com")) {
        console.log('[原图替换] 哔哩哔哩');
        rules = [
            ['img','src',/\b\.jpg@[0-9]{2,4}w[^ ]*\b/,'.jpg'],
            ['img','data-src',/\b\.jpg@[0-9]{2,4}w[^ ]*\b/,'.jpg'],
            ['source','srcset',/\b\.jpg@[0-9]{2,4}w[^ ]*\b/,'.jpg'],
        ];
        dels = [
            "#navigator-fixed > div > div.n-inner.clearfix > div.n-tab-links > a.n-btn.n-index.n-fans.n-404.router-link-exact-active.router-link-active.active > span.n-avatar > div > picture"
            //.remove();
        ];
    }
    else if (domain.match("taptap.cn")) {
        console.log('[原图替换] TapTap');
        rules = [
            ['img','src',/\b\.png\?imageMogr2[^ ]*\b/,'.png'],
            //['img','src','tb-left auto_switch'],//顶部
        ];
    }

    // 获取img
    function getTags(tagType, styleType, beforeText, afterText) {
        let tags = document.querySelectorAll(tagType);

        tags.forEach(function(tag){
            let tagText = tag.getAttribute(styleType);
            console.log('imgText的内容为:' + tagText);

            //if (tagText && tagText.includes(beforeText)) {
            if (tagText) {
                tagText = tagText.replace(beforeText, afterText);
                tag.setAttribute(styleType, tagText);
            }
        });
    }

    // 删除
    function delTags(del) {
        let delElement = document.querySelector(del);
        if (delElement) {
            delElement.remove();
        }
    }

    function goGetTags() {
        for (let i = 0; i < rules.length; i++) {
            let rule = rules[i];
            getTags(rule[0], rule[1], rule[2], rule[3]);
        }
        for (let j = 0; j < dels.length; j++) {
            let del = dels[j];
            delTags(del);
        }
    }

    setInterval(goGetTags, 5000);

})();