Greasy Fork is available in English.
同时支持封面和角色图高清化
当前为
// ==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();
})();