Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
green1052 committed Sep 1, 2021
1 parent e2e8f6e commit 7a442df
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 34 deletions.
4 changes: 0 additions & 4 deletions @types/novelpia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ declare var playAlert: number | undefined;

declare var data_load: 0 | 1;

declare var this_page: number;

declare function page_goto(goto_page: number): void;

interface NovelData {
text: string,
size: number,
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "betternovelpia",
"version": "4.1.3",
"version": "4.1.4",
"scripts": {
"build": "webpack",
"watch": "webpack --watch"
Expand All @@ -13,14 +13,14 @@
"@types/url-regex-safe": "^1.0.0",
"browserslist": "^4.16.8",
"jquery": "^3.6.0",
"js-cookie": "^3.0.0",
"js-cookie": "^3.0.1",
"regenerator-runtime": "^0.13.9",
"swc-loader": "^0.1.14",
"terser-webpack-plugin": "^5.1.4",
"terser-webpack-plugin": "^5.2.0",
"typescript": "^4.4.2",
"url-regex-safe": "^2.0.2",
"webpack": "^5.51.1",
"webpack-cli": "^4.8.0",
"webpack-userscript": "^2.5.8"
}
}
}
2 changes: 1 addition & 1 deletion src/module/AbsoluteViewerDrag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ function start() {
.removeAttr("ondragstart")
.removeAttr("onselectstart")
.removeAttr("oncontextmenu")
.append("<style></style>.no-drag{-ms-user-select:unset!important;-moz-user-select:unset!important;-webkit-user-select:unset!important;-khtml-user-select:unset!important;user-select:unset!important;}</style>");
.append("<style>.no-drag{-ms-user-select:unset!important;-moz-user-select:unset!important;-webkit-user-select:unset!important;-khtml-user-select:unset!important;user-select:unset!important;}</style>");
}
40 changes: 25 additions & 15 deletions src/module/Bookmark.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import $ from "jquery";
import {waitElement} from "../util/WaitElement";
import {HEADER_BAR, NOVEL_DRAWING, NOVEL_EP, NOVEL_TITLE, SIDE_LEFT} from "../util/Selectors";
import {HEADER_BAR, NOVEL_BOX, NOVEL_DRAWING, NOVEL_EP, NOVEL_TITLE, SIDE_LEFT} from "../util/Selectors";

export default {start};

Expand All @@ -9,21 +9,21 @@ interface Bookmarks {
}

interface Bookmark {
page: number,
scrollTop: number,
title: string,
chapter: string
}

interface PreviousBookmark {
url: string,
page: number
scrollTop: number
}

