Skip to content

Commit

Permalink
Dependency optimization (#1294)
Browse files Browse the repository at this point in the history
* -qs

* -urlencode

* +urlencode

* aaa
  • Loading branch information
Rider21 authored Nov 6, 2024
1 parent e5d852a commit 778a5be
Show file tree
Hide file tree
Showing 11 changed files with 2,295 additions and 104 deletions.
2,333 changes: 2,269 additions & 64 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"dayjs": "^1.11.10",
"htmlparser2": "^9.1.0",
"protobufjs": "^7.2.6",
"qs": "^6.11.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^9.1.2",
Expand All @@ -46,7 +45,6 @@
"@eslint/js": "^9.5.0",
"@types/eslint__js": "^8.42.3",
"@types/eslint-config-prettier": "^6.11.3",
"@types/qs": "^6.9.15",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@types/react-window": "^1.8.8",
Expand All @@ -60,11 +58,12 @@
"image-size": "^1.1.1",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"terser": "^5.34.1",
"terser": "^5.36.0",
"ts-node": "^10.9.2",
"typescript": "^5.5.2",
"typescript-eslint": "^7.14.1",
"vite": "^5.2.0"
"vite": "^5.2.0",
"vite-plugin-node-polyfills": "^0.22.0"
},
"lint-staged": {
"**/*.{js,ts,jsx,tsx}": "prettier --write"
Expand Down
5 changes: 2 additions & 3 deletions scripts/multisrc/readwn/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Plugin } from '@typings/plugin';
import { NovelStatus } from '@libs/novelStatus';
import { load as parseHTML } from 'cheerio';
import dayjs from 'dayjs';
import qs from 'qs';

type ReadwnOptions = {
versionIncrements?: number;
Expand Down Expand Up @@ -204,12 +203,12 @@ class ReadwnPlugin implements Plugin.PluginBase {
Origin: this.site,
},
method: 'POST',
body: qs.stringify({
body: new URLSearchParams({
show: 'title',
tempid: 1,
tbname: 'news',
keyboard: searchTerm,
}),
}).toString(),
}).then(res => res.text());
const loadedCheerio = parseHTML(result);

Expand Down
1 change: 0 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import '@fontsource/roboto/700.css';
import 'cheerio';
import 'htmlparser2';
import 'dayjs';
import 'qs';
import 'protobufjs';

const { fetch: originalFetch } = window;
Expand Down
27 changes: 10 additions & 17 deletions src/plugins/chinese/69xinshu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { load as parseHTML } from 'cheerio';
import { fetchText } from '@libs/fetch';
import { FilterTypes, Filters } from '@libs/filterInputs';
import { Plugin } from '@typings/plugin';
// import { encode } from 'urlencode';
import { encode } from 'urlencode';
import { NovelStatus } from '@libs/novelStatus';

