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