优化
This commit is contained in:
@@ -33,7 +33,7 @@ import splitties.init.appCtx
|
||||
data class BookChapter(
|
||||
var url: String = "", // 章节地址
|
||||
var title: String = "", // 章节标题
|
||||
var isVolume: Boolean = false, // 是否是卷名
|
||||
var isVolume: Boolean = false, // 是否是卷名
|
||||
var baseUrl: String = "", // 用来拼接相对url
|
||||
var bookUrl: String = "", // 书籍地址
|
||||
var index: Int = 0, // 章节序号
|
||||
|
||||
@@ -11,5 +11,5 @@ data class ContentRule(
|
||||
var sourceRegex: String? = null,
|
||||
var replaceRegex: String? = null, //替换规则
|
||||
var imageStyle: String? = null, //默认大小居中,FULL最大宽度
|
||||
var payAction: String? = null, //购买操作,url/js
|
||||
var payAction: String? = null, //购买操作,js或者包含{{js}}的url
|
||||
) : Parcelable
|
||||
@@ -460,6 +460,7 @@ class AnalyzeUrl(
|
||||
*/
|
||||
suspend fun getByteArrayAwait(): ByteArray {
|
||||
val concurrentRecord = fetchStart()
|
||||
|
||||
@Suppress("RegExpRedundantEscape")
|
||||
val dataUriFindResult = dataUriRegex.find(urlNoQuery)
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
|
||||
@@ -919,21 +919,15 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
if (payAction.isNullOrEmpty()) {
|
||||
throw NoStackTraceException("no pay action")
|
||||
}
|
||||
if (payAction.isAbsUrl()) {
|
||||
payAction
|
||||
} else {
|
||||
source.evalJS(payAction) {
|
||||
put("book", book)
|
||||
put("chapter", chapter)
|
||||
}?.toString()
|
||||
JsUtils.evalJs(payAction) {
|
||||
it["book"] = book
|
||||
it["chapter"] = chapter
|
||||
}
|
||||
}.onSuccess {
|
||||
it?.let {
|
||||
startActivity<WebViewActivity> {
|
||||
putExtra("title", getString(R.string.chapter_pay))
|
||||
putExtra("url", it)
|
||||
IntentData.put(it, ReadBook.bookSource?.getHeaderMap(true))
|
||||
}
|
||||
startActivity<WebViewActivity> {
|
||||
putExtra("title", getString(R.string.chapter_pay))
|
||||
putExtra("url", it)
|
||||
IntentData.put(it, ReadBook.bookSource?.getHeaderMap(true))
|
||||
}
|
||||
}.onError {
|
||||
toastOnUi(it.localizedMessage)
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
import io.legado.app.constant.AppConst.SCRIPT_ENGINE
|
||||
import io.legado.app.constant.AppPattern.EXP_PATTERN
|
||||
import javax.script.SimpleBindings
|
||||
|
||||
object JsUtils {
|
||||
|
||||
fun evalJs(js: String, bindingsFun: ((SimpleBindings) -> Unit)? = null): String {
|
||||
val bindings = SimpleBindings()
|
||||
bindingsFun?.invoke(bindings)
|
||||
if (js.contains("{{") && js.contains("}}")) {
|
||||
val sb = StringBuffer()
|
||||
val expMatcher = EXP_PATTERN.matcher(js)
|
||||
while (expMatcher.find()) {
|
||||
val result = expMatcher.group(1)?.let {
|
||||
SCRIPT_ENGINE.eval(it, bindings)
|
||||
} ?: ""
|
||||
if (result is String) {
|
||||
expMatcher.appendReplacement(sb, result)
|
||||
} else if (result is Double && result % 1.0 == 0.0) {
|
||||
expMatcher.appendReplacement(sb, String.format("%.0f", result))
|
||||
} else {
|
||||
expMatcher.appendReplacement(sb, result.toString())
|
||||
}
|
||||
}
|
||||
expMatcher.appendTail(sb)
|
||||
return sb.toString()
|
||||
}
|
||||
return SCRIPT_ENGINE.eval(js, bindings).toString()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user