|
|
@ -10,10 +10,7 @@ import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.CacheManager |
|
|
|
import io.legado.app.help.CacheManager |
|
|
|
import io.legado.app.help.JsExtensions |
|
|
|
import io.legado.app.help.JsExtensions |
|
|
|
import io.legado.app.help.http.CookieStore |
|
|
|
import io.legado.app.help.http.CookieStore |
|
|
|
import io.legado.app.utils.ACache |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
|
|
|
|
import io.legado.app.utils.fromJsonObject |
|
|
|
|
|
|
|
import io.legado.app.utils.splitNotBlank |
|
|
|
|
|
|
|
import kotlinx.parcelize.Parcelize |
|
|
|
import kotlinx.parcelize.Parcelize |
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.init.appCtx |
|
|
|
import javax.script.SimpleBindings |
|
|
|
import javax.script.SimpleBindings |
|
|
@ -100,42 +97,48 @@ data class BookSource( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun getExploreKinds() = arrayListOf<ExploreKind>().apply { |
|
|
|
fun getExploreKinds(): List<ExploreKind> { |
|
|
|
exploreUrl?.let { exploreUrl -> |
|
|
|
val exploreUrl = exploreUrl ?: return emptyList() |
|
|
|
var a = exploreUrl |
|
|
|
val kinds = arrayListOf<ExploreKind>() |
|
|
|
if (a.isNotBlank()) { |
|
|
|
var ruleStr = exploreUrl |
|
|
|
kotlin.runCatching { |
|
|
|
if (ruleStr.isNotBlank()) { |
|
|
|
if (exploreUrl.startsWith("<js>", false) |
|
|
|
kotlin.runCatching { |
|
|
|
|| exploreUrl.startsWith("@js", false) |
|
|
|
if (exploreUrl.startsWith("<js>", false) |
|
|
|
) { |
|
|
|
|| exploreUrl.startsWith("@js", false) |
|
|
|
val aCache = ACache.get(appCtx, "explore") |
|
|
|
) { |
|
|
|
a = aCache.getAsString(bookSourceUrl) ?: "" |
|
|
|
val aCache = ACache.get(appCtx, "explore") |
|
|
|
if (a.isBlank()) { |
|
|
|
ruleStr = aCache.getAsString(bookSourceUrl) ?: "" |
|
|
|
val bindings = SimpleBindings() |
|
|
|
if (ruleStr.isBlank()) { |
|
|
|
bindings["baseUrl"] = bookSourceUrl |
|
|
|
val bindings = SimpleBindings() |
|
|
|
bindings["java"] = this |
|
|
|
bindings["baseUrl"] = bookSourceUrl |
|
|
|
bindings["cookie"] = CookieStore |
|
|
|
bindings["java"] = this |
|
|
|
bindings["cache"] = CacheManager |
|
|
|
bindings["cookie"] = CookieStore |
|
|
|
val jsStr = if (exploreUrl.startsWith("@")) { |
|
|
|
bindings["cache"] = CacheManager |
|
|
|
exploreUrl.substring(3) |
|
|
|
val jsStr = if (exploreUrl.startsWith("@")) { |
|
|
|
} else { |
|
|
|
exploreUrl.substring(3) |
|
|
|
exploreUrl.substring(4, exploreUrl.lastIndexOf("<")) |
|
|
|
} else { |
|
|
|
} |
|
|
|
exploreUrl.substring(4, exploreUrl.lastIndexOf("<")) |
|
|
|
a = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString() |
|
|
|
|
|
|
|
aCache.put(bookSourceUrl, a) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ruleStr = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString().trim() |
|
|
|
|
|
|
|
aCache.put(bookSourceUrl, ruleStr) |
|
|
|
} |
|
|
|
} |
|
|
|
val b = a.split("(&&|\n)+".toRegex()) |
|
|
|
} |
|
|
|
b.forEach { c -> |
|
|
|
if (ruleStr.isJsonArray()) { |
|
|
|
|
|
|
|
GSON.fromJsonArray<ExploreKind>(ruleStr)?.let { |
|
|
|
|
|
|
|
kinds.addAll(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ruleStr.split("(&&|\n)+".toRegex()).forEach { c -> |
|
|
|
val d = c.split("::") |
|
|
|
val d = c.split("::") |
|
|
|
if (d.size > 1) |
|
|
|
if (d.size > 1) |
|
|
|
add(ExploreKind(d[0], d[1])) |
|
|
|
kinds.add(ExploreKind(d[0], d[1])) |
|
|
|
} |
|
|
|
} |
|
|
|
}.onFailure { |
|
|
|
|
|
|
|
add(ExploreKind(it.localizedMessage ?: "")) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}.onFailure { |
|
|
|
|
|
|
|
kinds.add(ExploreKind(it.localizedMessage ?: "")) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return kinds |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|