class XinShu69 implements Plugin.PluginBase {
id = '69xinshu';
name = '69书吧';
icon = 'src/cn/69xinshu/icon.png';
site = 'https://www.69shu.pro';
version = '0.1.1';
site = 'https://69shu.biz';
version = '0.1.2';

async popularNovels(
pageNo: number,
Expand All @@ -32,20 +32,14 @@ class XinShu69 implements Plugin.PluginBase {

const novelsList =
pageNo === 1
? loadedCheerio('div.newbox > ul > li')
? loadedCheerio('.newlistbox > ul > li')
: loadedCheerio('li');
novelsList.each((i, e) => {
const novelUrl = loadedCheerio(e)
.find('li > div > h3 > a:nth-child(2)')
.attr('href');

novelsList.each((i, e) => {
const novelUrl = loadedCheerio(e).find('div > h3 > a').attr('href');
if (novelUrl) {
const novelName = loadedCheerio(e)
.find('li > div > h3 > a:nth-child(2)')
.text();
const novelCover = loadedCheerio(e)
.find('li > a > img')
.attr('data-src');
const novelName = loadedCheerio(e).find('div > h3 > a').text();
const novelCover = loadedCheerio(e).find('a > img').attr('data-src');

const novel = {
name: novelName,
Expand Down Expand Up @@ -150,7 +144,7 @@ class XinShu69 implements Plugin.PluginBase {

const searchUrl = `${this.site}/modules/article/search.php`;
const formData = new FormData();
// formData.append('searchkey', encode(searchTerm, 'gbk'));
formData.append('searchkey', encode(searchTerm, 'gbk'));
formData.append('searchtype', 'all');

const body = await fetchText(
Expand All @@ -159,12 +153,11 @@ class XinShu69 implements Plugin.PluginBase {
'gbk',
);
if (body === '') throw Error('无法获取搜索结果,请检查网络');

const loadedCheerio = parseHTML(body);

const novels: Plugin.NovelItem[] = [];

loadedCheerio('div.newbox > ul > li').each((i, e) => {
loadedCheerio('.newbox > ul > li').each((i, e) => {
const novelUrl = loadedCheerio(e).find('a').attr('href')!;
const novelName = loadedCheerio(e).find('div.newnav > h3').text();
const novelCover = loadedCheerio(e).find('img').attr('data-src');
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/english/LibRead.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Plugin } from '@typings/plugin';
import { fetchApi } from '@libs/fetch';
import { CheerioAPI, load as parseHTML } from 'cheerio';
import qs from 'qs';
import { Filters, FilterTypes } from '@libs/filterInputs';

class LibReadPlugin implements Plugin.PluginBase {
Expand Down Expand Up @@ -131,7 +130,7 @@ class LibReadPlugin implements Plugin.PluginBase {
Origin: this.site,
},
method: 'POST',
body: qs.stringify({ searchkey: searchTerm }),
body: new URLSearchParams({ searchkey: searchTerm }).toString(),
});
if (!r.ok)
throw new Error(
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/english/NovelOnline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { load as parseHTML } from 'cheerio';
import { fetchApi } from '@libs/fetch';
import { Plugin } from '@typings/plugin';
import { Filters, FilterTypes } from '@libs/filterInputs';
import qs from 'qs';

class NovelsOnline implements Plugin.PluginBase {
id = 'NO.net';
Expand Down Expand Up @@ -119,7 +118,7 @@ class NovelsOnline implements Plugin.PluginBase {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
method: 'POST',
body: qs.stringify({ q: searchTerm }),
body: new URLSearchParams({ q: searchTerm }).toString(),
}).then(res => res.text());

const $ = parseHTML(result);
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/english/freewebnovel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Plugin } from '@typings/plugin';
import { fetchApi } from '@libs/fetch';
import { CheerioAPI, load as parseHTML } from 'cheerio';
import qs from 'qs';
import { Filters, FilterTypes } from '@libs/filterInputs';

class FreeWebNovel implements Plugin.PluginBase {
Expand Down Expand Up @@ -134,7 +133,7 @@ class FreeWebNovel implements Plugin.PluginBase {
Origin: this.site,
},
method: 'POST',
body: qs.stringify({ searchkey: searchTerm }),
body: new URLSearchParams({ searchkey: searchTerm }).toString(),
});
if (!r.ok)
throw new Error(
Expand Down
13 changes: 6 additions & 7 deletions src/plugins/korean/Agitoon.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { fetchApi } from '@libs/fetch';
import { Plugin } from '@typings/plugin';
import { load as parseHTML } from 'cheerio';
import qs from 'qs';

class Agitoon implements Plugin.PluginBase {
id = 'agit.xyz';
Expand Down Expand Up @@ -29,7 +28,7 @@ class Agitoon implements Plugin.PluginBase {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
method: 'POST',
body: qs.stringify({
body: new URLSearchParams({
mode: 'get_data_novel_list_p',
novel_menu: showLatestNovels ? '1' : '3',
np_day: new Date().getDay(),
Expand All @@ -41,7 +40,7 @@ class Agitoon implements Plugin.PluginBase {
np_genre_ex_2: '00',
list_limit: 20 * (pageNo - 1),
is_query_first: pageNo == 1,
}),
}).toString(),
});
if (!res.ok) {
throw new Error(
Expand Down Expand Up @@ -95,13 +94,13 @@ class Agitoon implements Plugin.PluginBase {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
method: 'POST',
body: qs.stringify({
body: new URLSearchParams({
mode: 'get_data_novel_list_c',
wr_id_p: novelPath,
page_no: '1',
cnt_list: '10000',
order_type: 'Asc',
}),
}).toString(),
});

const resJson = (await res.json()) as responseBook;
Expand Down Expand Up @@ -145,11 +144,11 @@ class Agitoon implements Plugin.PluginBase {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
method: 'POST',
body: qs.stringify({
body: new URLSearchParams({
mode: 'get_data_novel_list_p_sch',
search_novel: searchTerm,
list_limit: 0,
}),
}).toString(),
});
const resJson = (await rawResults.json()) as response;
const novels: Plugin.NovelItem[] = [];
Expand Down
1 change: 0 additions & 1 deletion src/plugins/russian/topliba.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class TopLiba implements Plugin.PluginBase {
});

if (searchTerm) data.append('q', searchTerm);

const body = await fetchApi(this.site + '/?' + data.toString()).then(res =>
res.text(),
);
Expand Down
3 changes: 2 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import path from 'path';
import { fileURLToPath } from 'url';

const dirname = path.dirname(fileURLToPath(import.meta.url));

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react({ devTarget: 'es5' })],
plugins: [nodePolyfills(), react({ devTarget: 'es5' })],
resolve: {
alias: {
'@libs': path.resolve(dirname, './src/libs'),
Expand Down

0 comments on commit 778a5be

Please sign in to comment.