diff --git a/README.md b/README.md index c389b490..7da9595f 100644 --- a/README.md +++ b/README.md @@ -353,6 +353,18 @@ EPUB 文件请使用相应阅读器阅读。 设置菜单中按击开启。 +### 自定义下载设置 + +在设置面板中,选中“启用自定义下载设置”以使自定义下载参数生效。 + +以下是自定义下载参数的介绍: + +- 并行下载线程数:可以理解为同时下载的章节数量。数值需设置为 > 0 的整数。非法数值可能会导致下载出错。 +- 下载间隔:仅当“并行下载线程数” = 1时 生效。为每下载一章节后增加的下载间隔时间,单位为毫秒(1 秒= 1000 毫秒)。数值需设置为 > 0 的整数。 +- 最大下载间隔:仅当“并行下载线程数” = 1 时生效。为下载两章节之间最大的间隔时间,单位为毫秒(1 秒= 1000 毫秒)。数值需设置为 > 0 的整数。 + +该设置将应用于所有网站,一般不需要修改此设置,我们已经为每个网站设置好了比较合适的数值。但当网站添加反爬检测时,你可以使用本设置进行调整,我们也欢迎将新的数值提交到issue中。 + ### 自定义筛选函数 如欲只下载部分章节,请在点击运行按钮前,按下 F12 打开开发者工具,在 `window` 下创建 `chapterFilter` 函数,具体格式如下: diff --git a/src/detect.ts b/src/detect.ts index e1238355..61d25300 100644 --- a/src/detect.ts +++ b/src/detect.ts @@ -3,7 +3,15 @@ import { GmWindow } from "./global"; import { _GM_info } from "./lib/GM"; import { storageAvailable } from "./lib/localStorageExpired"; -import { enableDebug, TxtDownload, EpubDownload } from "./setting"; +import { + enableDebug, + TxtDownload, + EpubDownload, + customDownload, + concurrencyLimit, + sleepTime, + maxSleepTime +} from "./setting"; import { fetchWithRetry, fetchWithTimeout } from "./lib/http"; function checkObjct(name: string) { @@ -53,7 +61,7 @@ async function TM_4_14_bug_Detect() { `检测到您当前使用的脚本管理器为 Tampermonkey 4.14。 Tampermonkey 4.14 因存在 Bug 将导致小说下载器脚本无法正常运行,详情可参见:https://github.com/Tampermonkey/tampermonkey/issues/1418 。 如您想继续使用小说下载器脚本,请您更换 Tampermonkey 版本,或使用 Violentmonkey 脚本管理器。 -如果您不欲降级或更换脚本管理器,同时不想再看到本提示,您可以暂时禁用小说下载器脚本。` +如果您不欲更改版本或更换脚本管理器,同时不想再看到本提示,您可以暂时禁用小说下载器脚本。` ); throw new Error("Tampermonkey 4.14 Bug Detect"); } @@ -86,6 +94,10 @@ export const environments = async () => { enableDebug: enableDebug.value, TxtDownload: TxtDownload.value, EpubDownload: EpubDownload.value, + customDownload: customDownload.value, + concurrencyLimit: concurrencyLimit.value, + sleepTime: sleepTime.value, + maxSleepTime: maxSleepTime.value, ScriptHandler: _GM_info.scriptHandler, "ScriptHandler version": _GM_info.version, "Novel-downloader version": _GM_info.script.version, diff --git a/src/rules.ts b/src/rules.ts index 9ad8539b..ec0ae7c0 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -9,12 +9,17 @@ import { Book, saveType } from "./main/Book"; import { SaveBook } from "./save/save"; import { SaveOptions, saveOptionsValidate } from "./save/options"; import { + customDownload, + concurrencyLimit, + sleepTime, + maxSleepTime, enableCustomChapterFilter, enableCustomFinishCallback, enableCustomSaveOptions, enableSaveToArchiveOrg, getCustomEnableSaveToArchiveOrg, } from "./setting"; + import { failedPlus, printStat, successPlus } from "./stat"; import { ProgressVM, vm as progress } from "./ui/progress"; import { setStreamSaverSetting } from "./lib/zip"; @@ -98,6 +103,7 @@ export abstract class BaseRuleClass { await self.preHook(); await initBook(); const saveBookObj = initSave(self.book as Book); + initDownload(); await saveHook(); await self.initChapters(self.book as Book, saveBookObj).catch((error) => { if (error instanceof ExpectError) { @@ -112,7 +118,14 @@ export abstract class BaseRuleClass { } catch (error) { self.catchError(error as Error); } - + function initDownload() { + if (customDownload.value) { + log.info("[run]发现自定义下载设置,将进行覆盖"); + self.concurrencyLimit = concurrencyLimit.value; + self.sleepTime = sleepTime.value; + self.maxSleepTime = maxSleepTime.value; + } + } async function initBook(): Promise { if ( (window as GmWindow)._book && diff --git a/src/save/save.ts b/src/save/save.ts index d14a5381..6b94333d 100644 --- a/src/save/save.ts +++ b/src/save/save.ts @@ -3,7 +3,11 @@ import { logText } from "../log"; import { Book, saveType } from "../main/Book"; import { Chapter } from "../main/Chapter"; import { Status } from "../main/main"; -import { enableDebug, TxtDownload,EpubDownload } from "../setting"; +import { + enableDebug, + TxtDownload, + EpubDownload, +} from "../setting"; import { SaveOptions } from "./options"; import { EPUB } from "./epub"; import { TXT } from "./txt"; diff --git a/src/setting.ts b/src/setting.ts index 05a30771..bc89f51b 100644 --- a/src/setting.ts +++ b/src/setting.ts @@ -10,6 +10,18 @@ export const TxtDownload = { export const EpubDownload = { value: true, }; +export const customDownload = { + value: false, +}; +export const concurrencyLimit = { + value: 1, +}; +export const sleepTime = { + value: 500, +}; +export const maxSleepTime = { + value: 2000, +}; export const enableCustomFinishCallback = true; export const enableCustomChapterFilter = true; export const enableCustomSaveOptions = true; diff --git a/src/ui/setting.html b/src/ui/setting.html index b82f7a9e..359e31a9 100644 --- a/src/ui/setting.html +++ b/src/ui/setting.html @@ -55,6 +55,29 @@
+
+

