pull/48/head
kunfei 5 years ago
parent 35c9a139b1
commit 41b9897341
  1. 34
      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,10 +527,14 @@ class AnalyzeRule(private var book: BaseBook? = null) {
}
}
regType == -1 -> {
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 -> {
}
jsEval == null -> Unit
jsEval is String -> infoVal.insert(0, jsEval)
jsEval is Double && jsEval % 1.0 == 0.0 -> infoVal.insert(
0,
@ -528,6 +543,7 @@ class AnalyzeRule(private var book: BaseBook? = null) {
else -> infoVal.insert(0, jsEval.toString())
}
}
}
regType == -2 -> {
infoVal.insert(0, get(ruleParam[index]))
}
@ -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 {

Loading…
Cancel
Save