pull/48/head
kunfei 5 years ago
parent 35c9a139b1
commit 41b9897341
  1. 48
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt

@ -351,6 +351,9 @@ class AnalyzeRule(private var book: BaseBook? = null) {
//检测Mode //检测Mode
var mMode: Mode = mode var mMode: Mode = mode
when { when {
vRuleStr.startsWith("@@") -> {
vRuleStr = vRuleStr.substring(2)
}
vRuleStr.startsWith("@XPath:", true) -> { vRuleStr.startsWith("@XPath:", true) -> {
mMode = Mode.XPath mMode = Mode.XPath
vRuleStr = vRuleStr.substring(7) 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 mode: Mode
internal var rule: String internal var rule: String
internal var replaceRegex = "" internal var replaceRegex = ""
@ -414,6 +417,14 @@ class AnalyzeRule(private var book: BaseBook? = null) {
} }
} else { } else {
when { when {
ruleStr.startsWith("@CSS:", true) -> {
mode = Mode.Default
rule = ruleStr
}
ruleStr.startsWith("@@") -> {
mode = Mode.Default
rule = ruleStr.substring(2)
}
ruleStr.startsWith("@XPath:", true) -> { ruleStr.startsWith("@XPath:", true) -> {
mode = Mode.XPath mode = Mode.XPath
rule = ruleStr.substring(7) rule = ruleStr.substring(7)
@ -516,16 +527,21 @@ class AnalyzeRule(private var book: BaseBook? = null) {
} }
} }
regType == -1 -> { regType == -1 -> {
val jsEval: Any? = evalJS(ruleParam[index], result) if (isRule(ruleParam[index])) {
when { getString(arrayListOf(SourceRule(ruleParam[index]))).let {
jsEval == null -> { 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 -> { regType == -2 -> {
@ -537,6 +553,18 @@ class AnalyzeRule(private var book: BaseBook? = null) {
rule = infoVal.toString() 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 { enum class Mode {

Loading…
Cancel
Save