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 var a = urlRule
if (a.isNotBlank()) { if (a.isNotBlank()) {
kotlin.runCatching { kotlin.runCatching {
if (urlRule.startsWith("<js>", false)) { if (urlRule.startsWith("<js>", false)
|| urlRule.startsWith("@js", false)
) {
val aCache = ACache.get(appCtx, "explore") val aCache = ACache.get(appCtx, "explore")
a = aCache.getAsString(bookSourceUrl) ?: "" a = aCache.getAsString(bookSourceUrl) ?: ""
if (a.isBlank()) { if (a.isBlank()) {
@ -114,10 +116,12 @@ data class BookSource(
bindings["java"] = this bindings["java"] = this
bindings["cookie"] = CookieStore bindings["cookie"] = CookieStore
bindings["cache"] = CacheManager bindings["cache"] = CacheManager
a = AppConst.SCRIPT_ENGINE.eval( val jsStr = if (urlRule.startsWith("@")) {
urlRule.substring(4, urlRule.lastIndexOf("<")), urlRule.substring(3)
bindings } else {
).toString() urlRule.substring(4, urlRule.lastIndexOf("<"))
}
a = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString()
aCache.put(bookSourceUrl, a) 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.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.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import splitties.init.appCtx
import java.util.* import java.util.*
import javax.script.SimpleBindings import javax.script.SimpleBindings
@ -105,9 +107,30 @@ data class RssSource(
return a == b || (a.isNullOrEmpty() && b.isNullOrEmpty()) return a == b || (a.isNullOrEmpty() && b.isNullOrEmpty())
} }
fun sortUrls(): LinkedHashMap<String, String> = fun sortUrls(): LinkedHashMap<String, String> = linkedMapOf<String, String>().apply {
linkedMapOf<String, String>().apply { kotlin.runCatching {
sortUrl?.split("(&&|\n)+".toRegex())?.forEach { c -> 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("::") val d = c.split("::")
if (d.size > 1) if (d.size > 1)
this[d[0]] = d[1] this[d[0]] = d[1]
@ -116,4 +139,5 @@ data class RssSource(
this[""] = sourceUrl this[""] = sourceUrl
} }
} }
}
} }
Loading…
Cancel
Save