diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index 00d744fce..59588192f 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -33,6 +33,10 @@ object AppConst { SimpleDateFormat("HH:mm") } + val DATE_FORMAT: SimpleDateFormat by lazy { + SimpleDateFormat("YY-MM-DD HH:mm") + } + val keyboardToolChars: List by lazy { arrayListOf( "@", "&", "|", "%", "/", ":", "[", "]", "{", "}", "<", ">", "\\", "$", "#", "!", ".", diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index f0213082b..d5c5a0f2c 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -45,7 +45,7 @@ data class BookSource( var ruleBookInfo: String? = null, // 书籍信息页规则 var ruleToc: String? = null, // 目录页规则 var ruleContent: String? = null // 正文页规则 -) : Parcelable { +) : Parcelable, JsExtensions { @Ignore @IgnoredOnParcel private var searchRuleV: SearchRule? = null @@ -137,7 +137,7 @@ data class BookSource( if (a.isBlank()) { val bindings = SimpleBindings() bindings["baseUrl"] = bookSourceUrl - bindings["java"] = JsExtensions + bindings["java"] = this a = AppConst.SCRIPT_ENGINE.eval( it.substring(4, it.lastIndexOf("<")), bindings @@ -165,7 +165,7 @@ data class BookSource( @Throws(Exception::class) private fun evalJS(jsStr: String): Any { val bindings = SimpleBindings() - bindings["java"] = JsExtensions + bindings["java"] = this return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings) } diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index a5c3b34db..261611caf 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -37,7 +37,7 @@ data class RssSource( var enableJs: Boolean = false, var loadWithBaseUrl: Boolean = false, var customOrder: Int = 0 -) : Parcelable { +) : Parcelable, JsExtensions { @Throws(Exception::class) fun getHeaderMap(): Map { @@ -64,7 +64,7 @@ data class RssSource( @Throws(Exception::class) private fun evalJS(jsStr: String): Any { val bindings = SimpleBindings() - bindings["java"] = JsExtensions + bindings["java"] = this return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings) } diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index e615ad435..0160000f7 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -1,13 +1,15 @@ package io.legado.app.help import android.util.Base64 +import io.legado.app.constant.AppConst.DATE_FORMAT import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.EncoderUtils import io.legado.app.utils.MD5Utils +import java.util.* @Suppress("unused") -object JsExtensions { +interface JsExtensions { /** * js实现跨域访问,不能删 @@ -46,4 +48,7 @@ object JsExtensions { return MD5Utils.md5Encode16(str) } + fun timeFormat(time: Long): String { + return DATE_FORMAT.format(Date(time)) + } } 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 adc7a3384..c2ed7c8da 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 @@ -1,12 +1,12 @@ package io.legado.app.model.analyzeRule import android.text.TextUtils -import android.util.Base64 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.data.entities.BookChapter +import io.legado.app.help.JsExtensions import io.legado.app.utils.* import org.mozilla.javascript.NativeObject import java.util.* @@ -21,7 +21,7 @@ import kotlin.collections.HashMap */ @Keep @Suppress("unused") -class AnalyzeRule(var book: BaseBook? = null) { +class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { var chapter: BookChapter? = null private var content: Any? = null private var baseUrl: String? = null @@ -291,9 +291,7 @@ class AnalyzeRule(var book: BaseBook? = null) { @Throws(Exception::class) private fun putRule(map: Map) { for ((key, value) in map) { - getString(value)?.let { - put(key, it) - } + put(key, getString(value)) } } @@ -595,7 +593,7 @@ class AnalyzeRule(var book: BaseBook? = null) { /** * js实现跨域访问,不能删 */ - fun ajax(urlStr: String): String? { + override fun ajax(urlStr: String): String? { return try { val analyzeUrl = AnalyzeUrl(urlStr, null, null, null, baseUrl, book) val call = analyzeUrl.getResponse() @@ -606,29 +604,6 @@ class AnalyzeRule(var book: BaseBook? = null) { } } - /** - * js实现解码,不能删 - */ - fun base64Decode(str: String): String { - return EncoderUtils.base64Decode(str) - } - - fun base64Encode(str: String): String? { - return EncoderUtils.base64Encode(str) - } - - fun base64Encode(str: String, flags: Int = Base64.NO_WRAP): String? { - return EncoderUtils.base64Encode(str, flags) - } - - fun md5Encode(str: String): String? { - return MD5Utils.md5Encode(str) - } - - fun md5Encode16(str: String): String? { - return MD5Utils.md5Encode16(str) - } - /** * 章节数转数字 */ 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 b776e2b31..bf8aded6d 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 @@ -40,7 +40,7 @@ class AnalyzeUrl( baseUrl: String? = null, book: BaseBook? = null, var useWebView: Boolean = false -) { +) : JsExtensions { companion object { private val pagePattern = Pattern.compile("<(.*?)>") private val jsonType = "application/json; charset=utf-8".toMediaTypeOrNull() @@ -130,7 +130,7 @@ class AnalyzeUrl( var jsEval: Any val sb = StringBuffer(ruleUrl.length) val simpleBindings = SimpleBindings() - simpleBindings["java"] = JsExtensions + simpleBindings["java"] = this simpleBindings["baseUrl"] = baseUrl simpleBindings["page"] = page simpleBindings["key"] = key @@ -233,7 +233,7 @@ class AnalyzeUrl( book: BaseBook? ): Any { val bindings = SimpleBindings() - bindings["java"] = JsExtensions + bindings["java"] = this bindings["page"] = page bindings["key"] = key bindings["book"] = book diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml index b8c095f44..26ba6db03 100644 --- a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -1,9 +1,50 @@ + - - + android:width="108dp" + android:height="108dp" + android:viewportWidth="108" + android:viewportHeight="108"> + + + + + + + + + + + + + + + + + + \ No newline at end of file