diff --git a/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt b/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt index f0243a3e4b35..09b4c368b1e2 100644 --- a/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt +++ b/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt @@ -5,7 +5,6 @@ import android.net.http.SslError import android.os.Handler import android.os.Looper import android.util.AndroidRuntimeException -import android.util.Log import android.webkit.CookieManager import android.webkit.SslErrorHandler import android.webkit.WebResourceRequest @@ -19,7 +18,6 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.utils.runOnUI import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Runnable -import kotlinx.coroutines.delay import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.withTimeout import org.apache.commons.text.StringEscapeUtils @@ -40,7 +38,7 @@ class BackstageWebView( private val sourceRegex: String? = null, private val overrideUrlRegex: String? = null, private val javaScript: String? = null, - private val delayTime: Long = 1000, + private val delayTime: Long = 0, ) { private val mHandler = Handler(Looper.getMainLooper()) @@ -149,13 +147,11 @@ class BackstageWebView( override fun onPageFinished(view: WebView, url: String) { setCookie(url) - mHandler.postDelayed({ - if (runnable == null) { - runnable = EvalJsRunnable(view, url, getJs()) - } - mHandler.removeCallbacks(runnable!!) - mHandler.postDelayed(runnable!!, 1000) - }, delayTime) + if (runnable == null) { + runnable = EvalJsRunnable(view, url, getJs()) + } + mHandler.removeCallbacks(runnable!!) + mHandler.postDelayed(runnable!!, 1000 + delayTime) } @SuppressLint("WebViewClientOnReceivedSslError") @@ -182,7 +178,6 @@ class BackstageWebView( private fun handleResult(result: String) = Coroutine.async { if (result.isNotEmpty() && result != "null") { - Log.d("BackstageWebView", "result: $result") val content = StringEscapeUtils.unescapeJson(result) .replace(quoteRegex, "") try { @@ -262,12 +257,10 @@ class BackstageWebView( override fun onPageFinished(webView: WebView, url: String) { setCookie(url) - mHandler.postDelayed({ - if (!javaScript.isNullOrEmpty()) { - val runnable = LoadJsRunnable(webView, javaScript) - mHandler.postDelayed(runnable, 1000L) - } - }, delayTime) + if (!javaScript.isNullOrEmpty()) { + val runnable = LoadJsRunnable(webView, javaScript) + mHandler.postDelayed(runnable, 1000L + delayTime) + } } @SuppressLint("WebViewClientOnReceivedSslError") diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index a1930392b6e9..b8a4a1c12a78 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -21,9 +21,31 @@ import io.legado.app.help.JsExtensions import io.legado.app.help.config.AppConfig import io.legado.app.help.exoplayer.ExoPlayerHelper import io.legado.app.help.glide.GlideHeaders -import io.legado.app.help.http.* +import io.legado.app.help.http.BackstageWebView +import io.legado.app.help.http.CookieManager import io.legado.app.help.http.CookieManager.mergeCookies -import io.legado.app.utils.* +import io.legado.app.help.http.CookieStore +import io.legado.app.help.http.RequestMethod +import io.legado.app.help.http.StrResponse +import io.legado.app.help.http.addHeaders +import io.legado.app.help.http.get +import io.legado.app.help.http.getProxyClient +import io.legado.app.help.http.newCallResponse +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.utils.EncoderUtils +import io.legado.app.utils.GSON +import io.legado.app.utils.NetworkUtils +import io.legado.app.utils.fromJsonArray +import io.legado.app.utils.fromJsonObject +import io.legado.app.utils.get +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 io.legado.app.utils.splitNotBlank import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import okhttp3.MediaType.Companion.toMediaType @@ -87,7 +109,7 @@ class AnalyzeUrl( private var webJs: String? = null private val enabledCookieJar = source?.enabledCookieJar ?: false private val domain: String - private var delayTime: Long? = null + private var webViewDelayTime: Long = 0 // 服务器ID var serverID: Long? = null @@ -216,7 +238,7 @@ class AnalyzeUrl( } } serverID = option.getServerID() - delayTime = option.getDelayTime() + webViewDelayTime = max(0, option.getWebViewDelayTime() ?: 0) } } urlNoQuery = url @@ -436,7 +458,7 @@ class AnalyzeUrl( javaScript = webJs ?: jsStr, sourceRegex = sourceRegex, headerMap = headerMap, - delayTime = delayTime ?:1000 + delayTime = webViewDelayTime ).getStrResponse() } @@ -446,7 +468,7 @@ class AnalyzeUrl( javaScript = webJs ?: jsStr, sourceRegex = sourceRegex, headerMap = headerMap, - delayTime = delayTime ?:1000 + delayTime = webViewDelayTime ).getStrResponse() } } else { @@ -712,7 +734,7 @@ class AnalyzeUrl( /** * webview等待页面加载完毕的延迟时间(毫秒) */ - private var delayTime: Long? = null, + private var webViewDelayTime: Long? = null, ) { fun setMethod(value: String?) { method = if (value.isNullOrBlank()) null else value @@ -820,12 +842,12 @@ class AnalyzeUrl( return serverID } - fun setDelayTime(value: String?) { - delayTime = if (value.isNullOrBlank()) null else value.toLong() + fun setWebViewDelayTime(value: String?) { + webViewDelayTime = if (value.isNullOrBlank()) null else value.toLong() } - fun getDelayTime(): Long? { - return delayTime + fun getWebViewDelayTime(): Long? { + return webViewDelayTime } }