pull/38/head
kunfei 5 years ago
parent 75792ac8c4
commit 6446c13de6
  1. 14
      app/src/main/java/io/legado/app/data/entities/BookSource.kt

@ -73,9 +73,9 @@ data class BookSource(
header?.let {
val header1 = when {
it.startsWith("@js:", true) ->
AppConst.SCRIPT_ENGINE.eval(it.substring(4)).toString()
evalJS(it.substring(4)).toString()
it.startsWith("<js>", true) ->
AppConst.SCRIPT_ENGINE.eval(it.substring(4, it.lastIndexOf("<"))).toString()
evalJS(it.substring(4, it.lastIndexOf("<"))).toString()
else -> it
}
GSON.fromJsonObject<Map<String, String>>(header1)?.let { map ->
@ -159,6 +159,16 @@ data class BookSource(
return exploreKinds
}
/**
* 执行JS
*/
@Throws(Exception::class)
private fun evalJS(jsStr: String): Any {
val bindings = SimpleBindings()
bindings["java"] = JsExtensions
return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings)
}
data class ExploreKind(
var title: String,
var url: String? = null

Loading…
Cancel
Save