Greasy Fork is available in English.
处理图片资源加载失败时自动重新加载
当前为
// ==UserScript==
// @name 修复copymanga图片错误
// @namespace http://tampermonkey.net/
// @version 1.0.0
// @description 处理图片资源加载失败时自动重新加载
// @author IronKinoko
// @match https://copymanga.com/comic/*/chapter/*
// @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 main() {
/** @type {HTMLImageElement[]} */
const imgs = await waitHasComicContent();
imgs.forEach((img) => {
img.addEventListener('error', () => {
fixImg(img);
});
});
}
/**
* @param {HTMLImageElement} img
*/
function fixImg(img) {
img.src = img.src + '?' + Math.random();
}
main();
}());