优化规则解析

pull/423/head
gedoor 4 years ago
parent 402a1df05e
commit 0786240f12
  1. 20
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt

@ -18,6 +18,10 @@ import java.util.*
*/ */
@Keep @Keep
class AnalyzeByJSoup { class AnalyzeByJSoup {
companion object {
val validKeys = arrayOf("class", "id", "tag", "text", "children")
}
private var element: Element? = null private var element: Element? = null
fun parse(doc: Any): AnalyzeByJSoup { fun parse(doc: Any): AnalyzeByJSoup {
@ -232,18 +236,18 @@ class AnalyzeByJSoup {
elements.addAll(es) elements.addAll(es)
} }
} else { } else {
val rulePcx = rule.splitNotBlank("!") val rulePcx = rule.split("!")
val rulePc = val rulePc = rulePcx[0].trim { it <= ' ' }.split(">")
rulePcx[0].trim { it <= ' ' }.splitNotBlank(">") val rules = rulePc[0].trim { it <= ' ' }.split(".")
val rules =
rulePc[0].trim { it <= ' ' }.splitNotBlank(".")
var filterRules: Array<String>? = null var filterRules: Array<String>? = null
var needFilterElements = rulePc.size > 1 && !isEmpty(rulePc[1].trim { it <= ' ' }) var needFilterElements = rulePc.size > 1 && !isEmpty(rulePc[1].trim { it <= ' ' })
if (needFilterElements) { if (needFilterElements) {
filterRules = rulePc[1].trim { it <= ' ' }.splitNotBlank(".") filterRules = rulePc[1].trim { it <= ' ' }.split(".").toTypedArray()
filterRules[0] = filterRules[0].trim { it <= ' ' } filterRules[0] = filterRules[0].trim { it <= ' ' }
val validKeys = listOf("class", "id", "tag", "text") if (filterRules.size < 2
if (filterRules.size < 2 || !validKeys.contains(filterRules[0]) || isEmpty(filterRules[1].trim { it <= ' ' })) { || !validKeys.contains(filterRules[0])
|| filterRules[1].trim { it <= ' ' }.isEmpty()
) {
needFilterElements = false needFilterElements = false
} }
filterRules[1] = filterRules[1].trim { it <= ' ' } filterRules[1] = filterRules[1].trim { it <= ' ' }

Loading…
Cancel
Save