From 0087746eb07db415953bb024cad1c817f58cd14c Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 12 Sep 2020 20:43:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/analyzeRule/AnalyzeRule.kt | 6 ++++++ .../main/java/io/legado/app/model/webBook/BookContent.kt | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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}")