From 390761c08973f294592d66bf1b19dd502fc126c1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 6 Nov 2019 12:40:24 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/model/WebBook.kt | 6 +++--- .../app/model/analyzeRule/AnalyzeUrl.kt | 19 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/WebBook.kt b/app/src/main/java/io/legado/app/model/WebBook.kt index e57adeefe..b24865544 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -96,7 +96,7 @@ class WebBook(val bookSource: BookSource) { baseUrl = sourceUrl, headerMapF = bookSource.getHeaderMap() ) - if (analyzeUrl.useWebView()) { + if (analyzeUrl.useWebView) { analyzeUrl.getResultByWebView(bookSource.bookSourceUrl) } else { analyzeUrl.getResponseAwait().body() @@ -126,7 +126,7 @@ class WebBook(val bookSource: BookSource) { baseUrl = book.bookUrl, headerMapF = bookSource.getHeaderMap() ) - if (analyzeUrl.useWebView()) { + if (analyzeUrl.useWebView) { analyzeUrl.getResultByWebView(bookSource.bookSourceUrl) } else { analyzeUrl.getResponseAwait().body() @@ -160,7 +160,7 @@ class WebBook(val bookSource: BookSource) { baseUrl = book.tocUrl, headerMapF = bookSource.getHeaderMap() ) - if (analyzeUrl.useWebView()) { + if (analyzeUrl.useWebView) { analyzeUrl.getResultByWebView(bookSource.bookSourceUrl) } else { analyzeUrl.getResponseAwait().body() 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 262e3d1c5..c52014ca9 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 @@ -57,8 +57,8 @@ class AnalyzeUrl( private var bodyTxt: String? = null private var body: RequestBody? = null private var method = RequestMethod.GET - private var webViewJs: String? = null - private var sourceRegex: String? = null + var useWebView: Boolean = false + private set init { baseUrl?.let { @@ -170,8 +170,7 @@ class AnalyzeUrl( } options["body"]?.let { bodyTxt = it } options["charset"]?.let { charset = it } - options["js"]?.let { webViewJs = it } - options["sourceRegex"]?.let { sourceRegex = it } + options["webView"]?.let { if (it.isNotEmpty()) useWebView = true } } } when (method) { @@ -292,16 +291,16 @@ class AnalyzeUrl( } } - fun useWebView(): Boolean { - return webViewJs != null || sourceRegex != null - } - - suspend fun getResultByWebView(tag: String): String { + suspend fun getResultByWebView( + tag: String, + jsStr: String? = null, + sourceRegex: String? = null + ): String { val params = AjaxWebView.AjaxParams(tag) params.url = url params.headerMap = headerMap params.requestMethod = method - params.javaScript = webViewJs + params.javaScript = jsStr params.sourceRegex = sourceRegex params.postData = bodyTxt?.toByteArray() return HttpHelper.ajax(params)