Skip to content

Instantly share code, notes, and snippets.

@Neboer
Created June 27, 2025 12:04
Show Gist options
  • Save Neboer/e0144a206396dc0bb84eb6f7deff8c00 to your computer and use it in GitHub Desktop.
Save Neboer/e0144a206396dc0bb84eb6f7deff8c00 to your computer and use it in GitHub Desktop.
修复萌娘百科缩略图无法加载的错误,将缩略图替换成原图URL。
// ==UserScript==
// @name Moegirl 原图简洁替换器
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 将萌娘百科图片中的缩略图链接简洁替换为原图链接(img.src)
// @match https://zh.moegirl.org.cn/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
function replaceImageSrcs() {
const prefix = 'https://img.moegirl.org.cn/common/thumb/';
const imgs = document.querySelectorAll('img[src^="' + prefix + '"]');
imgs.forEach(img => {
const src = img.src;
// 去掉 'thumb/' 部分
const noThumb = src.replace('/thumb/', '/');
// 去掉最后一节(最后一个 '/' 到结尾)
const lastSlash = noThumb.lastIndexOf('/');
if (lastSlash !== -1) {
const newSrc = noThumb.substring(0, lastSlash);
img.src = newSrc;
}
});
}
window.addEventListener('load', replaceImageSrcs);
// 监听 DOM 动态变动(如懒加载图片)
const observer = new MutationObserver(replaceImageSrcs);
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment