发现界面添加自定义样式

pull/1111/head
gedoor 3 years ago
parent 9deda74008
commit d4ee79029d
  1. 20
      app/src/main/assets/updateLog.md
  2. 67
      app/src/main/java/io/legado/app/data/entities/BookSource.kt

@ -8,6 +8,26 @@
* 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则出现问题。先关闭替换净化并刷新,再观察是否正常。如果正常说明净化规则存在误杀,如果关闭后仍然出现相关问题,请点击源链接查看原文与正文是否相同,如果不同,再进行反馈。
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
**2021/07/09**
1. 发现url添加json格式, 支持设置标签样式
* 样式属性可以搜索 [FleboxLayout子元素支持的属性介绍](https://www.jianshu.com/p/3c471953e36d)
* 样式属性可省略,有默认值
```json
[
{
"title": "xxx",
"url": "",
"style": {
"layout_flexGrow": 0,
"layout_flexShrink": 1,
"layout_alignSelf": "auto",
"layout_flexBasisPercent": -1,
"layout_wrapBefore": false
}
}
]
```
**2021/07/07**
1. 默认规则新增类似`jsonPath`的索引写法 by bushixuanqi
* 格式形如 `[index,index, ...]``[!index,index, ...]` 其中`[!`开头表示筛选方式为排除,`index`可以是单个索引,也可以是区间。

@ -10,10 +10,7 @@ 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 io.legado.app.utils.splitNotBlank
import io.legado.app.utils.*
import kotlinx.parcelize.Parcelize
import splitties.init.appCtx
import javax.script.SimpleBindings
@ -100,42 +97,48 @@ data class BookSource(
}
}
fun getExploreKinds() = arrayListOf<ExploreKind>().apply {
exploreUrl?.let { exploreUrl ->
var a = exploreUrl
if (a.isNotBlank()) {
kotlin.runCatching {
if (exploreUrl.startsWith("<js>", false)
|| exploreUrl.startsWith("@js", false)
) {
val aCache = ACache.get(appCtx, "explore")
a = aCache.getAsString(bookSourceUrl) ?: ""
if (a.isBlank()) {
val bindings = SimpleBindings()
bindings["baseUrl"] = bookSourceUrl
bindings["java"] = this
bindings["cookie"] = CookieStore
bindings["cache"] = CacheManager
val jsStr = if (exploreUrl.startsWith("@")) {
exploreUrl.substring(3)
} else {
exploreUrl.substring(4, exploreUrl.lastIndexOf("<"))
}
a = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString()
aCache.put(bookSourceUrl, a)
fun getExploreKinds(): List<ExploreKind> {
val exploreUrl = exploreUrl ?: return emptyList()
val kinds = arrayListOf<ExploreKind>()
var ruleStr = exploreUrl
if (ruleStr.isNotBlank()) {
kotlin.runCatching {
if (exploreUrl.startsWith("<js>", false)
|| exploreUrl.startsWith("@js", false)
) {
val aCache = ACache.get(appCtx, "explore")
ruleStr = aCache.getAsString(bookSourceUrl) ?: ""
if (ruleStr.isBlank()) {
val bindings = SimpleBindings()
bindings["baseUrl"] = bookSourceUrl
bindings["java"] = this
bindings["cookie"] = CookieStore
bindings["cache"] = CacheManager
val jsStr = if (exploreUrl.startsWith("@")) {
exploreUrl.substring(3)
} else {
exploreUrl.substring(4, exploreUrl.lastIndexOf("<"))
}
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("::")
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
}
/**

Loading…
Cancel
Save