|
|
@ -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,17 +97,18 @@ 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 |
|
|
|
|
|
|
|
if (ruleStr.isNotBlank()) { |
|
|
|
kotlin.runCatching { |
|
|
|
kotlin.runCatching { |
|
|
|
if (exploreUrl.startsWith("<js>", false) |
|
|
|
if (exploreUrl.startsWith("<js>", false) |
|
|
|
|| exploreUrl.startsWith("@js", false) |
|
|
|
|| exploreUrl.startsWith("@js", false) |
|
|
|
) { |
|
|
|
) { |
|
|
|
val aCache = ACache.get(appCtx, "explore") |
|
|
|
val aCache = ACache.get(appCtx, "explore") |
|
|
|
a = aCache.getAsString(bookSourceUrl) ?: "" |
|
|
|
ruleStr = aCache.getAsString(bookSourceUrl) ?: "" |
|
|
|
if (a.isBlank()) { |
|
|
|
if (ruleStr.isBlank()) { |
|
|
|
val bindings = SimpleBindings() |
|
|
|
val bindings = SimpleBindings() |
|
|
|
bindings["baseUrl"] = bookSourceUrl |
|
|
|
bindings["baseUrl"] = bookSourceUrl |
|
|
|
bindings["java"] = this |
|
|
|
bindings["java"] = this |
|
|
@ -121,21 +119,26 @@ data class BookSource( |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
exploreUrl.substring(4, exploreUrl.lastIndexOf("<")) |
|
|
|
exploreUrl.substring(4, exploreUrl.lastIndexOf("<")) |
|
|
|
} |
|
|
|
} |
|
|
|
a = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString() |
|
|
|
ruleStr = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString().trim() |
|
|
|
aCache.put(bookSourceUrl, a) |
|
|
|
aCache.put(bookSourceUrl, ruleStr) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
val b = a.split("(&&|\n)+".toRegex()) |
|
|
|
if (ruleStr.isJsonArray()) { |
|
|
|
b.forEach { c -> |
|
|
|
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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|