diff --git a/package.json b/package.json index 6a74d6a..dd698fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "betternovelpia", - "version": "10.7.1", + "version": "10.7.2", "license": "UNLICENSED", "scripts": { "preinstall": "npx only-allow pnpm", diff --git a/src/module/ViewNovelToCookie.ts b/src/module/ViewNovelToCookie.ts index 048a1ff..2095b4c 100644 --- a/src/module/ViewNovelToCookie.ts +++ b/src/module/ViewNovelToCookie.ts @@ -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; diff --git a/src/util/ViewerData.ts b/src/util/ViewerData.ts index 3e99041..c41c81d 100644 --- a/src/util/ViewerData.ts +++ b/src/util/ViewerData.ts @@ -1,45 +1,46 @@ -export async function viewerData(url: string, cookie: string): Promise { - 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 { + // 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?.(); + } }