From b5a198e8871ea4c8d7d836917deba548487efa59 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Sep 2019 17:23:45 +0800 Subject: [PATCH] up --- .../app/model/analyzeRule/AnalyzeRule.kt | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index c3db2f5ee..cb4ff8a80 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -5,7 +5,6 @@ import androidx.annotation.Keep import io.legado.app.constant.AppConst.SCRIPT_ENGINE import io.legado.app.constant.Pattern.JS_PATTERN import io.legado.app.data.entities.BaseBook -import io.legado.app.help.JsExtensions import io.legado.app.utils.* import java.util.* import java.util.regex.Pattern @@ -516,9 +515,8 @@ class AnalyzeRule(private var book: BaseBook? = null) { @Throws(Exception::class) private fun evalJS(jsStr: String, result: Any?): Any { val bindings = SimpleBindings() - bindings["analyzeRule"] = this + bindings["java"] = this bindings["book"] = book - bindings["java"] = JsExtensions() bindings["result"] = result bindings["baseUrl"] = baseUrl return SCRIPT_ENGINE.eval(jsStr, bindings) @@ -529,4 +527,44 @@ class AnalyzeRule(private var book: BaseBook? = null) { private val getPattern = Pattern.compile("@get:\\{([^}]+?)\\}", Pattern.CASE_INSENSITIVE) } + /** + * js实现跨域访问,不能删 + */ + fun ajax(urlStr: String): String? { + try { + val analyzeUrl = AnalyzeUrl(urlStr, null, null, null, null, null) + val call = analyzeUrl.getResponse() + val response = call.execute() + if (response.body() != null) { + return response.body()!!.toString() + } + } catch (e: Exception) { + return e.localizedMessage + } + + return null + } + + /** + * js实现解码,不能删 + */ + fun base64Decoder(str: String): String { + return Encoder.base64Decoder(str) + } + + /** + * 章节数转数字 + */ + fun toNumChapter(s: String?): String? { + if (s == null) { + return null + } + val pattern = Pattern.compile("(第)(.+?)(章)") + val matcher = pattern.matcher(s) + return if (matcher.find()) { + matcher.group(1) + StringUtils.stringToInt(matcher.group(2)) + matcher.group(3) + } else { + s + } + } }