diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index fc656d183..84673215c 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -580,6 +580,10 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } fun get(key: String): String { + val chapter = chapter + if (chapter != null && key == "title") { + return chapter.title + } return chapter?.variableMap?.get(key) ?: book?.variableMap?.get(key) ?: "" @@ -594,6 +598,8 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { bindings["book"] = book bindings["result"] = result bindings["baseUrl"] = baseUrl + bindings["chapter"] = chapter + bindings["title"] = chapter?.title return SCRIPT_ENGINE.eval(jsStr, bindings) } diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt index 21a0fa317..040ee91a4 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -96,7 +96,10 @@ object BookContent { var contentStr = content.toString().htmlFormat() val replaceRegex = bookSource.ruleContent?.replaceRegex if (!replaceRegex.isNullOrEmpty()) { - contentStr = AnalyzeRule(book).setContent(contentStr).getString(replaceRegex) + val analyzeRule = AnalyzeRule(book) + analyzeRule.setContent(body, baseUrl) + analyzeRule.chapter = bookChapter + contentStr = analyzeRule.getString(replaceRegex) } Debug.log(bookSource.bookSourceUrl, "┌获取章节名称") Debug.log(bookSource.bookSourceUrl, "└${bookChapter.title}")