js添加传入cookie类,可以用来保存参数

pull/487/head^2
gedoor 4 years ago
parent 352cf90c96
commit c68a4f26e5
  1. 3
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 2
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  3. 2
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  4. 20
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt

@ -9,6 +9,7 @@ import io.legado.app.constant.BookType
import io.legado.app.data.entities.rule.*
import io.legado.app.help.AppConfig
import io.legado.app.help.JsExtensions
import io.legado.app.help.http.CookieStore
import io.legado.app.utils.ACache
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
@ -109,6 +110,7 @@ data class BookSource(
val bindings = SimpleBindings()
bindings["baseUrl"] = bookSourceUrl
bindings["java"] = this
bindings["cookie"] = CookieStore
a = AppConst.SCRIPT_ENGINE.eval(
it.substring(4, it.lastIndexOf("<")),
bindings
@ -136,6 +138,7 @@ data class BookSource(
private fun evalJS(jsStr: String): Any {
val bindings = SimpleBindings()
bindings["java"] = this
bindings["cookie"] = CookieStore
return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings)
}

@ -7,6 +7,7 @@ import androidx.room.PrimaryKey
import io.legado.app.constant.AppConst
import io.legado.app.help.AppConfig
import io.legado.app.help.JsExtensions
import io.legado.app.help.http.CookieStore
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import kotlinx.android.parcel.Parcelize
@ -76,6 +77,7 @@ data class RssSource(
private fun evalJS(jsStr: String): Any? {
val bindings = SimpleBindings()
bindings["java"] = this
bindings["cookie"] = CookieStore
return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings)
}

@ -7,6 +7,7 @@ import io.legado.app.constant.AppPattern.JS_PATTERN
import io.legado.app.data.entities.BaseBook
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.JsExtensions
import io.legado.app.help.http.CookieStore
import io.legado.app.utils.*
import org.jsoup.nodes.Entities
import org.mozilla.javascript.NativeObject
@ -649,6 +650,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
private fun evalJS(jsStr: String, result: Any?): Any? {
val bindings = SimpleBindings()
bindings["java"] = this
bindings["cookie"] = CookieStore
bindings["book"] = book
bindings["result"] = result
bindings["baseUrl"] = baseUrl

@ -136,18 +136,19 @@ class AnalyzeUrl(
if (ruleUrl.contains("{{") && ruleUrl.contains("}}")) {
var jsEval: Any
val sb = StringBuffer()
val simpleBindings = SimpleBindings()
simpleBindings["java"] = this
simpleBindings["baseUrl"] = baseUrl
simpleBindings["page"] = page
simpleBindings["key"] = key
simpleBindings["speakText"] = speakText
simpleBindings["speakSpeed"] = speakSpeed
simpleBindings["book"] = book
val bindings = SimpleBindings()
bindings["java"] = this
bindings["cookie"] = CookieStore
bindings["baseUrl"] = baseUrl
bindings["page"] = page
bindings["key"] = key
bindings["speakText"] = speakText
bindings["speakSpeed"] = speakSpeed
bindings["book"] = book
val expMatcher = EXP_PATTERN.matcher(ruleUrl)
while (expMatcher.find()) {
jsEval = expMatcher.group(1)?.let {
SCRIPT_ENGINE.eval(it, simpleBindings)
SCRIPT_ENGINE.eval(it, bindings)
} ?: ""
if (jsEval is String) {
expMatcher.appendReplacement(sb, jsEval)
@ -259,6 +260,7 @@ class AnalyzeUrl(
private fun evalJS(jsStr: String, result: Any? = null): Any? {
val bindings = SimpleBindings()
bindings["java"] = this
bindings["cookie"] = CookieStore
bindings["page"] = page
bindings["key"] = key
bindings["speakText"] = speakText

Loading…
Cancel
Save