From 8c9ef11fcc7c1b54da071e54861d483c6041590f Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 30 Nov 2020 16:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89fontJs,=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=86=99=E5=9C=A8=E6=9B=BF=E6=8D=A2=E8=A7=84=E5=88=99=E9=87=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/data/entities/rule/ContentRule.kt | 1 - .../app/model/analyzeRule/AnalyzeRule.kt | 25 +++++++++++-------- .../legado/app/model/webBook/BookContent.kt | 7 +----- .../source/edit/BookSourceEditActivity.kt | 2 -- app/src/main/res/values-zh-rHK/strings.xml | 3 +-- app/src/main/res/values-zh-rTW/strings.xml | 3 +-- app/src/main/res/values-zh/strings.xml | 3 +-- app/src/main/res/values/strings.xml | 3 +-- 8 files changed, 19 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt index d9fe9afd6..7679810a9 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt @@ -10,6 +10,5 @@ data class ContentRule( var webJs: String? = null, var sourceRegex: String? = null, var replaceRegex: String? = null, //替换规则 - var fontJs: String? = null, var imageStyle: String? = null, //默认大小居中,FULL最大宽度 ) : Parcelable \ No newline at end of file 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 841f06284..9d9640ee7 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 @@ -25,8 +25,7 @@ import kotlin.collections.HashMap @Suppress("unused", "RegExpRedundantEscape") class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { var chapter: BookChapter? = null - var content: Any? = null - private set + private var content: Any? = null private var baseUrl: String? = null private var baseURL: URL? = null private var isJSON: Boolean = false @@ -178,20 +177,24 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { * 获取文本 */ @JvmOverloads - fun getString(ruleStr: String?, isUrl: Boolean = false): String { + fun getString(ruleStr: String?, isUrl: Boolean = false, value: String? = null): String { if (TextUtils.isEmpty(ruleStr)) return "" val ruleList = splitSourceRule(ruleStr) - return getString(ruleList, isUrl) + return getString(ruleList, isUrl, value) } @JvmOverloads - fun getString(ruleList: List, isUrl: Boolean = false): String { - var result: Any? = null + fun getString( + ruleList: List, + isUrl: Boolean = false, + value: String? = null + ): String { + var result: Any? = value val content = this.content - if (content != null && ruleList.isNotEmpty()) { - result = content - if (content is NativeObject) { - result = content[ruleList[0].rule]?.toString() + if ((content != null || result != null) && ruleList.isNotEmpty()) { + if (result == null) result = content + if (result is NativeObject) { + result = result[ruleList[0].rule]?.toString() } else { for (sourceRule in ruleList) { putRule(sourceRule.putMap) @@ -622,7 +625,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { /** * 执行JS */ - fun evalJS(jsStr: String, result: Any?, content: String? = null): Any? { + fun evalJS(jsStr: String, result: Any?): Any? { val bindings = SimpleBindings() bindings["java"] = this bindings["cookie"] = CookieStore 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 46fc2d690..3176aa962 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 @@ -92,14 +92,9 @@ object BookContent { } content.deleteCharAt(content.length - 1) var contentStr = content.toString().htmlFormat() - val fontJs = contentRule.fontJs - if (!fontJs.isNullOrBlank()) { - contentStr = analyzeRule.evalJS(fontJs, body, contentStr)?.toString() ?: "" - } val replaceRegex = contentRule.replaceRegex if (!replaceRegex.isNullOrEmpty()) { - analyzeRule.setContent(contentStr) - contentStr = analyzeRule.getString(replaceRegex) + contentStr = analyzeRule.getString(replaceRegex, value = contentStr) } Debug.log(bookSource.bookSourceUrl, "┌获取章节名称") Debug.log(bookSource.bookSourceUrl, "└${bookChapter.title}") diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 080b8d368..37423cc54 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -236,7 +236,6 @@ class BookSourceEditActivity : add(EditEntity("webJs", cr?.webJs, R.string.rule_web_js)) add(EditEntity("sourceRegex", cr?.sourceRegex, R.string.rule_source_regex)) add(EditEntity("replaceRegex", cr?.replaceRegex, R.string.rule_replace_regex)) - add(EditEntity("fontJs", cr?.fontJs, R.string.rule_font_js)) add(EditEntity("imageStyle", cr?.imageStyle, R.string.rule_image_style)) } //发现 @@ -340,7 +339,6 @@ class BookSourceEditActivity : "webJs" -> contentRule.webJs = it.value "sourceRegex" -> contentRule.sourceRegex = it.value "replaceRegex" -> contentRule.replaceRegex = it.value - "fontJs" -> contentRule.fontJs = it.value "imageStyle" -> contentRule.imageStyle = it.value } } diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 893411d95..2c15ad602 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -410,9 +410,8 @@ 更新時間 (ChapterInfo) 正文規則 (content) 正文下一頁 URL 規則 (nextContentUrl) - webJs + WebViewJs(webJs) 資源正則 (sourceRegex) - 字体处理js 圖標 (sourceIcon) 列表規則 (ruleArticles) 列表下一頁規則 (ruleArticles) diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index c09b3900d..70beb84fd 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -411,7 +411,7 @@ 更新時間(ChapterInfo) 正文規則(content) 正文下一頁URL規則(nextContentUrl) - webJs + WebViewJs(webJs) 資源正則(sourceRegex) 圖示(sourceIcon) @@ -729,7 +729,6 @@ 閱讀介面設定 圖片樣式(imageStyle) 取代規則(replaceRegex) - 字体处理js 分組名稱 備註內容 預設啟用取代淨化 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index d1db709e9..91ffcc4fb 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -416,10 +416,9 @@ 更新时间(ChapterInfo) 正文规则(content) 正文下一页URL规则(nextContentUrl) - webJs + WebViewJs(webJs) 图片样式(imageStyle) 替换规则(replaceRegex) - 字体处理js 资源正则(sourceRegex) 图标(sourceIcon) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 755942049..e3c4ef893 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -418,10 +418,9 @@ 更新时间(ChapterInfo) 正文规则(content) 正文下一页URL规则(nextContentUrl) - webJs + WebViewJs(webJs) 资源正则(sourceRegex) 替换规则(replaceRegex) - 字体处理js 图片样式(imageStyle) 图标(sourceIcon)