diff --git a/ComicRead-AdGuard.user.js b/ComicRead-AdGuard.user.js index e54fe83f..871bfafc 100644 --- a/ComicRead-AdGuard.user.js +++ b/ComicRead-AdGuard.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name ComicRead // @namespace ComicRead -// @version 9.1.0 +// @version 9.1.1 // @description 为漫画站增加双页阅读、翻译等优化体验的增强功能。百合会——「记录阅读历史、自动签到等」、百合会新站、动漫之家——「解锁隐藏漫画」、E-Hentai——「匹配 nhentai 漫画」、nhentai——「彻底屏蔽漫画、自动翻页」、Yurifans——「自动签到」、拷贝漫画(copymanga)——「显示最后阅读记录」、PonpomuYuri、明日方舟泰拉记事社、禁漫天堂、漫画柜(manhuagui)、漫画DB(manhuadb)、动漫屋(dm5)、绅士漫画(wnacg)、mangabz、komiic、无限动漫、新新漫画、hitomi、Anchira、kemono、nekohouse、welovemanga // @description:en Add enhanced features to the comic site for optimized experience, including dual-page reading and translation. // @description:ru Добавляет расширенные функции для удобства на сайт, такие как двухстраничный режим и перевод. @@ -517,7 +517,6 @@ const insertNode = (node, textnode, referenceNode = null) => { temp.innerHTML = textnode; const frag = document.createDocumentFragment(); while (temp.firstChild) frag.append(temp.firstChild); - // TODO: 可以淘汰这个工具函数了 // eslint-disable-next-line unicorn/prefer-modern-dom-apis node.insertBefore(frag, referenceNode); }; @@ -4610,7 +4609,9 @@ const handleScrollModeDrag = ({ } }; -const [loadLock, setLoadLock] = solidJs.createSignal(false); +const [loadLock, setLoadLock] = solidJs.createSignal(false, { + equals: false +}); /** 用于存储正在加载的图片元素 */ const loadingImgMap = new Map(); @@ -4656,29 +4657,37 @@ const handleImgError = (i, e) => () => { /** 当前要加载的图片 */ const loadImgList = new Set(); + +/** 加载指定图片。返回是否加载成功 */ const loadImg = index => { - if (!needLoadImgList().has(index) || !store.imgList[index].src) return; - if (store.imgList[index].loadType === 'error' && !renderImgList().has(index)) return; + if (index === -1) return true; + const img = store.imgList[index]; + if (img.loadType === 'loaded') return true; + if (!img.src) return false; + if (img.loadType === 'error' && !renderImgList().has(index)) return true; if (!loadingImgMap.has(index)) { - const img = new Image(); - img.onload = handleImgLoaded(index, img); - img.onerror = handleImgError(index, img); - img.src = store.imgList[index].src; - loadingImgMap.set(index, img); + const imgEle = new Image(); + imgEle.onload = handleImgLoaded(index, imgEle); + imgEle.onerror = handleImgError(index, imgEle); + imgEle.src = img.src; + loadingImgMap.set(index, imgEle); _setState('imgList', index, 'loadType', 'loading'); } loadImgList.add(index); + return true; }; /** * 以当前显示页为基准,预加载附近指定页数的图片,并取消其他预加载的图片 * @param target 加载目标页 * @param loadNum 加载图片数量 - * @returns 返回是否成功加载了指定数量的图片 + * @returns 返回指定范围内是否还有未加载的图片 */ -const loadPageImg = (target = 0, loadNum = 2) => { - const load = i => { - for (const index of store.pageList[i]) loadImg(index); +const loadRangeImg = (target = 0, loadNum = 2) => { + /** 是否还有未加载的图片 */ + let hasUnloadedImg = false; + const loadPage = i => { + for (const index of store.pageList[i]) if (!loadImg(index)) hasUnloadedImg = true; if (loadImgList.size >= loadNum) { setLoadLock(true); return true; @@ -4697,31 +4706,30 @@ const loadPageImg = (target = 0, loadNum = 2) => { end = clamp(0, end, store.pageList.length - 1); } if (start <= end) { - for (let index = start; index <= end; index++) if (load(index)) return true; + for (let index = start; index <= end; index++) if (loadPage(index)) return index !== end || hasUnloadedImg; } else { - for (let index = start; index >= end; index--) if (load(index)) return true; + for (let index = start; index >= end; index--) if (loadPage(index)) return index !== end || hasUnloadedImg; } - return false; + return hasUnloadedImg; }; const updateImgLoadType = singleThreaded(() => { if (needLoadImgList().size === 0 || loadLock()) return; loadImgList.clear(); - setLoadLock(false); if (store.imgList.length > 0) { // eslint-disable-next-line @typescript-eslint/no-unused-vars const _ = // 优先加载当前显示的图片 - loadPageImg() || + loadRangeImg() || // 再加载后面几页 - loadPageImg(preloadNum().back) || + loadRangeImg(preloadNum().back) || // 再加载前面几页 - loadPageImg(-preloadNum().front) || + loadRangeImg(-preloadNum().front) || // 根据图片总数和设置决定是否要继续加载其余图片 !store.option.alwaysLoadAllImg && store.imgList.length > 60 || // 加载当前页后面的图片 - loadPageImg(Number.POSITIVE_INFINITY, 5) || + loadRangeImg(Number.POSITIVE_INFINITY, 5) || // 加载当前页前面的图片 - loadPageImg(Number.NEGATIVE_INFINITY, 5); + loadRangeImg(Number.NEGATIVE_INFINITY, 5); } // 取消其他预加载的图片 @@ -4818,7 +4826,7 @@ const useStyleSheet = () => { const styleSheet = new CSSStyleSheet(); solidJs.onMount(() => { const root = refs.root.getRootNode(); - root.adoptedStyleSheets.push(styleSheet); + root.adoptedStyleSheets = [...root.adoptedStyleSheets, styleSheet]; solidJs.onCleanup(() => { const index = root.adoptedStyleSheets.indexOf(styleSheet); if (index !== -1) root.adoptedStyleSheets.splice(index, 1); @@ -7315,10 +7323,8 @@ const useFab = async initProps => { }; var _tmpl$$1 = /*#__PURE__*/web.template(\`

🥳 ComicRead 已更新到 v\`), - _tmpl$2 = /*#__PURE__*/web.template(\`

新增\`), - _tmpl$3 = /*#__PURE__*/web.template(\`