自定义下载参数

+ + + + + +
+ + + +
+ + + + + +
+

自定义保存参数

    diff --git a/src/ui/setting.ts b/src/ui/setting.ts index 1137554c..845ec0c3 100644 --- a/src/ui/setting.ts +++ b/src/ui/setting.ts @@ -6,7 +6,15 @@ import { log } from "../log"; import { Status } from "../main/main"; import { Chapter } from "../main/Chapter"; import { SaveOptions as globalSaveOptions } from "../save/options"; -import { enableDebug, TxtDownload, EpubDownload } from "../setting"; +import { + enableDebug, + TxtDownload, + EpubDownload, + customDownload, + concurrencyLimit, + sleepTime, + maxSleepTime +} from "../setting"; import FilterTab, { FilterSetting as filterSettingGlobal, getFilterFunction, @@ -30,6 +38,10 @@ export const vm = createApp({ enableDebug?: boolean; TxtDownload?: boolean; EpubDownload?: boolean; + customDownload?: boolean; + concurrencyLimit?: number; + sleepTime?: number; + maxSleepTime?: number; enableTestPage?: boolean; chooseSaveOption?: string; filterSetting?: filterSettingGlobal; @@ -122,6 +134,14 @@ export const vm = createApp({ TxtDownload.value = setting.TxtDownload ?? TxtDownload.value; setting.EpubDownload = GM_getValue('EpubDownload', EpubDownload.value); EpubDownload.value = setting.EpubDownload ?? EpubDownload.value; + setting.customDownload = GM_getValue('customDownload', false); + customDownload.value = setting.customDownload ?? customDownload.value; + setting.concurrencyLimit = GM_getValue('concurrencyLimit', concurrencyLimit.value); + concurrencyLimit.value = setting.concurrencyLimit ?? concurrencyLimit.value; + setting.sleepTime = GM_getValue('sleepTime', sleepTime.value); + sleepTime.value = setting.sleepTime ?? sleepTime.value; + setting.maxSleepTime = GM_getValue('maxSleepTime', maxSleepTime.value); + maxSleepTime.value = setting.maxSleepTime ?? maxSleepTime.value; setting.enableTestPage = GM_getValue('enableTestPage', false); setting.chooseSaveOption = GM_getValue('chooseSaveOption', 'null'); setting.filterSetting = GM_getValue('filterSetting', undefined); @@ -155,6 +175,7 @@ export const vm = createApp({ setEnableDebug(); setTxtDownload(); setEpubDownload(); + setCustomDownloadOption(); setCustomSaveOption(); setCustomFilter(); saveAllSettings(); @@ -183,7 +204,24 @@ export const vm = createApp({ log.info(`[Init]EpubDownload: ${EpubDownload.value}`); } } - + function setCustomDownloadOption() { + if (typeof config.customDownload === "boolean") { + customDownload.value = config.customDownload; + log.info(`[Init]customDownload: ${customDownload.value}`); + } + if (typeof config.concurrencyLimit === "number") { + concurrencyLimit.value = config.concurrencyLimit; + log.info(`[Init]concurrencyLimit: ${concurrencyLimit.value}`); + } + if (typeof config.sleepTime === "number") { + sleepTime.value = config.sleepTime; + log.info(`[Init]sleepTime: ${sleepTime.value}`); + } + if (typeof config.maxSleepTime === "number") { + maxSleepTime.value = config.maxSleepTime; + log.info(`[Init]maxSleepTime: ${maxSleepTime.value}`); + } + } function setCustomSaveOption() { (unsafeWindow as UnsafeWindow).saveOptions = curSaveOption(); } @@ -215,6 +253,10 @@ export const vm = createApp({ GM_setValue('enableDebug', config.enableDebug); GM_setValue('TxtDownload', config.TxtDownload); GM_setValue('EpubDownload', config.EpubDownload); + GM_setValue('customDownload', config.customDownload); + GM_setValue('concurrencyLimit', config.concurrencyLimit); + GM_setValue('sleepTime', config.sleepTime); + GM_setValue('maxSleepTime', config.maxSleepTime); GM_setValue('enableTestPage', config.enableTestPage); GM_setValue('chooseSaveOption', config.chooseSaveOption); GM_setValue('filterSetting', config.filterSetting);