diff --git a/docs/rule/index.md b/docs/rule/index.md index f6c3cb67..31fd211a 100644 --- a/docs/rule/index.md +++ b/docs/rule/index.md @@ -123,7 +123,7 @@ enum ContentType { | searchKey | ✅ | 同 `$keyword` , ⚠️不推荐使用 | | $host | ✅ | 替换规则的 `host` | | $result | ✅ | 上一个步骤 result 字段的结果 | -| lastResult | ❌ | | +| lastResult | ✅ | | | searchPage | ❌ | | | $page | ❌ | | | $pageSize | ❌ | | diff --git a/packages/core/src/analyzer/RuleManager.ts b/packages/core/src/analyzer/RuleManager.ts index f6e15ce5..fbc33e0a 100644 --- a/packages/core/src/analyzer/RuleManager.ts +++ b/packages/core/src/analyzer/RuleManager.ts @@ -74,6 +74,9 @@ export class RuleManager { } async getChapter(result: string): Promise { + JSEngine.setEnvironment({ + result, + }) if (this.rule.chapterUrl === '正文') { return [ { @@ -87,8 +90,9 @@ export class RuleManager { JSEngine.setEnvironment({ page: 1, - baseUrl: chapterUrl, lastResult: result, + result: body, + baseUrl: chapterUrl, }) let list = [] @@ -115,20 +119,17 @@ export class RuleManager { return chapterItems } - async getContent(result: string, lastResult?: string): Promise { - if (lastResult) { - JSEngine.setEnvironment({ - page: 1, - result: lastResult, - lastResult, - }) - } + async getContent(result: string): Promise { + JSEngine.setEnvironment({ + result, + }) const contentUrl = this.rule.contentUrl !== 'null' ? this.rule.contentUrl : null const { body, params } = await fetch(this.parseUrl(contentUrl || result), '', result, this.rule) JSEngine.setEnvironment({ page: 1, - baseUrl: params.url, lastResult: result, + result: body, + baseUrl: params.url, }) let list = await this.analyzerManager.getStringList(this.rule.contentItems, body) if (this.rule.contentType === ContentType.NOVEL) { @@ -234,6 +235,9 @@ export class RuleManager { // 获取分类下内容 async discover(url: string, page = 1) { + JSEngine.setEnvironment({ + result: url, + }) const hasNextUrlRule = this.rule.discoverNextUrl !== undefined && this.rule.discoverNextUrl.length > 0 @@ -265,9 +269,9 @@ export class RuleManager { } JSEngine.setEnvironment({ - page, - rule: this.rule, - result: discoverUrl, + page: 1, + lastResult: url, + result: body, baseUrl: this.rule.host, })