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.data.entities.rule.*
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.JsExtensions import io.legado.app.help.JsExtensions
import io.legado.app.help.http.CookieStore
import io.legado.app.utils.ACache import io.legado.app.utils.ACache
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
@ -109,6 +110,7 @@ data class BookSource(
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["baseUrl"] = bookSourceUrl bindings["baseUrl"] = bookSourceUrl
bindings["java"] = this bindings["java"] = this
bindings["cookie"] = CookieStore
a = AppConst.SCRIPT_ENGINE.eval( a = AppConst.SCRIPT_ENGINE.eval(
it.substring(4, it.lastIndexOf("<")), it.substring(4, it.lastIndexOf("<")),
bindings bindings
@ -136,6 +138,7 @@ data class BookSource(
private fun evalJS(jsStr: String): Any { private fun evalJS(jsStr: String): Any {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["java"] = this bindings["java"] = this
bindings["cookie"] = CookieStore
return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings) 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.constant.AppConst
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.JsExtensions import io.legado.app.help.JsExtensions
import io.legado.app.help.http.CookieStore
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
@ -76,6 +77,7 @@ data class RssSource(
private fun evalJS(jsStr: String): Any? { private fun evalJS(jsStr: String): Any? {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["java"] = this bindings["java"] = this
bindings["cookie"] = CookieStore
return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings) 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.BaseBook
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.JsExtensions import io.legado.app.help.JsExtensions
import io.legado.app.help.http.CookieStore
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jsoup.nodes.Entities import org.jsoup.nodes.Entities
import org.mozilla.javascript.NativeObject import org.mozilla.javascript.NativeObject
@ -649,6 +650,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
private fun evalJS(jsStr: String, result: Any?): Any? { private fun evalJS(jsStr: String, result: Any?): Any? {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["java"] = this bindings["java"] = this
bindings["cookie"] = CookieStore
bindings["book"] = book bindings["book"] = book
bindings["result"] = result bindings["result"] = result
bindings["baseUrl"] = baseUrl bindings["baseUrl"] = baseUrl

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

Loading…
Cancel
Save