rss分类url可以写js

pull/854/head
gedoor 4 years ago
parent 532f429454
commit 4d98146751
  1. 14
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 30
      app/src/main/java/io/legado/app/data/entities/RssSource.kt

@ -105,7 +105,9 @@ data class BookSource(
var a = urlRule
if (a.isNotBlank()) {
kotlin.runCatching {
if (urlRule.startsWith("<js>", false)) {
if (urlRule.startsWith("<js>", false)
|| urlRule.startsWith("@js", false)
) {
val aCache = ACache.get(appCtx, "explore")
a = aCache.getAsString(bookSourceUrl) ?: ""
if (a.isBlank()) {
@ -114,10 +116,12 @@ data class BookSource(
bindings["java"] = this
bindings["cookie"] = CookieStore
bindings["cache"] = CacheManager
a = AppConst.SCRIPT_ENGINE.eval(
urlRule.substring(4, urlRule.lastIndexOf("<")),
bindings
).toString()
val jsStr = if (urlRule.startsWith("@")) {
urlRule.substring(3)
} else {
urlRule.substring(4, urlRule.lastIndexOf("<"))
}
a = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString()
aCache.put(bookSourceUrl, a)
}
}

@ -9,9 +9,11 @@ import io.legado.app.help.AppConfig
import io.legado.app.help.CacheManager
import io.legado.app.help.JsExtensions
import io.legado.app.help.http.CookieStore
import io.legado.app.utils.ACache
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import kotlinx.parcelize.Parcelize
import splitties.init.appCtx
import java.util.*
import javax.script.SimpleBindings
@ -105,9 +107,30 @@ data class RssSource(
return a == b || (a.isNullOrEmpty() && b.isNullOrEmpty())
}
fun sortUrls(): LinkedHashMap<String, String> =
linkedMapOf<String, String>().apply {
sortUrl?.split("(&&|\n)+".toRegex())?.forEach { c ->
fun sortUrls(): LinkedHashMap<String, String> = linkedMapOf<String, String>().apply {
kotlin.runCatching {
var a = sortUrl
if (sortUrl?.startsWith("<js>", false) == true
|| sortUrl?.startsWith("@js", false) == true
) {
val aCache = ACache.get(appCtx, "rssSortUrl")
a = aCache.getAsString(sourceUrl) ?: ""
if (a.isBlank()) {
val bindings = SimpleBindings()
bindings["baseUrl"] = sourceUrl
bindings["java"] = this
bindings["cookie"] = CookieStore
bindings["cache"] = CacheManager
val jsStr = if (sortUrl!!.startsWith("@")) {
sortUrl!!.substring(3)
} else {
sortUrl!!.substring(4, sortUrl!!.lastIndexOf("<"))
}
a = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString()
aCache.put(sourceUrl, a)
}
}
a?.split("(&&|\n)+".toRegex())?.forEach { c ->
val d = c.split("::")
if (d.size > 1)
this[d[0]] = d[1]
@ -117,3 +140,4 @@ data class RssSource(
}
}
}
}
Loading…
Cancel
Save