|
|
|
@ -46,6 +46,52 @@ data class BookSource( |
|
|
|
|
var ruleContent: ContentRule? = null // 正文页规则 |
|
|
|
|
) : Parcelable, JsExtensions { |
|
|
|
|
|
|
|
|
|
@delegate:Transient |
|
|
|
|
@delegate:Ignore |
|
|
|
|
@IgnoredOnParcel |
|
|
|
|
val exploreKinds by lazy { |
|
|
|
|
val exploreUrl = exploreUrl?.trim() ?: return@lazy emptyList() |
|
|
|
|
val kinds = arrayListOf<ExploreKind>() |
|
|
|
|
var ruleStr = exploreUrl |
|
|
|
|
if (ruleStr.isNotBlank()) { |
|
|
|
|
kotlin.runCatching { |
|
|
|
|
if (exploreUrl.startsWith("<js>", false) |
|
|
|
|
|| exploreUrl.startsWith("@js", false) |
|
|
|
|
) { |
|
|
|
|
val aCache = ACache.get(appCtx, "explore") |
|
|
|
|
ruleStr = aCache.getAsString(bookSourceUrl) ?: "" |
|
|
|
|
if (ruleStr.isBlank()) { |
|
|
|
|
val bindings = SimpleBindings() |
|
|
|
|
bindings["baseUrl"] = bookSourceUrl |
|
|
|
|
bindings["java"] = this |
|
|
|
|
bindings["cookie"] = CookieStore |
|
|
|
|
bindings["cache"] = CacheManager |
|
|
|
|
val jsStr = if (exploreUrl.startsWith("@")) { |
|
|
|
|
exploreUrl.substring(3) |
|
|
|
|
} else { |
|
|
|
|
exploreUrl.substring(4, exploreUrl.lastIndexOf("<")) |
|
|
|
|
} |
|
|
|
|
ruleStr = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString().trim() |
|
|
|
|
aCache.put(bookSourceUrl, ruleStr) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (ruleStr.isJsonArray()) { |
|
|
|
|
GSON.fromJsonArray<ExploreKind>(ruleStr)?.let { |
|
|
|
|
kinds.addAll(it) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
ruleStr.split("(&&|\n)+".toRegex()).forEach { kindStr -> |
|
|
|
|
val kindCfg = kindStr.split("::") |
|
|
|
|
kinds.add(ExploreKind(kindCfg.first(), kindCfg.getOrNull(1))) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}.onFailure { |
|
|
|
|
kinds.add(ExploreKind(it.localizedMessage ?: "")) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return@lazy kinds |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun hashCode(): Int { |
|
|
|
|
return bookSourceUrl.hashCode() |
|
|
|
|
} |
|
|
|
@ -98,53 +144,6 @@ data class BookSource( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@delegate:Transient |
|
|
|
|
@delegate:Ignore |
|
|
|
|
@IgnoredOnParcel |
|
|
|
|
val exploreKinds by lazy { |
|
|
|
|
val exploreUrl = exploreUrl ?: return@lazy emptyList() |
|
|
|
|
val kinds = arrayListOf<ExploreKind>() |
|
|
|
|
var ruleStr = exploreUrl |
|
|
|
|
if (ruleStr.isNotBlank()) { |
|
|
|
|
kotlin.runCatching { |
|
|
|
|
if (exploreUrl.startsWith("<js>", false) |
|
|
|
|
|| exploreUrl.startsWith("@js", false) |
|
|
|
|
) { |
|
|
|
|
val aCache = ACache.get(appCtx, "explore") |
|
|
|
|
ruleStr = aCache.getAsString(bookSourceUrl) ?: "" |
|
|
|
|
if (ruleStr.isBlank()) { |
|
|
|
|
val bindings = SimpleBindings() |
|
|
|
|
bindings["baseUrl"] = bookSourceUrl |
|
|
|
|
bindings["java"] = this |
|
|
|
|
bindings["cookie"] = CookieStore |
|
|
|
|
bindings["cache"] = CacheManager |
|
|
|
|
val jsStr = if (exploreUrl.startsWith("@")) { |
|
|
|
|
exploreUrl.substring(3) |
|
|
|
|
} else { |
|
|
|
|
exploreUrl.substring(4, exploreUrl.lastIndexOf("<")) |
|
|
|
|
} |
|
|
|
|
ruleStr = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString().trim() |
|
|
|
|
aCache.put(bookSourceUrl, ruleStr) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (ruleStr.isJsonArray()) { |
|
|
|
|
GSON.fromJsonArray<ExploreKind>(ruleStr)?.let { |
|
|
|
|
kinds.addAll(it) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
ruleStr.split("(&&|\n)+".toRegex()).forEach { c -> |
|
|
|
|
val d = c.split("::") |
|
|
|
|
if (d.size > 1) |
|
|
|
|
kinds.add(ExploreKind(d[0], d[1])) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}.onFailure { |
|
|
|
|
kinds.add(ExploreKind(it.localizedMessage ?: "")) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return@lazy kinds |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 执行JS |
|
|
|
|
*/ |
|
|
|
|