Greasy Fork

Greasy Fork is available in English.

Bangumi高清图片

同时支持封面和角色图高清化

当前为 2025-04-25 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bangumi高清图片
// @namespace    rabbitohh.top
// @version      1.4
// @description  同时支持封面和角色图高清化
// @author       rabbitohh & deepseek
// @match        *://bgm.tv/*
// @match        *://bgm.tv/*
// @match        *://bangumi.tv/*
// @match        *://bangumi.tv/*
// @match        *://chii.in/*
// @match        *://chii.in/*
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const REPLACE_RULES = [
    // 新增s/路径处理规则 (必须放在c/规则之前)
    {
        match: /(\/pic\/cover\/)s\//,  // 捕获s/路径
        replace: '$1l/',                // 替换为l/
        insert: '/r/400'                // 插入分辨率参数
    },
    // 原始规则保持不变
    {
        match: /(\/pic\/cover\/)c\//,
        replace: '$1l/',
        insert: '/r/400'
    },
    {
        match: /(\/pic\/crt\/)g\//,
        replace: '$1m/',
        insert: ''
    }
];

    function enhancedReplace(url) {
        let newUrl = url;
        for (const rule of REPLACE_RULES) {
            if (rule.match.test(newUrl)) {
                newUrl = newUrl
                    .replace(/\/\/lain\.bgm\.tv\//, `//lain.bgm.tv${rule.insert}/`)
                    .replace(rule.match, rule.replace);
                break;
            }
        }
        return newUrl;
    }
    function safeUpgradeImages() {
        document.querySelectorAll('img[src*="lain.bgm.tv"]:not([data-upgraded])').forEach(img => {
            try {
                const original = img.src;
                const newSrc = enhancedReplace(original);

                if (newSrc === original) return;

                const testImg = new Image();
                testImg.onload = function() {
                    img.src = newSrc;
                    img.setAttribute('data-upgraded', 'true');
                    img.style.cssText = 'max-width: 100%; height: auto;';
                };
                testImg.onerror = function() {
                    console.warn('图片加载失败,保留原始地址:', original);
                    img.src = original;
                };
                testImg.src = newSrc;

            } catch (error) {
                console.error('图片处理失败:', error);
            }
        });
    }

    function init() {
        setTimeout(safeUpgradeImages, 2000);
        document.addEventListener('DOMContentLoaded', safeUpgradeImages);
        window.addEventListener('load', safeUpgradeImages);
    }

    let isProcessing = false;
    const safeObserver = new MutationObserver((mutations) => {
        if (!isProcessing) {
            isProcessing = true;
            requestIdleCallback(() => {
                safeUpgradeImages();
                isProcessing = false;
            }, { timeout: 1000 });
        }
    });

    safeObserver.observe(document.body, {
        childList: true,
        subtree: true,
        attributes: false
    });

    init();
})();