优化
This commit is contained in:
@@ -11,5 +11,5 @@ data class ContentRule(
|
|||||||
var sourceRegex: String? = null,
|
var sourceRegex: String? = null,
|
||||||
var replaceRegex: String? = null, //替换规则
|
var replaceRegex: String? = null, //替换规则
|
||||||
var imageStyle: String? = null, //默认大小居中,FULL最大宽度
|
var imageStyle: String? = null, //默认大小居中,FULL最大宽度
|
||||||
var payAction: String? = null, //购买操作,url/js
|
var payAction: String? = null, //购买操作,js或者包含{{js}}的url
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
@@ -460,6 +460,7 @@ class AnalyzeUrl(
|
|||||||
*/
|
*/
|
||||||
suspend fun getByteArrayAwait(): ByteArray {
|
suspend fun getByteArrayAwait(): ByteArray {
|
||||||
val concurrentRecord = fetchStart()
|
val concurrentRecord = fetchStart()
|
||||||
|
|
||||||
@Suppress("RegExpRedundantEscape")
|
@Suppress("RegExpRedundantEscape")
|
||||||
val dataUriFindResult = dataUriRegex.find(urlNoQuery)
|
val dataUriFindResult = dataUriRegex.find(urlNoQuery)
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
@Suppress("BlockingMethodInNonBlockingContext")
|
||||||
|
|||||||
@@ -919,22 +919,16 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
if (payAction.isNullOrEmpty()) {
|
if (payAction.isNullOrEmpty()) {
|
||||||
throw NoStackTraceException("no pay action")
|
throw NoStackTraceException("no pay action")
|
||||||
}
|
}
|
||||||
if (payAction.isAbsUrl()) {
|
JsUtils.evalJs(payAction) {
|
||||||
payAction
|
it["book"] = book
|
||||||
} else {
|
it["chapter"] = chapter
|
||||||
source.evalJS(payAction) {
|
|
||||||
put("book", book)
|
|
||||||
put("chapter", chapter)
|
|
||||||
}?.toString()
|
|
||||||
}
|
}
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
it?.let {
|
|
||||||
startActivity<WebViewActivity> {
|
startActivity<WebViewActivity> {
|
||||||
putExtra("title", getString(R.string.chapter_pay))
|
putExtra("title", getString(R.string.chapter_pay))
|
||||||
putExtra("url", it)
|
putExtra("url", it)
|
||||||
IntentData.put(it, ReadBook.bookSource?.getHeaderMap(true))
|
IntentData.put(it, ReadBook.bookSource?.getHeaderMap(true))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}.onError {
|
}.onError {
|
||||||
toastOnUi(it.localizedMessage)
|
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