优化
This commit is contained in:
@@ -12,14 +12,13 @@ import io.legado.app.help.JsExtensions
|
||||
import io.legado.app.help.SymmetricCryptoAndroid
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.http.CookieStore
|
||||
import io.legado.app.model.SharedJsScope
|
||||
import io.legado.app.help.source.getShareScope
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.fromJsonArray
|
||||
import io.legado.app.utils.fromJsonObject
|
||||
import io.legado.app.utils.has
|
||||
import io.legado.app.utils.printOnDebug
|
||||
import org.intellij.lang.annotations.Language
|
||||
import org.mozilla.javascript.Scriptable
|
||||
|
||||
/**
|
||||
* 可在js里调用,source.xxx()
|
||||
@@ -249,8 +248,4 @@ interface BaseSource : JsExtensions {
|
||||
}
|
||||
return RhinoScriptEngine.eval(jsStr, scope)
|
||||
}
|
||||
|
||||
fun getShareScope(): Scriptable? {
|
||||
return SharedJsScope.getScope(jsLib)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package io.legado.app.help.source
|
||||
|
||||
import io.legado.app.data.entities.BaseSource
|
||||
import io.legado.app.model.SharedJsScope
|
||||
import org.mozilla.javascript.Scriptable
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
fun BaseSource.getShareScope(coroutineContext: CoroutineContext? = null): Scriptable? {
|
||||
return SharedJsScope.getScope(jsLib, coroutineContext)
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import org.mozilla.javascript.Scriptable
|
||||
import splitties.init.appCtx
|
||||
import java.io.File
|
||||
import java.lang.ref.WeakReference
|
||||
import kotlin.collections.set
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
object SharedJsScope {
|
||||
|
||||
@@ -25,7 +25,7 @@ object SharedJsScope {
|
||||
|
||||
private val scopeMap = hashMapOf<String, WeakReference<Scriptable>>()
|
||||
|
||||
fun getScope(jsLib: String?): Scriptable? {
|
||||
fun getScope(jsLib: String?, coroutineContext: CoroutineContext?): Scriptable? {
|
||||
if (jsLib.isNullOrBlank()) {
|
||||
return null
|
||||
}
|
||||
@@ -60,11 +60,11 @@ object SharedJsScope {
|
||||
throw NoStackTraceException("下载jsLib-${value}失败")
|
||||
}
|
||||
}
|
||||
RhinoScriptEngine.eval(js, scope)
|
||||
RhinoScriptEngine.eval(js, scope, coroutineContext)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
RhinoScriptEngine.eval(jsLib, scope)
|
||||
RhinoScriptEngine.eval(jsLib, scope, coroutineContext)
|
||||
}
|
||||
scopeMap[key] = WeakReference(scope)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import io.legado.app.data.entities.RssArticle
|
||||
import io.legado.app.help.CacheManager
|
||||
import io.legado.app.help.JsExtensions
|
||||
import io.legado.app.help.http.CookieStore
|
||||
import io.legado.app.help.source.getShareScope
|
||||
import io.legado.app.model.webBook.WebBook
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.NetworkUtils
|
||||
@@ -748,7 +749,7 @@ class AnalyzeRule(
|
||||
bindings["rssArticle"] = rssArticle
|
||||
}
|
||||
val scope = RhinoScriptEngine.getRuntimeScope(bindings)
|
||||
source?.getShareScope()?.let {
|
||||
source?.getShareScope(coroutineContext)?.let {
|
||||
scope.prototype = it
|
||||
}
|
||||
return RhinoScriptEngine.eval(jsStr, scope, coroutineContext)
|
||||
|
||||
@@ -8,6 +8,7 @@ import cn.hutool.core.util.HexUtil
|
||||
import com.bumptech.glide.load.model.GlideUrl
|
||||
import com.script.buildScriptBindings
|
||||
import com.script.rhino.RhinoScriptEngine
|
||||
import com.script.rhino.runScriptWithContext
|
||||
import io.legado.app.constant.AppConst.UA_NAME
|
||||
import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.constant.AppPattern.JS_PATTERN
|
||||
@@ -35,6 +36,7 @@ import io.legado.app.help.http.newCallStrResponse
|
||||
import io.legado.app.help.http.postForm
|
||||
import io.legado.app.help.http.postJson
|
||||
import io.legado.app.help.http.postMultipart
|
||||
import io.legado.app.help.source.getShareScope
|
||||
import io.legado.app.utils.EncoderUtils
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.NetworkUtils
|
||||
@@ -45,7 +47,6 @@ import io.legado.app.utils.isJson
|
||||
import io.legado.app.utils.isJsonArray
|
||||
import io.legado.app.utils.isJsonObject
|
||||
import io.legado.app.utils.isXml
|
||||
import com.script.rhino.runScriptWithContext
|
||||
import io.legado.app.utils.splitNotBlank
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
@@ -307,7 +308,7 @@ class AnalyzeUrl(
|
||||
bindings["result"] = result
|
||||
}
|
||||
val scope = RhinoScriptEngine.getRuntimeScope(bindings)
|
||||
source?.getShareScope()?.let {
|
||||
source?.getShareScope(coroutineContext)?.let {
|
||||
scope.prototype = it
|
||||
}
|
||||
return RhinoScriptEngine.eval(jsStr, scope, coroutineContext)
|
||||
|
||||
Reference in New Issue
Block a user