Horis 1 год назад
Родитель
Сommit
749a8702fc

+ 16 - 0
app/src/main/java/io/legado/app/help/source/BaseSourceExtensions.kt

@@ -3,6 +3,7 @@ package io.legado.app.help.source
 import io.legado.app.constant.SourceType
 import io.legado.app.constant.SourceType
 import io.legado.app.data.entities.BaseSource
 import io.legado.app.data.entities.BaseSource
 import io.legado.app.data.entities.BookSource
 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.data.entities.RssSource
 import io.legado.app.model.SharedJsScope
 import io.legado.app.model.SharedJsScope
 import org.mozilla.javascript.Scriptable
 import org.mozilla.javascript.Scriptable
@@ -19,3 +20,18 @@ fun BaseSource.getSourceType(): Int {
         else -> error("unknown source type: ${this::class.simpleName}.")
         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}.")
+    }
+}

+ 4 - 1
app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt

@@ -16,6 +16,7 @@ import io.legado.app.exception.NoStackTraceException
 import io.legado.app.help.CacheManager
 import io.legado.app.help.CacheManager
 import io.legado.app.help.JsExtensions
 import io.legado.app.help.JsExtensions
 import io.legado.app.help.http.CookieStore
 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.help.source.getShareScope
 import io.legado.app.model.Debug
 import io.legado.app.model.Debug
 import io.legado.app.model.webBook.WebBook
 import io.legado.app.model.webBook.WebBook
@@ -79,6 +80,8 @@ class AnalyzeRule(
     private var topScopeRef: WeakReference<Scriptable>? = null
     private var topScopeRef: WeakReference<Scriptable>? = null
     private var evalJSCallCount = 0
     private var evalJSCallCount = 0
 
 
+    private val sourceCopy = source?.copy()
+
     private var coroutineContext: CoroutineContext = EmptyCoroutineContext
     private var coroutineContext: CoroutineContext = EmptyCoroutineContext
 
 
     private var loggedNonStandardJSON = false
     private var loggedNonStandardJSON = false
@@ -769,7 +772,7 @@ class AnalyzeRule(
             bindings["java"] = this
             bindings["java"] = this
             bindings["cookie"] = CookieStore
             bindings["cookie"] = CookieStore
             bindings["cache"] = CacheManager
             bindings["cache"] = CacheManager
-            bindings["source"] = source
+            bindings["source"] = sourceCopy
             bindings["book"] = book
             bindings["book"] = book
             bindings["result"] = result
             bindings["result"] = result
             bindings["baseUrl"] = baseUrl
             bindings["baseUrl"] = baseUrl