function setBookmark(bookmarks: Bookmarks, url: string, page: number, title: string, chapter: string) {
function setBookmark(bookmarks: Bookmarks, url: string, scrollTop: number, title: string, chapter: string) {
const bookmark: Bookmarks = bookmarks ?? {};

bookmark[url] = {
page: page,
scrollTop: scrollTop,
title: encodeURIComponent(title),
chapter: encodeURIComponent(chapter)
};
Expand Down Expand Up @@ -57,14 +57,16 @@ async function previousBookmark() {
if (!GM_config.get("PreviousBookmark") || !location.pathname.includes("/viewer/"))
return;

let lastPage = 0;
let lastScrollTop = 0;

setInterval(() => {
if (this_page === lastPage)
const scrollTop = $("#novel_box").scrollTop()!;

if (!scrollTop || scrollTop === lastScrollTop)
return;

GM.setValue("previousBookmark", {url: location.href, page: this_page} as PreviousBookmark);
lastPage = this_page;
GM.setValue("previousBookmark", {url: location.href, scrollTop: scrollTop} as PreviousBookmark);
lastScrollTop = scrollTop;
}, 1000);

const bookmark: PreviousBookmark = await GM.getValue("previousBookmark");
Expand All @@ -77,7 +79,8 @@ async function previousBookmark() {

const goto = () => {
if (!GM_config.get("PreviousBookmark_AutoUse") && !confirm("읽던 부분으로 이동하시겠습니까?")) return;
page_goto(bookmark.page);

$(NOVEL_BOX).animate({scrollTop: bookmark.scrollTop}, 0);
};

if ($(NOVEL_DRAWING).children().length > 0) {
Expand Down Expand Up @@ -140,6 +143,14 @@ async function addViewerBookmarkButton() {
.css("width", 63)
.css("z-index", 10000)
.on("click", async () => {
const scrollTop = $("#novel_box").scrollTop();

if (scrollTop === undefined)
return;

if (scrollTop === 0)
return alert("스크롤을 해야 저장할 수 있습니다.");

const bookmarks: Bookmarks = await GM.getValue("bookmarks") ?? {};

const title = $(NOVEL_TITLE).text();
Expand All @@ -148,7 +159,7 @@ async function addViewerBookmarkButton() {
if (!title || !chapter)
return alert("제목 또는 챕터 값이 비어있습니다.");

setBookmark(bookmarks, location.href, this_page, title, chapter);
setBookmark(bookmarks, location.href, scrollTop, title, chapter);

alert("저장되었습니다.");
})
Expand All @@ -161,18 +172,17 @@ async function addViewerBookmarkButton() {
if (!bookmarks)
return;

const page = bookmarks[location.href]?.page;
const scrollTop = bookmarks[location.href]?.scrollTop;

if (!page || !await isFirst("bookmark"))
if (!scrollTop || !await isFirst("bookmark"))
return;

if (GM_config.get("Bookmark_OneUse"))
removeBookmark(bookmarks, location.href);

const goto = () => {
if (!GM_config.get("Bookmark_AutoUse") && !confirm("저장해두었던 북마크로 이동하시겠습니까?")) return;

page_goto(page);
$(NOVEL_BOX).animate({scrollTop: scrollTop}, 0);
};

if ($(NOVEL_DRAWING).children().length > 0) {
Expand Down
43 changes: 33 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,10 @@ __metadata:
"@types/url-regex-safe": ^1.0.0
browserslist: ^4.16.8
jquery: ^3.6.0
js-cookie: ^3.0.0
js-cookie: ^3.0.1
regenerator-runtime: ^0.13.9
swc-loader: ^0.1.14
terser-webpack-plugin: ^5.1.4
terser-webpack-plugin: ^5.2.0
typescript: ^4.4.2
url-regex-safe: ^2.0.2
webpack: ^5.51.1
Expand Down Expand Up @@ -1466,7 +1466,7 @@ __metadata:
languageName: node
linkType: hard

"jest-worker@npm:^27.0.2":
"jest-worker@npm:^27.0.2, jest-worker@npm:^27.0.6":
version: 27.1.0
resolution: "jest-worker@npm:27.1.0"
dependencies:
Expand All @@ -1484,10 +1484,10 @@ __metadata:
languageName: node
linkType: hard

"js-cookie@npm:^3.0.0":
version: 3.0.0
resolution: "js-cookie@npm:3.0.0"
checksum: 36575124492d8344e91048075e387834178a5ffedb5d30910e69e88608464e3c5da973b6534ff3cf208e5ebec8760bd28749426a734e690348a3054058c870d8
"js-cookie@npm:^3.0.1":
version: 3.0.1
resolution: "js-cookie@npm:3.0.1"
checksum: bb48de67e2a6bd1ae3dfd6b2d5a167c33dd0c5a37e909206161eb0358c98f17cb55acd55827a58e9eea3630d89444e7479f7938ef4420dda443218b8c434a4c3
languageName: node
linkType: hard

Expand Down Expand Up @@ -2207,7 +2207,7 @@ resolve@^1.9.0:
languageName: node
linkType: hard

"schema-utils@npm:^3.0.0, schema-utils@npm:^3.1.0":
"schema-utils@npm:^3.0.0, schema-utils@npm:^3.1.0, schema-utils@npm:^3.1.1":
version: 3.1.1
resolution: "schema-utils@npm:3.1.1"
dependencies:
Expand Down Expand Up @@ -2464,7 +2464,7 @@ resolve@^1.9.0:
languageName: node
linkType: hard

"terser-webpack-plugin@npm:^5.1.3, terser-webpack-plugin@npm:^5.1.4":
"terser-webpack-plugin@npm:^5.1.3":
version: 5.1.4
resolution: "terser-webpack-plugin@npm:5.1.4"
dependencies:
Expand All @@ -2480,7 +2480,30 @@ resolve@^1.9.0:
languageName: node
linkType: hard

"terser@npm:^5.3.8, terser@npm:^5.7.0":
"terser-webpack-plugin@npm:^5.2.0":
version: 5.2.0
resolution: "terser-webpack-plugin@npm:5.2.0"
dependencies:
jest-worker: ^27.0.6
p-limit: ^3.1.0
schema-utils: ^3.1.1
serialize-javascript: ^6.0.0
source-map: ^0.6.1
terser: ^5.7.2
peerDependencies:
webpack: ^5.1.0
peerDependenciesMeta:
"@swc/core":
optional: true
esbuild:
optional: true
uglify-js:
optional: true
checksum: df2a4a340d1c8efb611b61987d4f2c2217efdff479dd2e44d7628ef32df2dafc8322c7e8a1267bdaec530824f7a66fc1cf71a39f0a5bb721c710235d6ee86c92
languageName: node
linkType: hard

"terser@npm:^5.3.8, terser@npm:^5.7.0, terser@npm:^5.7.2":
version: 5.7.2
resolution: "terser@npm:5.7.2"
dependencies:
Expand Down

0 comments on commit 7a442df

Please sign in to comment.