优化
This commit is contained in:
@@ -235,12 +235,12 @@ interface BaseSource : JsExtensions {
|
|||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun evalJS(jsStr: String, bindingsConfig: ScriptBindings.() -> Unit = {}): Any? {
|
fun evalJS(jsStr: String, bindingsConfig: ScriptBindings.() -> Unit = {}): Any? {
|
||||||
val bindings = buildScriptBindings { bindings ->
|
val bindings = buildScriptBindings { bindings ->
|
||||||
bindings.apply(bindingsConfig)
|
|
||||||
bindings["java"] = this
|
bindings["java"] = this
|
||||||
bindings["source"] = this
|
bindings["source"] = this
|
||||||
bindings["baseUrl"] = getKey()
|
bindings["baseUrl"] = getKey()
|
||||||
bindings["cookie"] = CookieStore
|
bindings["cookie"] = CookieStore
|
||||||
bindings["cache"] = CacheManager
|
bindings["cache"] = CacheManager
|
||||||
|
bindings.apply(bindingsConfig)
|
||||||
}
|
}
|
||||||
val sharedScope = getShareScope()
|
val sharedScope = getShareScope()
|
||||||
val scope = if (sharedScope == null) {
|
val scope = if (sharedScope == null) {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import androidx.core.view.ViewCompat
|
|||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.size
|
import androidx.core.view.size
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.script.rhino.RhinoScriptEngine
|
import com.script.rhino.runScriptWithContext
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.VMBaseActivity
|
import io.legado.app.base.VMBaseActivity
|
||||||
import io.legado.app.constant.AppConst
|
import io.legado.app.constant.AppConst
|
||||||
@@ -473,11 +473,13 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
|
|||||||
val source = viewModel.rssSource
|
val source = viewModel.rssSource
|
||||||
val js = source?.shouldOverrideUrlLoading
|
val js = source?.shouldOverrideUrlLoading
|
||||||
if (!js.isNullOrBlank()) {
|
if (!js.isNullOrBlank()) {
|
||||||
val result = RhinoScriptEngine.runCatching {
|
val result = kotlin.runCatching {
|
||||||
eval(js) {
|
runScriptWithContext(lifecycleScope.coroutineContext) {
|
||||||
|
source.evalJS(js) {
|
||||||
put("java", rssJsExtensions)
|
put("java", rssJsExtensions)
|
||||||
put("url", url.toString())
|
put("url", url.toString())
|
||||||
}.toString()
|
}.toString()
|
||||||
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
AppLog.put("url跳转拦截js出错", it)
|
AppLog.put("url跳转拦截js出错", it)
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
|
|||||||
Reference in New Issue
Block a user