diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 88fbf53ed..8f5adc182 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -105,7 +105,9 @@ data class BookSource( var a = urlRule if (a.isNotBlank()) { kotlin.runCatching { - if (urlRule.startsWith("", false)) { + if (urlRule.startsWith("", 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) } } diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index d71d7b583..5c3280812 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -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 = - linkedMapOf().apply { - sortUrl?.split("(&&|\n)+".toRegex())?.forEach { c -> + fun sortUrls(): LinkedHashMap = linkedMapOf().apply { + kotlin.runCatching { + var a = sortUrl + if (sortUrl?.startsWith("", 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] @@ -116,4 +139,5 @@ data class RssSource( this[""] = sourceUrl } } + } } \ No newline at end of file