mirror of
https://github.com/gedoor/legado.git
synced 2024-09-03 09:55:00 +08:00
优化
This commit is contained in:
parent
218e56bf98
commit
2e7ce425a6
@ -14,7 +14,6 @@
|
||||
**2023/03/24**
|
||||
|
||||
* 更新cronet: 111.0.5563.115
|
||||
* 更新到 rhino-1.7.14.1
|
||||
* 修复bug
|
||||
* 其中一些更新由 Xwite, Horis提供
|
||||
|
||||
|
@ -4,8 +4,6 @@ import android.annotation.SuppressLint
|
||||
import android.content.pm.PackageManager
|
||||
import android.provider.Settings
|
||||
import androidx.annotation.Keep
|
||||
import com.script.rhino.RhinoScriptEngine
|
||||
|
||||
import io.legado.app.BuildConfig
|
||||
import io.legado.app.utils.channel
|
||||
import splitties.init.appCtx
|
||||
@ -28,10 +26,6 @@ object AppConst {
|
||||
|
||||
const val DEFAULT_WEBDAV_ID = -1L
|
||||
|
||||
val SCRIPT_ENGINE: RhinoScriptEngine by lazy {
|
||||
RhinoScriptEngine()
|
||||
}
|
||||
|
||||
val timeFormat: SimpleDateFormat by lazy {
|
||||
SimpleDateFormat("HH:mm")
|
||||
}
|
||||
|
7
app/src/main/java/io/legado/app/constant/ScriptEngine.kt
Normal file
7
app/src/main/java/io/legado/app/constant/ScriptEngine.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package io.legado.app.constant
|
||||
|
||||
import com.script.rhino.RhinoScriptEngine
|
||||
|
||||
val SCRIPT_ENGINE: RhinoScriptEngine by lazy {
|
||||
RhinoScriptEngine()
|
||||
}
|
@ -4,6 +4,7 @@ import cn.hutool.crypto.symmetric.AES
|
||||
import com.script.SimpleBindings
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.SCRIPT_ENGINE
|
||||
import io.legado.app.data.entities.rule.RowUi
|
||||
import io.legado.app.help.CacheManager
|
||||
import io.legado.app.help.JsExtensions
|
||||
@ -227,6 +228,6 @@ interface BaseSource : JsExtensions {
|
||||
bindings["baseUrl"] = getKey()
|
||||
bindings["cookie"] = CookieStore
|
||||
bindings["cache"] = CacheManager
|
||||
return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings)
|
||||
return SCRIPT_ENGINE.eval(jsStr, bindings)
|
||||
}
|
||||
}
|
@ -4,10 +4,7 @@ package io.legado.app.help.book
|
||||
|
||||
import android.net.Uri
|
||||
import com.script.SimpleBindings
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.BookSourceType
|
||||
import io.legado.app.constant.BookType
|
||||
import io.legado.app.constant.*
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.BaseBook
|
||||
import io.legado.app.data.entities.Book
|
||||
@ -241,7 +238,7 @@ fun Book.getExportFileName(suffix: String): String {
|
||||
bindings["name"] = name
|
||||
bindings["author"] = getRealAuthor()
|
||||
return kotlin.runCatching {
|
||||
AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString() + "." + suffix
|
||||
SCRIPT_ENGINE.eval(jsStr, bindings).toString() + "." + suffix
|
||||
}.onFailure {
|
||||
AppLog.put("导出书名规则错误,使用默认规则\n${it.localizedMessage}", it)
|
||||
}.getOrDefault("${name} 作者:${getRealAuthor()}.$suffix")
|
||||
|
@ -3,8 +3,8 @@ package io.legado.app.model.analyzeRule
|
||||
import android.text.TextUtils
|
||||
import androidx.annotation.Keep
|
||||
import com.script.SimpleBindings
|
||||
import io.legado.app.constant.AppConst.SCRIPT_ENGINE
|
||||
import io.legado.app.constant.AppPattern.JS_PATTERN
|
||||
import io.legado.app.constant.SCRIPT_ENGINE
|
||||
import io.legado.app.data.entities.*
|
||||
import io.legado.app.help.CacheManager
|
||||
import io.legado.app.help.JsExtensions
|
||||
|
@ -6,11 +6,11 @@ import androidx.annotation.Keep
|
||||
import cn.hutool.core.util.HexUtil
|
||||
import com.bumptech.glide.load.model.GlideUrl
|
||||
import com.script.SimpleBindings
|
||||
import io.legado.app.constant.AppConst.SCRIPT_ENGINE
|
||||
import io.legado.app.constant.AppConst.UA_NAME
|
||||
import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.constant.AppPattern.JS_PATTERN
|
||||
import io.legado.app.constant.AppPattern.dataUriRegex
|
||||
import io.legado.app.constant.SCRIPT_ENGINE
|
||||
import io.legado.app.data.entities.BaseSource
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
|
@ -5,10 +5,7 @@ import android.util.Base64
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.script.SimpleBindings
|
||||
import io.legado.app.R
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.BookType
|
||||
import io.legado.app.constant.*
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.BaseSource
|
||||
import io.legado.app.data.entities.Book
|
||||
@ -269,7 +266,7 @@ object LocalBook {
|
||||
if (!AppConfig.bookImportFileName.isNullOrBlank()) {
|
||||
try {
|
||||
//在脚本中定义如何分解文件名成书名、作者名
|
||||
val jsonStr = AppConst.SCRIPT_ENGINE.eval(
|
||||
val jsonStr = SCRIPT_ENGINE.eval(
|
||||
//在用户脚本后添加捕获author、name的代码,只要脚本中author、name有值就会被捕获
|
||||
AppConfig.bookImportFileName + "\nJSON.stringify({author:author,name:name})",
|
||||
//将文件名注入到脚本的src变量中
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
import com.script.SimpleBindings
|
||||
import io.legado.app.constant.AppConst.SCRIPT_ENGINE
|
||||
import io.legado.app.constant.AppPattern.EXP_PATTERN
|
||||
import io.legado.app.constant.SCRIPT_ENGINE
|
||||
|
||||
object JsUtils {
|
||||
|
||||
|
@ -2,7 +2,7 @@ package io.legado.app.utils
|
||||
|
||||
import androidx.core.os.postDelayed
|
||||
import com.script.SimpleBindings
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.SCRIPT_ENGINE
|
||||
import io.legado.app.exception.RegexTimeoutException
|
||||
import io.legado.app.help.CrashHandler
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
@ -33,7 +33,7 @@ fun CharSequence.replace(regex: Regex, replacement: String, timeout: Long): Stri
|
||||
val bindings = SimpleBindings()
|
||||
bindings["result"] = matcher.group()
|
||||
val jsResult =
|
||||
AppConst.SCRIPT_ENGINE.eval(replacement1, bindings).toString()
|
||||
SCRIPT_ENGINE.eval(replacement1, bindings).toString()
|
||||
matcher.appendReplacement(stringBuffer, jsResult)
|
||||
} else {
|
||||
matcher.appendReplacement(stringBuffer, replacement1)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.legado.app
|
||||
|
||||
import com.script.SimpleBindings
|
||||
import com.script.rhino.RhinoScriptEngine
|
||||
import io.legado.app.constant.SCRIPT_ENGINE
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
@ -19,13 +19,12 @@ class ExampleUnitTest {
|
||||
|
||||
@Test
|
||||
fun jsTest() {
|
||||
val scriptEngine = RhinoScriptEngine()
|
||||
val map = hashMapOf("id" to "3242532321")
|
||||
map["id"] = "12314123"
|
||||
val bindings = SimpleBindings()
|
||||
bindings["result"] = map
|
||||
val js = "$=result;id=$.id;id"
|
||||
val result = scriptEngine.eval(js, bindings)?.toString()
|
||||
val result = SCRIPT_ENGINE.eval(js, bindings)?.toString()
|
||||
assertEquals("12314123", result)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user