pull/1272/head
gedoor 3 years ago
parent b80286435d
commit 53238cf38c
  1. 4
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  2. 12
      app/src/main/java/io/legado/app/data/entities/BookSource.kt

@ -96,9 +96,11 @@ interface BaseSource : JsExtensions {
* 执行JS
*/
@Throws(Exception::class)
private fun evalJS(jsStr: String): Any? {
fun evalJS(jsStr: String): Any? {
val bindings = SimpleBindings()
bindings["java"] = this
bindings["source"] = this
bindings["baseUrl"] = getStoreUrl()
bindings["cookie"] = CookieStore
bindings["cache"] = CacheManager
return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings)

@ -3,16 +3,12 @@ package io.legado.app.data.entities
import android.os.Parcelable
import android.text.TextUtils
import androidx.room.*
import io.legado.app.constant.AppConst
import io.legado.app.constant.BookType
import io.legado.app.data.entities.rule.*
import io.legado.app.help.CacheManager
import io.legado.app.help.http.CookieStore
import io.legado.app.utils.*
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import splitties.init.appCtx
import javax.script.SimpleBindings
@Parcelize
@TypeConverters(BookSource.Converters::class)
@ -66,18 +62,12 @@ data class BookSource(
val aCache = ACache.get(appCtx, "explore")
ruleStr = aCache.getAsString(bookSourceUrl) ?: ""
if (ruleStr.isBlank()) {
val bindings = SimpleBindings()
bindings["java"] = this
bindings["source"] = this
bindings["baseUrl"] = bookSourceUrl
bindings["cookie"] = CookieStore
bindings["cache"] = CacheManager
val jsStr = if (exploreUrl.startsWith("@")) {
exploreUrl.substring(4)
} else {
exploreUrl.substring(4, exploreUrl.lastIndexOf("<"))
}
ruleStr = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString().trim()
ruleStr = evalJS(jsStr).toString().trim()
aCache.put(bookSourceUrl, ruleStr)
}
}

Loading…
Cancel
Save