pull/49/head
kunfei 5 years ago
parent 5c429c150c
commit db3641085c
  1. 4
      app/src/main/java/io/legado/app/constant/AppConst.kt
  2. 6
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  3. 4
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  4. 7
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  5. 33
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  6. 6
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  7. 53
      app/src/main/res/drawable-v24/ic_launcher_foreground.xml

@ -33,6 +33,10 @@ object AppConst {
SimpleDateFormat("HH:mm") SimpleDateFormat("HH:mm")
} }
val DATE_FORMAT: SimpleDateFormat by lazy {
SimpleDateFormat("YY-MM-DD HH:mm")
}
val keyboardToolChars: List<String> by lazy { val keyboardToolChars: List<String> by lazy {
arrayListOf( arrayListOf(
"@", "&", "|", "%", "/", ":", "[", "]", "{", "}", "<", ">", "\\", "$", "#", "!", ".", "@", "&", "|", "%", "/", ":", "[", "]", "{", "}", "<", ">", "\\", "$", "#", "!", ".",

@ -45,7 +45,7 @@ data class BookSource(
var ruleBookInfo: String? = null, // 书籍信息页规则 var ruleBookInfo: String? = null, // 书籍信息页规则
var ruleToc: String? = null, // 目录页规则 var ruleToc: String? = null, // 目录页规则
var ruleContent: String? = null // 正文页规则 var ruleContent: String? = null // 正文页规则
) : Parcelable { ) : Parcelable, JsExtensions {
@Ignore @Ignore
@IgnoredOnParcel @IgnoredOnParcel
private var searchRuleV: SearchRule? = null private var searchRuleV: SearchRule? = null
@ -137,7 +137,7 @@ data class BookSource(
if (a.isBlank()) { if (a.isBlank()) {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["baseUrl"] = bookSourceUrl bindings["baseUrl"] = bookSourceUrl
bindings["java"] = JsExtensions bindings["java"] = this
a = AppConst.SCRIPT_ENGINE.eval( a = AppConst.SCRIPT_ENGINE.eval(
it.substring(4, it.lastIndexOf("<")), it.substring(4, it.lastIndexOf("<")),
bindings bindings
@ -165,7 +165,7 @@ data class BookSource(
@Throws(Exception::class) @Throws(Exception::class)
private fun evalJS(jsStr: String): Any { private fun evalJS(jsStr: String): Any {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["java"] = JsExtensions bindings["java"] = this
return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings) return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings)
} }

@ -37,7 +37,7 @@ data class RssSource(
var enableJs: Boolean = false, var enableJs: Boolean = false,
var loadWithBaseUrl: Boolean = false, var loadWithBaseUrl: Boolean = false,
var customOrder: Int = 0 var customOrder: Int = 0
) : Parcelable { ) : Parcelable, JsExtensions {
@Throws(Exception::class) @Throws(Exception::class)
fun getHeaderMap(): Map<String, String> { fun getHeaderMap(): Map<String, String> {
@ -64,7 +64,7 @@ data class RssSource(
@Throws(Exception::class) @Throws(Exception::class)
private fun evalJS(jsStr: String): Any { private fun evalJS(jsStr: String): Any {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["java"] = JsExtensions bindings["java"] = this
return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings) return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings)
} }

@ -1,13 +1,15 @@
package io.legado.app.help package io.legado.app.help
import android.util.Base64 import android.util.Base64
import io.legado.app.constant.AppConst.DATE_FORMAT
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.EncoderUtils import io.legado.app.utils.EncoderUtils
import io.legado.app.utils.MD5Utils import io.legado.app.utils.MD5Utils
import java.util.*
@Suppress("unused") @Suppress("unused")
object JsExtensions { interface JsExtensions {
/** /**
* js实现跨域访问,不能删 * js实现跨域访问,不能删
@ -46,4 +48,7 @@ object JsExtensions {
return MD5Utils.md5Encode16(str) return MD5Utils.md5Encode16(str)
} }
fun timeFormat(time: Long): String {
return DATE_FORMAT.format(Date(time))
}
} }

@ -1,12 +1,12 @@
package io.legado.app.model.analyzeRule package io.legado.app.model.analyzeRule
import android.text.TextUtils import android.text.TextUtils
import android.util.Base64
import androidx.annotation.Keep import androidx.annotation.Keep
import io.legado.app.constant.AppConst.SCRIPT_ENGINE import io.legado.app.constant.AppConst.SCRIPT_ENGINE
import io.legado.app.constant.Pattern.JS_PATTERN import io.legado.app.constant.Pattern.JS_PATTERN
import io.legado.app.data.entities.BaseBook import io.legado.app.data.entities.BaseBook
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.JsExtensions
import io.legado.app.utils.* import io.legado.app.utils.*
import org.mozilla.javascript.NativeObject import org.mozilla.javascript.NativeObject
import java.util.* import java.util.*
@ -21,7 +21,7 @@ import kotlin.collections.HashMap
*/ */
@Keep @Keep
@Suppress("unused") @Suppress("unused")
class AnalyzeRule(var book: BaseBook? = null) { class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
var chapter: BookChapter? = null var chapter: BookChapter? = null
private var content: Any? = null private var content: Any? = null
private var baseUrl: String? = null private var baseUrl: String? = null
@ -291,9 +291,7 @@ class AnalyzeRule(var book: BaseBook? = null) {
@Throws(Exception::class) @Throws(Exception::class)
private fun putRule(map: Map<String, String>) { private fun putRule(map: Map<String, String>) {
for ((key, value) in map) { for ((key, value) in map) {
getString(value)?.let { put(key, getString(value))
put(key, it)
}
} }
} }
@ -595,7 +593,7 @@ class AnalyzeRule(var book: BaseBook? = null) {
/** /**
* js实现跨域访问,不能删 * js实现跨域访问,不能删
*/ */
fun ajax(urlStr: String): String? { override fun ajax(urlStr: String): String? {
return try { return try {
val analyzeUrl = AnalyzeUrl(urlStr, null, null, null, baseUrl, book) val analyzeUrl = AnalyzeUrl(urlStr, null, null, null, baseUrl, book)
val call = analyzeUrl.getResponse() 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)
}
/** /**
* 章节数转数字 * 章节数转数字
*/ */

@ -40,7 +40,7 @@ class AnalyzeUrl(
baseUrl: String? = null, baseUrl: String? = null,
book: BaseBook? = null, book: BaseBook? = null,
var useWebView: Boolean = false var useWebView: Boolean = false
) { ) : JsExtensions {
companion object { companion object {
private val pagePattern = Pattern.compile("<(.*?)>") private val pagePattern = Pattern.compile("<(.*?)>")
private val jsonType = "application/json; charset=utf-8".toMediaTypeOrNull() private val jsonType = "application/json; charset=utf-8".toMediaTypeOrNull()
@ -130,7 +130,7 @@ class AnalyzeUrl(
var jsEval: Any var jsEval: Any
val sb = StringBuffer(ruleUrl.length) val sb = StringBuffer(ruleUrl.length)
val simpleBindings = SimpleBindings() val simpleBindings = SimpleBindings()
simpleBindings["java"] = JsExtensions simpleBindings["java"] = this
simpleBindings["baseUrl"] = baseUrl simpleBindings["baseUrl"] = baseUrl
simpleBindings["page"] = page simpleBindings["page"] = page
simpleBindings["key"] = key simpleBindings["key"] = key
@ -233,7 +233,7 @@ class AnalyzeUrl(
book: BaseBook? book: BaseBook?
): Any { ): Any {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["java"] = JsExtensions bindings["java"] = this
bindings["page"] = page bindings["page"] = page
bindings["key"] = key bindings["key"] = key
bindings["book"] = book bindings["book"] = book

@ -1,9 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="108dp"
android:height="24dp" android:height="108dp"
android:viewportWidth="24.0" android:viewportWidth="108"
android:viewportHeight="24.0"> android:viewportHeight="108">
<path <path
android:fillColor="#BB7306" android:fillColor="#d81e06"
android:pathData="M12,11.55C9.64,9.35 6.48,8 3,8v11c3.48,0 6.64,1.35 9,3.55 2.36,-2.19 5.52,-3.55 9,-3.55V8c-3.48,0 -6.64,1.35 -9,3.55zM12,8c1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3 1.34,3 3,3z" /> android:pathData="M 53.86 49.62 H 54.27 V 49.68 H 53.86 V 49.62 Z" />
<path
android:fillColor="#d81e06"
android:pathData="M49.31,73.17c1.84 0.3 ,3.35 0.63 ,4.4 0.87 a14.46,14.46,0,0,0-7.2-3.28c-2.11-0.28-4.07,0-6.95-1.14a8.66,8.66,0,0,1-2.64-1.54,9.38,9.38,0,0,1-2.54-4.27c-0.66-1.8-1.63-4.34-3-7.7L28,57.91c3.72,9.3,7.45,18.4,8,18.93a10.09,10.09,0,0,1,4.69-3.93C42.76,72.09,45,72.48,49.31,73.17Zm0,0" />
<group>
<clip-path android:pathData="M 21.5 37.04 H 86.64 V 76.92 H 21.5 V 37.04 Z" />
<path
android:fillColor="#d81e06"
android:pathData="M71,68.23c-0.8 0.56 -1.23 0.48 -4.29,1l-0.26 0.05 a60,60,0,0,0-6.06,1.34,15.69,15.69,0,0,0-5.78,3.51c0.41-0.28,6.61-4.43,12.73-1.61a11.63,11.63,0,0,1,4.78,4.19c0.53-0.51,4.07-9.11,7.68-18.13l-0.12-0.05a15.32,15.32,0,0,1-3.5-1.93c-1.08,2.59-1.87,4.72-2.4,6.19C72.61,66.08,72.32,67.32,71,68.23ZM71.57,73" />
<path
android:fillColor="#d81e06"
android:pathData="M53.61,49.74l0,0c-1.36-1.58-13.71-15.3-28-12A12.21,12.21,0,0,0,27,40.77l2.48-0.07-1.28-2.25h0.08c4.15-0.67,9.7,1.54,14.55,4.18a88.44,88.44,0,0,1,9.57,6.17l0.76 0.57 -0.06 0.1 0.22 0.13 0.12 0.07 -0.14,0a0.2 0.2 ,0,0,0-0.09 0.18 l0.7,23c0,0.1 0.06 0.18 0.12 0.18h0.12s0.11-0.08 0.11 -0.18l0.7-23c0-0.09,0-0.15-0.11-0.15H54.6l0.18-0.11a95.49,95.49,0,0,1,16.48-4.51c5.71-1,8.1-0.88,8.85 0.37 s-0.29,3.13-1.14,4.43c0.55 0.23 ,1.12 0.47 ,1.72 0.7 s1.36 0.5 ,2,0.71c1.54-3.9,3-7.47,3.94-10-15.31-1.55-28,5.73-31.48,8l-0.07-0.1a41,41,0,0,1,10.78-7,51.37,51.37,0,0,1,8.93-2.9c2-0.49,3.72-0.79,5-1l-1.19,2.26,2.47 0.06 L82.63,37A39.6,39.6,0,0,0,63.7,41.83,39,39,0,0,0,53.61,49.74Zm0,0" />
<path
android:fillColor="#d81e06"
android:pathData="M33.37,44.74a28.2,28.2,0,0,1,4,0.5C44.08,46.78,52.9,49.73,53,49.41S46.72,45,37.66,42.84a54.46,54.46,0,0,0-16.17-1.4c0.54,1.38,1.08,2.77,1.63,4.15 0.61 ,1.56,1.29,3.28,2,5.08l0.95-0.22c1-0.24,2-0.5,2.88-0.79-0.19-0.33-1.65-3-0.63-4.29C29,44.48,30.46,44.56,33.37,44.74Z" />
</group>
<path
android:fillColor="#d81e06"
android:pathData="M23.25,52.12a0.86 0.86 ,0,0,0,0.23 0.7 c0.26 0.31 0.62 0.44 0.74 0.37 A15.06,15.06,0,0,1,29,51.56c0.25-0.06,1-0.29 0.91 -0.62s-0.76-0.54-1.3-0.54l-0.42,0h-0.08a15.11,15.11,0,0,0-4.12 0.89 ,1.32,1.32,0,0,0-0.69 0.81 Zm0,0" />
<path
android:fillColor="#d81e06"
android:pathData="M23.79,54.37c0.13 0.47 0.38 0.71 0.73 0.71 a1,1,0,0,0,0.51-0.16l0.06,0a10.12,10.12,0,0,1,4.27-1.47c1-0.12,2.21-0.63,2.16-1.09,0-0.15-0.06-0.62-1.05-0.62a7.75,7.75,0,0,0-1.64 0.25 ,29.36,29.36,0,0,0-4.46,1.42c-0.26 0.11 -0.71 0.53 -0.58,1Zm0,0" />
<path
android:fillColor="#d81e06"
android:pathData="M30,53.69h-0.07a15.85,15.85,0,0,0-4.7,1.43,1.13,1.13,0,0,0-0.59 0.8 0.91 0.91 ,0,0,0,0.23 0.72 0.85 0.85 ,0,0,0,0.57 0.26 0.27 0.27 ,0,0,0,0.13,0A10.37,10.37,0,0,0,27.36,56a9.55,9.55,0,0,1,1.6-0.78l0.16,0c1.66-0.44,1.87-0.78,1.85-1a0.62 0.62 ,0,0,0-0.7-0.59l-0.27,0Zm0,0" />
<path
android:fillColor="#d81e06"
android:pathData="M28.84,55.73h0a9.13,9.13,0,0,0-2.12,1.14l-0.52 0.33 a0.46 0.46 ,0,0,0-0.23 0.26 0.43 0.43 ,0,0,0,0.1 0.32 c0.21 0.31 0.37 0.34 0.48 0.34 a1,1,0,0,0,0.33-0.08,1,1,0,0,1,0.24-0.09,3.89,3.89,0,0,0,1.75-0.91,4.55,4.55,0,0,1,0.64-0.47l0.06,0c0.15-0.09 0.57 -0.32 0.63 -0.62a0.46 0.46 ,0,0,0-0.12-0.36 0.33 0.33,0,0,0-0.24-0.06,3.37,3.37,0,0,0-1,0.23Zm0,0" />
<path
android:fillColor="#d81e06"
android:pathData="M79.26,50.71a5.25,5.25,0,0,0-0.72-0.06c-0.42,0-0.94 0.08 -1,0.45s0.61 0.61 0.87 0.69 a15.1,15.1,0,0,1,4.6,2,0.16 0.16 ,0,0,0,0.11,0,1.08,1.08,0,0,0,0.68-0.37 0.87 0.87,0,0,0,0.25-0.65,1.34,1.34,0,0,0-0.63-0.86,14.76,14.76,0,0,0-4-1.18Zm0,0" />
<path
android:fillColor="#d81e06"
android:pathData="M82.8,53.93a31.94,31.94,0,0,0-4.34-1.74,7,7,0,0,0-1.83-0.37c-0.71,0-0.85 0.32 -0.89 0.55 -0.08 0.46 ,1.07,1.05,2.08,1.24A10.06,10.06,0,0,1,82,55.39l0.06,0a1,1,0,0,0,0.55 0.19 c0.32,0,0.57-0.22 0.73 -0.66s-0.26-0.89-0.51-1Zm0,0" />
<path
android:fillColor="#d81e06"
android:pathData="M81.81,55.62a15.51,15.51,0,0,0-4.58-1.77h-0.07a1.69,1.69,0,0,0-0.35,0,0.61 0.61 ,0,0,0-0.66 0.54 c0,0.16 0.15 0.52,1.78,1.08l0.16 0.06 a10.82,10.82,0,0,1,1.54 0.89 ,10.21,10.21,0,0,0,1.72,1,0.4 0.4 ,0,0,0,0.17,0,0.88 0.88 ,0,0,0,0.83-0.93,1.11,1.11,0,0,0-0.54-0.83Zm0,0" />
<path
android:fillColor="#d81e06"
android:pathData="M78.2,56l0,0a2.84,2.84,0,0,0-1-0.3 0.3 0.3,0,0,0-0.19 0.05 0.44 0.44 ,0,0,0-0.14 0.35 c0,0.3 0.44 0.57 0.59 0.67l0,0a5.8,5.8,0,0,1,0.61 0.52 ,3.86,3.86,0,0,0,1.68,1,0.94 0.94 ,0,0,1,0.23 0.1 ,1,1,0,0,0,0.35 0.11 0.65 0.65 ,0,0,0,0.48-0.31 0.42 0.42,0,0,0,0.12-0.31 0.52 0.52,0,0,0-0.21-0.28l-0.49-0.36a9.24,9.24,0,0,0-2-1.29Zm0,0" />
</vector> </vector>
Loading…
Cancel
Save