|
@@ -7,7 +7,7 @@ export const EPUB_THEME_KEY = "epub-theme";
|
|
|
export const EPUB_FONT_KEY = "epub-font";
|
|
|
export const EPUB_FONTSIZE_KEY = "epub-fontsize";
|
|
|
export const EPUB_SIMPLIFIED = "epub-simplified";
|
|
|
-export const EPUB_LOCATION = "epub-location";
|
|
|
+export const EPUB_LOCATION = "epub-loc";
|
|
|
|
|
|
const getFileName = (path) => {
|
|
|
const regex = /([^/]+)\.[^.]+$/;
|
|
@@ -19,6 +19,7 @@ const getFileName = (path) => {
|
|
|
|
|
|
export const useEpubStore = defineStore("epub", () => {
|
|
|
let bodyNode = null;
|
|
|
+ let ghost = false;
|
|
|
const fileName = ref("");
|
|
|
const book = ref(null);
|
|
|
/**
|
|
@@ -62,17 +63,20 @@ export const useEpubStore = defineStore("epub", () => {
|
|
|
manager: "continuous",
|
|
|
snap: false,
|
|
|
* }
|
|
|
+ // 无痕模式
|
|
|
+ ghost: true
|
|
|
* })
|
|
|
*/
|
|
|
const init = async (options = {}) => {
|
|
|
fileName.value = getFileName(options.url);
|
|
|
+ ghost = options.ghost ?? false;
|
|
|
|
|
|
await initEpub(options);
|
|
|
initTheme(options.themes);
|
|
|
const locationStorage = localStorage.getItem(
|
|
|
`${EPUB_LOCATION}-${fileName.value}`
|
|
|
);
|
|
|
- if (locationStorage) {
|
|
|
+ if (locationStorage && !ghost) {
|
|
|
const match = locationStorage.match(/^(.*?)-(\d+)$/);
|
|
|
|
|
|
goToChapter(match[1], match[2]);
|
|
@@ -167,7 +171,7 @@ export const useEpubStore = defineStore("epub", () => {
|
|
|
const startCfi = curLocation.start.cfi;
|
|
|
const scrollLeft =
|
|
|
document.getElementsByClassName("epub-container")[0]?.scrollLeft;
|
|
|
- const page = scrollLeft / rendition.value._layout.pageWidth;
|
|
|
+ const page = Math.round(scrollLeft / rendition.value._layout.pageWidth);
|
|
|
|
|
|
localStorage.setItem(
|
|
|
`${EPUB_LOCATION}-${fileName.value}`,
|
|
@@ -230,10 +234,10 @@ export const useEpubStore = defineStore("epub", () => {
|
|
|
document.getElementsByClassName("epub-container")[0]?.scrollTo({
|
|
|
left: Number(page) * rendition.value._layout.pageWidth,
|
|
|
});
|
|
|
- refreshLocation();
|
|
|
+ !ghost && refreshLocation();
|
|
|
});
|
|
|
} else {
|
|
|
- refreshLocation();
|
|
|
+ !ghost && refreshLocation();
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -257,12 +261,12 @@ export const useEpubStore = defineStore("epub", () => {
|
|
|
|
|
|
const prePage = () => {
|
|
|
rendition.value.prev().then(() => {
|
|
|
- refreshLocation();
|
|
|
+ !ghost && refreshLocation();
|
|
|
});
|
|
|
};
|
|
|
const nextPage = () => {
|
|
|
rendition.value.next().then(() => {
|
|
|
- refreshLocation();
|
|
|
+ !ghost && refreshLocation();
|
|
|
});
|
|
|
};
|
|
|
|