From dac407a47020f72a7554fec301b342f576a1a48b Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 12 Nov 2019 15:32:53 +0800 Subject: [PATCH] up --- .../io/legado/app/data/entities/BookChapter.kt | 3 --- .../legado/app/model/analyzeRule/AnalyzeRule.kt | 15 ++++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index 8fa130d31..b88151e5d 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -54,8 +54,5 @@ data class BookChapter( variable = GSON.toJson(variableMap) } - fun getVariableValue(book: Book, key: String): String? { - return variableMap?.get(key) ?: book.variableMap?.get(key) - } } 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 1fa1b11c7..20804006f 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 @@ -6,6 +6,7 @@ import androidx.annotation.Keep import io.legado.app.constant.AppConst.SCRIPT_ENGINE import io.legado.app.constant.Pattern.JS_PATTERN import io.legado.app.data.entities.BaseBook +import io.legado.app.data.entities.BookChapter import io.legado.app.utils.* import org.mozilla.javascript.NativeObject import java.util.* @@ -20,7 +21,8 @@ import kotlin.collections.HashMap */ @Keep @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 baseUrl: String? = null private var isJSON: Boolean = false @@ -34,10 +36,6 @@ class AnalyzeRule(private var book: BaseBook? = null) { private var objectChangedJS = false private var objectChangedJP = false - fun setBook(book: BaseBook) { - this.book = book - } - @Throws(Exception::class) @JvmOverloads 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 { - book?.putVariable(key, value) + chapter?.putVariable(key, value) + ?: book?.putVariable(key, value) return value } operator fun get(key: String): String { - return book?.variableMap?.get(key) ?: "" + return chapter?.variableMap?.get(key) + ?: book?.variableMap?.get(key) + ?: "" } /**