Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
green1052 committed Feb 15, 2023
1 parent 7b5bc57 commit cbe4a73
Show file tree
Hide file tree
Showing 22 changed files with 948 additions and 906 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
823 changes: 0 additions & 823 deletions .yarn/releases/yarn-3.3.1.cjs

This file was deleted.

873 changes: 873 additions & 0 deletions .yarn/releases/yarn-3.4.1.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "betternovelpia",
"version": "10.5.6",
"version": "10.6.0",
"license": "UNLICENSED",
"scripts": {
"build": "webpack --config webpack.prod.js",
Expand Down
15 changes: 6 additions & 9 deletions src/module/Bookmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {isDarkMode} from "../util/IsDarkMode";
import {isPageViewer} from "../util/IsPageViewer";
import {appendSide} from "../util/AppendSide";
import {useLongPress} from "use-long-press";
import {Header} from "../util/ApeendHeader";
import {novelLoaded} from "../util/NovelLoaded";
import {NovelContinueBox} from "../util/NovelContinueBox";

Expand Down Expand Up @@ -396,11 +395,7 @@ function Viewer() {
: "#0000007a"};
`;

return (
<Header>
<BookmarkIcon className="icon ion-bookmark" onClick={click} {...longClick}/>
</Header>
);
return <BookmarkIcon className="icon ion-bookmark" onClick={click} {...longClick}/>;
}

export default {
Expand Down Expand Up @@ -463,9 +458,11 @@ export default {
}

if (/^\/viewer\//.test(location.pathname)) {
const appContainer = document.createElement("td");
appContainer.style.width = "63px";
$(HEADER_BAR).children().eq(6).before(appContainer);
const appContainer = document.createElement("div");
appContainer.style.width = "20px";
appContainer.style.height = "20px";

$(`${HEADER_BAR} .menu-top-right`).children().eq(2).before(appContainer);

const root = createRoot(appContainer);
root.render(<Viewer/>);
Expand Down
21 changes: 10 additions & 11 deletions src/module/Layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default {
}
},
property: "start",
start() {
start: function () {
const hideAdEnable = GM_getValue<boolean>("HideAd", false);
const hideEventEnable = GM_getValue<boolean>("HideEvent", false);
const hideRecommendEffectEnable = GM_getValue<boolean>("HideRecommendEffect", false);
Expand Down Expand Up @@ -124,16 +124,22 @@ export default {
}

if (infoUnfoldEnable && /^\/novel\//.test(location.pathname)) {
const moreInfoButton = document.querySelector("#more_info_btn") as HTMLElement;
const moreInfo = document.querySelector(".more_info") as HTMLElement;
const moreInfoButton = document.querySelector<HTMLElement>("#more_info_btn")
const moreInfo = document.querySelector<HTMLElement>(".more_info")

if (moreInfoButton !== null && moreInfo !== null) {
if (moreInfoButton && moreInfo) {
moreInfoButton.style.display = "none";
moreInfo.style.display = "initial";
}
}

if (naviColorEnable && /^\/viewer\//.test(location.pathname)) {
const changeTheme = () => {
const color = document.querySelector<HTMLElement>("#viewer_no_drag")!.style.backgroundColor;
document.querySelector<HTMLElement>(HEADER_BAR)!.style.backgroundColor = color;
document.querySelector<HTMLElement>(FOOTER_BAR)!.style.backgroundColor = color;
};

unsafeWindow.viewer_display =
new Proxy(unsafeWindow.viewer_display, {
apply(target, thisArg, argArray) {
Expand All @@ -142,13 +148,6 @@ export default {
}
});

function changeTheme() {
const color = (document.querySelector("#viewer_no_drag") as HTMLElement).style.backgroundColor;

(document.querySelector(HEADER_BAR) as HTMLElement).style.backgroundColor = color;
(document.querySelector(FOOTER_BAR) as HTMLElement).style.backgroundColor = color;
}

changeTheme();
}

Expand Down
8 changes: 4 additions & 4 deletions src/module/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ function Setting() {
height: 50px;
box-shadow: rgb(0 0 0 / 16%) 0 1px 4px 0;
${isDarkMode()
? css`background-color: black;
? css`background-color: black;
color: white;`
: css`background-color: white;`};
: css`background-color: white;`};
`;

const UnderDiv = styled.div`
Expand All @@ -176,9 +176,9 @@ function Setting() {
height: 30px;
box-shadow: rgb(0 0 0 / 16%) 0 1px 4px 0;
${isDarkMode()
? css`background-color: black;
? css`background-color: black;
color: white;`
: css`background-color: white;`};
: css`background-color: white;`};
`;

return (
Expand Down
36 changes: 24 additions & 12 deletions src/module/ViewNovelToCookie.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import $ from "jquery";
import {fakeViewer} from "../util/FakeViewer";
import {viewerData} from "../util/ViewerData";
import Cookies from "js-cookie";

function resetCookie(name: string, value: string) {
Cookies.set(name, value, {
domain: ".novelpia.com",
path: "/",
expires: new Date(new Date().setFullYear(new Date().getFullYear() + 1))
});
}

export default {
include: /^\/viewer\//,
Expand All @@ -24,26 +33,29 @@ export default {
}
},
async start() {
const blocked = $(".one-event-viewer-plus");
const blocked = $(`p:contains("플러스 멤버십이"), p:contains("열람에 회원가입/로그인이")`);

if (!blocked.length) return;
if (!blocked.length)
return;

const loginKey = GM_getValue<string>("ViewNovelToCookie_LOGINKEY", "").trim();
const userKey = GM_getValue<string>("ViewNovelToCookie_USERKEY", "").trim();
const loginKey = GM_getValue("ViewNovelToCookie_LOGINKEY", "") as string;
const userKey = GM_getValue("ViewNovelToCookie_USERKEY", "") as string;

if (!loginKey || !userKey)
return;

const data = await viewerData(location.pathname.substring(8), `LOGINKEY=${loginKey}; USERKEY=${userKey};`);

if (!data.length) return;
const oldLoginKey = Cookies.get("LOGINKEY") ?? "";
const oldUserKey = Cookies.get("USERKEY") ?? "";

fakeViewer(blocked, data);
resetCookie("LOGINKEY", loginKey);
resetCookie("USERKEY", userKey);

const oldGetCommentBox = unsafeWindow.get_comment_box
.toString()
.replace("response.status == '200'", `response.status == '200' || response.errmsg.includes("PLUS")`);
const data = await viewerData(location.pathname.substring(8), () => {
resetCookie("LOGINKEY", oldLoginKey);
resetCookie("USERKEY", oldUserKey);
});

unsafeWindow.get_comment_box = () => eval(`${oldGetCommentBox}get_comment_box()`);
if (data.length > 0)
fakeViewer(blocked, data);
}
} as Module;
17 changes: 0 additions & 17 deletions src/util/ApeendHeader.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/util/Selectors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const SIDE_LEFT = ".am-sideleft ul";

export const HEADER_BAR = "#header_bar tr";
export const HEADER_BAR = "#header_bar";

export const NOVEL_DRAWING = "#novel_drawing";

Expand Down
57 changes: 29 additions & 28 deletions src/util/ViewerData.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
export async function viewerData(url: string, cookie?: string): Promise<NovelData[]> {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
data: "size=14",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Cookie: cookie ?? document.cookie
},
export function fetchWithTimeout(input: RequestInfo, options: RequestInit, timeout = 5000): Promise<Response> {
// @ts-ignore
return Promise.race([
fetch(input, options),
new Promise((_, reject) =>
setTimeout(() => reject(new Error("timeout")), timeout)
)
]);
}

export async function viewerData(url: string, code?: () => void): Promise<NovelData[]> {
try {
const response: { c: string, s: { text: string }[] } = await (await fetchWithTimeout(`/proc/viewer_data/${url}`, {
method: "POST",
timeout: 5000,
url: `/proc/viewer_data/${url}`,
onerror: (response) => {
reject(response);
cache: "no-cache",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
onload: (response) => {
console.log(response.responseText);

const data: { c: string, s: { text: string }[] } = JSON.parse(response.responseText!);
body: new URLSearchParams({
size: "14"
})
})).json();

resolve(data.s.map(({text}) => {
return {
text,
size: 11,
align: "left"
};
}));
},
ontimeout: (response) => {
reject(response);
}
return response.s.map(({text}) => {
return {
text: text,
size: 11,
align: "left"
};
});
});
} finally {
code?.();
}
}

0 comments on commit cbe4a73

Please sign in to comment.