Skip to content

Commit

Permalink
fix: 🐛 修复预加载页数未正确生效的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hymbz committed Jul 10, 2024
1 parent 6279c89 commit c9f4d8e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@

这是一个因为目前大部分漫画站都不支持双页显示,所以每次遇到 **漫画中的跨页大图被分割成两页** 就很不爽的人为了有更好的漫画阅读体验而写的油猴脚本,为主流漫画站增加了**双页阅读模式**和各种优化体验的增强功能。

双页阅读模式下会自动根据加载图片的长宽进行调整,即使跨页图没有被分割也能自动识别出来单独放一页,并以此自动调整布局确保其他图片的左右页位置正确。

脚本会在网页右下角弹出用于 **进入阅读模式** 的悬浮按钮,其上的快捷按钮用于切换站点增强功能的开启与否。默认会开启**自动进入阅读模式**的功能,也可在这里关闭。脚本除快捷键外,所有设置修改都只会在当前站点生效保存。~~反正平时也就只上那几个站点。~~

脚本也提供了[简易阅读模式](#简易阅读模式)」用于自动识别适配支持站点以外的网站。
另外也提供了[简易阅读模式](#简易阅读模式)」用于自动识别适配支持站点以外的网站。

> 如果喜欢这种阅读模式,也想用来看**本地漫画**的话,欢迎使用「[ComicRead PWA](https://comic-read.pages.dev/)」,只要打开网页拖入本地漫画即可获得完全一致的体验
Expand Down
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@

这是一个因为目前大部分漫画站都不支持双页显示,所以每次遇到 **漫画中的跨页大图被分割成两页** 就很不爽的人为了有更好的漫画阅读体验而写的油猴脚本,为主流漫画站增加了**双页阅读模式**和各种优化体验的增强功能。

双页阅读模式下会自动根据加载图片的长宽进行调整,即使跨页图没有被分割也能自动识别出来单独放一页,并以此自动调整布局确保其他图片的左右页位置正确。

脚本会在网页右下角弹出用于 **进入阅读模式** 的悬浮按钮,其上的快捷按钮用于切换站点增强功能的开启与否。默认会开启**自动进入阅读模式**的功能,也可在这里关闭。脚本除快捷键外,所有设置修改都只会在当前站点生效保存。~~反正平时也就只上那几个站点。~~

脚本也提供了[简易阅读模式](#简易阅读模式)」用于自动识别适配支持站点以外的网站。
另外也提供了[简易阅读模式](#简易阅读模式)」用于自动识别适配支持站点以外的网站。

> 如果喜欢这种阅读模式,也想用来看**本地漫画**的话,欢迎使用「[ComicRead PWA](https://comic-read.pages.dev/)」,只要打开网页拖入本地漫画即可获得完全一致的体验
Expand Down
4 changes: 2 additions & 2 deletions src/components/Manga/actions/imageLoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ const updateImgLoadType = singleThreaded(() => {
loadRangeImg(preloadNum().back) ||
// 再加载前面几页
loadRangeImg(-preloadNum().front) ||
// 根据图片总数和设置决定是否要继续加载其余图片
(!store.option.alwaysLoadAllImg && store.imgList.length > 60) ||
// 根据设置决定是否要继续加载其余图片
!store.option.alwaysLoadAllImg ||
// 加载当前页后面的图片
loadRangeImg(Number.POSITIVE_INFINITY, 5) ||
// 加载当前页前面的图片
Expand Down
19 changes: 1 addition & 18 deletions src/components/Manga/components/ComicImg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import {
defaultImgType,
handleImgError,
handleImgLoaded,
renderImgList,
} from '../actions';
import classes from '../index.module.css';

const RenderComicImg: Component<ComicImg & { index: number }> = (img) => {
export const ComicImg: Component<ComicImg & { index: number }> = (img) => {
const showState = () => imgShowState().get(img.index);

const src = () => {
Expand Down Expand Up @@ -93,22 +92,6 @@ const RenderComicImg: Component<ComicImg & { index: number }> = (img) => {
);
};

// 用于防止图片缓存被浏览器回收
const SaveComicImg: Component<ComicImg & { index: number }> = (img) => (
<picture class={classes.img} id={`${img.index}`}>
<Show when={img.loadType === 'loaded'} children={<img src={img.src} />} />
</picture>
);

/** 漫画图片 */
export const ComicImg: Component<ComicImg & { index: number }> = (img) => (
<Show
when={renderImgList().has(img.index)}
children={RenderComicImg(img)}
fallback={SaveComicImg(img)}
/>
);

// 目前即使是不显示的图片也必须挂载上,否则解析好的图片会被浏览器垃圾回收掉,
// 导致在 ehentai 上无法正常加载图片。但这样会在图片过多时造成性能问题,
// 虽然也尝试了将解析好的 Image 对象存储起来挂上引用和另外放到一个避免渲染的 dom 下,
Expand Down

0 comments on commit c9f4d8e

Please sign in to comment.