优化
This commit is contained in:
@@ -3,6 +3,7 @@ package io.legado.app.help.source
|
||||
import io.legado.app.constant.SourceType
|
||||
import io.legado.app.data.entities.BaseSource
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.data.entities.HttpTTS
|
||||
import io.legado.app.data.entities.RssSource
|
||||
import io.legado.app.model.SharedJsScope
|
||||
import org.mozilla.javascript.Scriptable
|
||||
@@ -19,3 +20,18 @@ fun BaseSource.getSourceType(): Int {
|
||||
else -> error("unknown source type: ${this::class.simpleName}.")
|
||||
}
|
||||
}
|
||||
|
||||
fun BaseSource.copy(): BaseSource {
|
||||
return when (this) {
|
||||
is BookSource -> copy(
|
||||
ruleExplore = ruleExplore?.copy(),
|
||||
ruleSearch = ruleSearch?.copy(),
|
||||
ruleBookInfo = ruleBookInfo?.copy(),
|
||||
ruleToc = ruleToc?.copy()
|
||||
)
|
||||
|
||||
is RssSource -> copy()
|
||||
is HttpTTS -> copy()
|
||||
else -> error("unknown copy source type: ${this::class.simpleName}.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import io.legado.app.exception.NoStackTraceException
|
||||
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.copy
|
||||
import io.legado.app.help.source.getShareScope
|
||||
import io.legado.app.model.Debug
|
||||
import io.legado.app.model.webBook.WebBook
|
||||
@@ -79,6 +80,8 @@ class AnalyzeRule(
|
||||
private var topScopeRef: WeakReference<Scriptable>? = null
|
||||
private var evalJSCallCount = 0
|
||||
|
||||
private val sourceCopy = source?.copy()
|
||||
|
||||
private var coroutineContext: CoroutineContext = EmptyCoroutineContext
|
||||
|
||||
private var loggedNonStandardJSON = false
|
||||
@@ -769,7 +772,7 @@ class AnalyzeRule(
|
||||
bindings["java"] = this
|
||||
bindings["cookie"] = CookieStore
|
||||
bindings["cache"] = CacheManager
|
||||
bindings["source"] = source
|
||||
bindings["source"] = sourceCopy
|
||||
bindings["book"] = book
|
||||
bindings["result"] = result
|
||||
bindings["baseUrl"] = baseUrl
|
||||
|
||||
Reference in New Issue
Block a user