Skip to content

Commit

Permalink
10.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
green1052 committed Dec 6, 2023
1 parent 176d3f0 commit 971b3ec
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 53 deletions.
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.7.1",
"version": "10.7.2",
"license": "UNLICENSED",
"scripts": {
"preinstall": "npx only-allow pnpm",
Expand Down
20 changes: 10 additions & 10 deletions src/module/ViewNovelToCookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ export default {
if (!loginKey || !userKey)
return;

// const oldLoginKey = Cookies.get("LOGINKEY") ?? "";
// const oldUserKey = Cookies.get("USERKEY") ?? "";
//
// resetCookie("LOGINKEY", loginKey);
// resetCookie("USERKEY", userKey);
const oldLoginKey = Cookies.get("LOGINKEY") ?? "";
const oldUserKey = Cookies.get("USERKEY") ?? "";

// const data = await viewerData(location.pathname.substring(8), () => {
// resetCookie("LOGINKEY", oldLoginKey);
// resetCookie("USERKEY", oldUserKey);
// });
resetCookie("LOGINKEY", loginKey);
resetCookie("USERKEY", userKey);

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

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

if (data.length <= 0)
return;
Expand Down
85 changes: 43 additions & 42 deletions src/util/ViewerData.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
export async function viewerData(url: string, cookie: string): Promise<NovelData[]> {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "POST",
url: `/proc/viewer_data/${url}`,
data: "size=14",
headers: {
"Cookie": cookie,
},
cookie: cookie,
responseType: "json",
anonymous: true,
onload: ({response}) => {
resolve((response as { c: string, s: { text: string }[] }).s.map(({text}) => {
return {
text: text,
size: 11,
align: "left"
};
}))
},
onerror: reject,
})
});
import ky from "ky";

export async function viewerData(url: string, code?: () => void): Promise<NovelData[]> {
// return new Promise((resolve, reject) => {
// GM_xmlhttpRequest({
// method: "POST",
// url: `/proc/viewer_data/${url}`,
// data: "size=14",
// headers: {
// "Cookie": cookie,
// },
// cookie: cookie,
// responseType: "json",
// anonymous: true,
// onload: ({response}) => {
// resolve((response as { c: string, s: { text: string }[] }).s.map(({text}) => {
// return {
// text: text,
// size: 11,
// align: "left"
// };
// }))
// },
// onerror: reject,
// })
// });

// try {
// const response = await ky.post(`/proc/viewer_data/${url}`, {
// timeout: 5000,
// searchParams: {
// size: "14"
// }
// }).json<{ c: string, s: { text: string }[] }>();
//
// return response.s.map(({text}) => {
// return {
// text: text,
// size: 11,
// align: "left"
// };
// });
// } finally {
// code?.();
// }
try {
const response = await ky.post(`/proc/viewer_data/${url}`, {
timeout: 5000,
searchParams: {
size: "14"
}
}).json<{ c: string, s: { text: string }[] }>();

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

0 comments on commit 971b3ec

Please sign in to comment.