pull/48/head
kunfei 5 years ago
parent fa010e9a70
commit 390761c089
  1. 6
      app/src/main/java/io/legado/app/model/WebBook.kt
  2. 19
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt

@ -96,7 +96,7 @@ class WebBook(val bookSource: BookSource) {
baseUrl = sourceUrl, baseUrl = sourceUrl,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
if (analyzeUrl.useWebView()) { if (analyzeUrl.useWebView) {
analyzeUrl.getResultByWebView(bookSource.bookSourceUrl) analyzeUrl.getResultByWebView(bookSource.bookSourceUrl)
} else { } else {
analyzeUrl.getResponseAwait().body() analyzeUrl.getResponseAwait().body()
@ -126,7 +126,7 @@ class WebBook(val bookSource: BookSource) {
baseUrl = book.bookUrl, baseUrl = book.bookUrl,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
if (analyzeUrl.useWebView()) { if (analyzeUrl.useWebView) {
analyzeUrl.getResultByWebView(bookSource.bookSourceUrl) analyzeUrl.getResultByWebView(bookSource.bookSourceUrl)
} else { } else {
analyzeUrl.getResponseAwait().body() analyzeUrl.getResponseAwait().body()
@ -160,7 +160,7 @@ class WebBook(val bookSource: BookSource) {
baseUrl = book.tocUrl, baseUrl = book.tocUrl,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
if (analyzeUrl.useWebView()) { if (analyzeUrl.useWebView) {
analyzeUrl.getResultByWebView(bookSource.bookSourceUrl) analyzeUrl.getResultByWebView(bookSource.bookSourceUrl)
} else { } else {
analyzeUrl.getResponseAwait().body() analyzeUrl.getResponseAwait().body()

@ -57,8 +57,8 @@ class AnalyzeUrl(
private var bodyTxt: String? = null private var bodyTxt: String? = null
private var body: RequestBody? = null private var body: RequestBody? = null
private var method = RequestMethod.GET private var method = RequestMethod.GET
private var webViewJs: String? = null var useWebView: Boolean = false
private var sourceRegex: String? = null private set
init { init {
baseUrl?.let { baseUrl?.let {
@ -170,8 +170,7 @@ class AnalyzeUrl(
} }
options["body"]?.let { bodyTxt = it } options["body"]?.let { bodyTxt = it }
options["charset"]?.let { charset = it } options["charset"]?.let { charset = it }
options["js"]?.let { webViewJs = it } options["webView"]?.let { if (it.isNotEmpty()) useWebView = true }
options["sourceRegex"]?.let { sourceRegex = it }
} }
} }
when (method) { when (method) {
@ -292,16 +291,16 @@ class AnalyzeUrl(
} }
} }
fun useWebView(): Boolean { suspend fun getResultByWebView(
return webViewJs != null || sourceRegex != null tag: String,
} jsStr: String? = null,
sourceRegex: String? = null
suspend fun getResultByWebView(tag: String): String { ): String {
val params = AjaxWebView.AjaxParams(tag) val params = AjaxWebView.AjaxParams(tag)
params.url = url params.url = url
params.headerMap = headerMap params.headerMap = headerMap
params.requestMethod = method params.requestMethod = method
params.javaScript = webViewJs params.javaScript = jsStr
params.sourceRegex = sourceRegex params.sourceRegex = sourceRegex
params.postData = bodyTxt?.toByteArray() params.postData = bodyTxt?.toByteArray()
return HttpHelper.ajax(params) return HttpHelper.ajax(params)

Loading…
Cancel
Save