Greasy Fork is available in English.
处理图片资源加载失败时自动重新加载
当前为
// ==UserScript==
// @name 修复copymanga图片错误
// @namespace https://github.com/IronKinoko/copymanga
// @version 1.0.1
// @license MIT
// @description 处理图片资源加载失败时自动重新加载
// @author IronKinoko
// @match https://copymanga.com/*
// @icon https://www.google.com/s2/favicons?domain=copymanga.com
// @grant none
// ==/UserScript==
(function () {
'use strict';
async function waitHasComicContent() {
return new Promise((resolve, reject) => {
function getComic() {
const imgs = document.querySelectorAll('.comicContent-image-list li img');
if (imgs.length) {
resolve(imgs);
} else {
requestAnimationFrame(getComic);
}
}
requestAnimationFrame(getComic);
})
}
async function injectFixImg() {
/** @type {HTMLImageElement[]} */
const imgs = await waitHasComicContent();
imgs.forEach((img) => {
img.addEventListener('error', () => {
const url = new URL(img.src);
url.searchParams.set('t', Date.now());
img.src = url.toString();
});
});
}
function $(string) {
return new DOMParser().parseFromString(string, 'text/html').body.firstChild
}
function main() {
if (/comic\/.*\/chapter/.test(location.href)) injectFixImg();
else {
const header = document.querySelector('.container.header-log .row');
if (header) {
header.style.flexWrap = 'nowrap';
header.querySelector('div:nth-child(6)').replaceWith(
$(
`<div class="col-1">
<div class="log-txt">
<a href="/web/person/shujia">我的书架</a>
<div class="log-unboder"></div>
</div>
</div>`
)
);
header.querySelector('div:nth-child(7)').replaceWith(
$(
`<div class="col-1">
<div class="log-txt">
<a href="/web/person/liulan">我的浏览</a>
<div class="log-unboder"></div>
</div>
</div>`
)
);
header.querySelector('div:nth-child(8)').className = 'col';
header.querySelector('div.col > div > div').style.justifyContent =
'flex-end';
}
}
}
main();
}());