From 41b9897341373013af30c9727ad6b73471d96374 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 6 Nov 2019 17:23:22 +0800 Subject: [PATCH] up --- .../app/model/analyzeRule/AnalyzeRule.kt | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) 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 336e09a13..92f4d71f1 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 @@ -351,6 +351,9 @@ class AnalyzeRule(private var book: BaseBook? = null) { //检测Mode var mMode: Mode = mode when { + vRuleStr.startsWith("@@") -> { + vRuleStr = vRuleStr.substring(2) + } vRuleStr.startsWith("@XPath:", true) -> { mMode = Mode.XPath vRuleStr = vRuleStr.substring(7) @@ -394,7 +397,7 @@ class AnalyzeRule(private var book: BaseBook? = null) { /** * 规则类 */ - inner class SourceRule internal constructor(ruleStr: String, mainMode: Mode) { + inner class SourceRule internal constructor(ruleStr: String, mainMode: Mode = Mode.Default) { internal var mode: Mode internal var rule: String internal var replaceRegex = "" @@ -414,6 +417,14 @@ class AnalyzeRule(private var book: BaseBook? = null) { } } else { when { + ruleStr.startsWith("@CSS:", true) -> { + mode = Mode.Default + rule = ruleStr + } + ruleStr.startsWith("@@") -> { + mode = Mode.Default + rule = ruleStr.substring(2) + } ruleStr.startsWith("@XPath:", true) -> { mode = Mode.XPath rule = ruleStr.substring(7) @@ -516,16 +527,21 @@ class AnalyzeRule(private var book: BaseBook? = null) { } } regType == -1 -> { - val jsEval: Any? = evalJS(ruleParam[index], result) - when { - jsEval == null -> { + if (isRule(ruleParam[index])) { + getString(arrayListOf(SourceRule(ruleParam[index]))).let { + infoVal.insert(0, it) + } + } else { + val jsEval: Any? = evalJS(ruleParam[index], result) + when { + jsEval == null -> Unit + jsEval is String -> infoVal.insert(0, jsEval) + jsEval is Double && jsEval % 1.0 == 0.0 -> infoVal.insert( + 0, + String.format("%.0f", jsEval) + ) + else -> infoVal.insert(0, jsEval.toString()) } - jsEval is String -> infoVal.insert(0, jsEval) - jsEval is Double && jsEval % 1.0 == 0.0 -> infoVal.insert( - 0, - String.format("%.0f", jsEval) - ) - else -> infoVal.insert(0, jsEval.toString()) } } regType == -2 -> { @@ -537,6 +553,18 @@ class AnalyzeRule(private var book: BaseBook? = null) { rule = infoVal.toString() } } + + private fun isRule(ruleStr: String): Boolean { + return when { + ruleStr.startsWith("$.") -> true + ruleStr.startsWith("@XPath:", true) -> true + ruleStr.startsWith("//") -> true + ruleStr.startsWith("@Json:", true) -> true + ruleStr.startsWith("@CSS:", true) -> true + ruleStr.startsWith("@@") -> true + else -> false + } + } } enum class Mode {