pull/48/head
kunfei 5 years ago
parent 22f7dad49a
commit dac407a470
  1. 3
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  2. 15
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt

@ -54,8 +54,5 @@ data class BookChapter(
variable = GSON.toJson(variableMap) variable = GSON.toJson(variableMap)
} }
fun getVariableValue(book: Book, key: String): String? {
return variableMap?.get(key) ?: book.variableMap?.get(key)
}
} }

@ -6,6 +6,7 @@ import androidx.annotation.Keep
import io.legado.app.constant.AppConst.SCRIPT_ENGINE import io.legado.app.constant.AppConst.SCRIPT_ENGINE
import io.legado.app.constant.Pattern.JS_PATTERN import io.legado.app.constant.Pattern.JS_PATTERN
import io.legado.app.data.entities.BaseBook import io.legado.app.data.entities.BaseBook
import io.legado.app.data.entities.BookChapter
import io.legado.app.utils.* import io.legado.app.utils.*
import org.mozilla.javascript.NativeObject import org.mozilla.javascript.NativeObject
import java.util.* import java.util.*
@ -20,7 +21,8 @@ import kotlin.collections.HashMap
*/ */
@Keep @Keep
@Suppress("unused") @Suppress("unused")
class AnalyzeRule(private var book: BaseBook? = null) { class AnalyzeRule(var book: BaseBook? = null) {
var chapter: BookChapter? = null
private var content: Any? = null private var content: Any? = null
private var baseUrl: String? = null private var baseUrl: String? = null
private var isJSON: Boolean = false private var isJSON: Boolean = false
@ -34,10 +36,6 @@ class AnalyzeRule(private var book: BaseBook? = null) {
private var objectChangedJS = false private var objectChangedJS = false
private var objectChangedJP = false private var objectChangedJP = false
fun setBook(book: BaseBook) {
this.book = book
}
@Throws(Exception::class) @Throws(Exception::class)
@JvmOverloads @JvmOverloads
fun setContent(content: Any?, baseUrl: String? = this.baseUrl): AnalyzeRule { fun setContent(content: Any?, baseUrl: String? = this.baseUrl): AnalyzeRule {
@ -570,12 +568,15 @@ class AnalyzeRule(private var book: BaseBook? = null) {
} }
fun put(key: String, value: String): String { fun put(key: String, value: String): String {
book?.putVariable(key, value) chapter?.putVariable(key, value)
?: book?.putVariable(key, value)
return value return value
} }
operator fun get(key: String): String { operator fun get(key: String): String {
return book?.variableMap?.get(key) ?: "" return chapter?.variableMap?.get(key)
?: book?.variableMap?.get(key)
?: ""
} }
/** /**

Loading…
Cancel
Save