diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 4d6e0ba67..1f4fca06e 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,6 +11,11 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! +**2022/05/28** + +* 移除刷新时重新获取目录页链接Url的配置 +* 添加刷新前Js,功能更强大 + **2022/05/27** * 书源详情页规则添加刷新时重新获取目录页链接Url的配置,true or false 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 ea04ed64b..4d76d1713 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 @@ -130,21 +130,43 @@ data class BookSource( return bookSourceUrl.hashCode() } - override fun equals(other: Any?) = - if (other is BookSource) other.bookSourceUrl == bookSourceUrl else false - - fun getSearchRule() = ruleSearch ?: SearchRule() + override fun equals(other: Any?): Boolean { + return if (other is BookSource) other.bookSourceUrl == bookSourceUrl else false + } - fun getExploreRule() = ruleExplore ?: ExploreRule() + fun getSearchRule(): SearchRule { + ruleSearch?.let { return it } + val rule = SearchRule() + ruleSearch = rule + return rule + } - fun getBookInfoRule() = ruleBookInfo ?: BookInfoRule() + fun getExploreRule(): ExploreRule { + ruleExplore?.let { return it } + val rule = ExploreRule() + ruleExplore = rule + return rule + } - fun getTocRule() = ruleToc ?: TocRule() + fun getBookInfoRule(): BookInfoRule { + ruleBookInfo?.let { return it } + val rule = BookInfoRule() + ruleBookInfo = rule + return rule + } - fun getContentRule() = ruleContent ?: ContentRule() + fun getTocRule(): TocRule { + ruleToc?.let { return it } + val rule = TocRule() + ruleToc = rule + return rule + } - fun isReGetTocUrlOnRefresh(): Boolean { - return ruleBookInfo?.reGetTocUrlOnRefresh.isTrue() + fun getContentRule(): ContentRule { + ruleContent?.let { return it } + val rule = ContentRule() + ruleContent = rule + return rule } fun getDisPlayNameGroup(): String { diff --git a/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt index 81e147a20..cddba2c4f 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt @@ -17,6 +17,5 @@ data class BookInfoRule( var tocUrl: String? = null, var wordCount: String? = null, var canReName: String? = null, - var downloadUrls: String? = null, - var reGetTocUrlOnRefresh: String? = null + var downloadUrls: String? = null ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt index 10337735d..1dfd97e83 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt @@ -5,6 +5,7 @@ import kotlinx.parcelize.Parcelize @Parcelize data class TocRule( + var preUpdateJs: String? = null, var chapterList: String? = null, var chapterName: String? = null, var chapterUrl: String? = null, diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 5ca5dab58..32f9ab482 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -634,7 +634,7 @@ class AnalyzeRule( /** * 执行JS */ - fun evalJS(jsStr: String, result: Any?): Any? { + fun evalJS(jsStr: String, result: Any? = null): Any? { val bindings = SimpleBindings() bindings["java"] = this bindings["cookie"] = CookieStore diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index 75ff48199..4819cf85c 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -277,16 +277,15 @@ object LocalBook { val defaultBookTreeUri = AppConfig.defaultBookTreeUri if (defaultBookTreeUri.isNullOrBlank()) throw NoStackTraceException("没有设置书籍保存位置!") val treeUri = Uri.parse(defaultBookTreeUri) - var bookUrl: String = "" - if (treeUri.isContentScheme()) { + val bookUrl = if (treeUri.isContentScheme()) { val treeDoc = DocumentFile.fromTreeUri(appCtx, treeUri) - var doc = treeDoc!!.findFile(fileName) ?: return false - bookUrl = doc.uri.toString() + val doc = treeDoc!!.findFile(fileName) ?: return false + doc.uri.toString() } else { val treeFile = File(treeUri.path!!) val file = treeFile.getFile(fileName) if (!file.exists()) return false - bookUrl = file.absolutePath + file.absolutePath } return appDb.bookDao.getBook(bookUrl) != null } diff --git a/app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt b/app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt index fc1293ce7..982ac183f 100644 --- a/app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt +++ b/app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt @@ -2,8 +2,8 @@ package io.legado.app.ui.book.remote.manager import android.net.Uri -import io.legado.app.constant.PreferKey import io.legado.app.constant.AppPattern.bookFileRegex +import io.legado.app.constant.PreferKey import io.legado.app.exception.NoStackTraceException import io.legado.app.help.AppWebDav import io.legado.app.help.config.AppConfig @@ -12,7 +12,10 @@ import io.legado.app.lib.webdav.WebDavFile import io.legado.app.model.localBook.LocalBook import io.legado.app.ui.book.remote.RemoteBook import io.legado.app.ui.book.remote.RemoteBookManager -import io.legado.app.utils.* +import io.legado.app.utils.NetworkUtils +import io.legado.app.utils.getPrefString +import io.legado.app.utils.isContentScheme +import io.legado.app.utils.readBytes import kotlinx.coroutines.runBlocking import splitties.init.appCtx import java.io.File @@ -96,7 +99,6 @@ object RemoteBookWebDav : RemoteBookManager() { } }.onFailure { it.printStackTrace() - null }.getOrNull() } diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index c0b44a17e..fdf694bb3 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -269,12 +269,12 @@ class BookSourceEditActivity : add(EditEntity("tocUrl", ir?.tocUrl, R.string.rule_toc_url)) add(EditEntity("canReName", ir?.canReName, R.string.rule_can_re_name)) add(EditEntity("downloadUrls", ir?.downloadUrls, R.string.download_url_rule)) - add(EditEntity("reGetTocUrl", ir?.reGetTocUrlOnRefresh, R.string.rule_re_get_toc_url)) } //目录页 val tr = source?.getTocRule() tocEntities.clear() tocEntities.apply { + add(EditEntity("preUpdateJs", tr?.preUpdateJs, R.string.pre_update_js)) add(EditEntity("chapterList", tr?.chapterList, R.string.rule_chapter_list)) add(EditEntity("chapterName", tr?.chapterName, R.string.rule_chapter_name)) add(EditEntity("chapterUrl", tr?.chapterUrl, R.string.rule_chapter_url)) @@ -402,12 +402,12 @@ class BookSourceEditActivity : "canReName" -> bookInfoRule.canReName = it.value "downloadUrls" -> bookInfoRule.downloadUrls = viewModel.ruleComplete(it.value, bookInfoRule.init) - "reGetTocUrl" -> bookInfoRule.reGetTocUrlOnRefresh = it.value } } tocEntities.forEach { when (it.key) { - "chapterList" -> tocRule.chapterList = it.value ?: "" + "preUpdateJs" -> tocRule.preUpdateJs = it.value + "chapterList" -> tocRule.chapterList = it.value "chapterName" -> tocRule.chapterName = viewModel.ruleComplete(it.value, tocRule.chapterList) "chapterUrl" -> tocRule.chapterUrl = diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 0da137f7c..043c999de 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -15,6 +15,7 @@ import io.legado.app.help.DefaultData import io.legado.app.help.config.AppConfig import io.legado.app.help.config.LocalConfig import io.legado.app.model.CacheBook +import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.webBook.WebBook import io.legado.app.service.CacheBookService import io.legado.app.utils.postEvent @@ -116,7 +117,11 @@ class MainViewModel(application: Application) : BaseViewModel(application) { onUpTocBooks.add(book.bookUrl) postEvent(EventBus.UP_BOOKSHELF, book.bookUrl) execute(context = upTocPool) { - if (book.tocUrl.isBlank() || source.isReGetTocUrlOnRefresh()) { + val preUpdateJs = source.ruleToc?.preUpdateJs + if (!preUpdateJs.isNullOrBlank()) { + AnalyzeRule(book, source).evalJS(preUpdateJs) + } + if (book.tocUrl.isBlank()) { WebBook.getBookInfoAwait(this, source, book) } val toc = WebBook.getChapterListAwait(this, source, book).getOrThrow() diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index f463d99ab..bd53997ec 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -416,7 +416,7 @@ Volume mark(isVolume) VIP标识(isVip) 更新时间(ChapterInfo) - 刷新时重新获取目录Url(reGetTocUrlOnRefresh) + 更新之前Js 正文规则(content) 正文下一页URL规则(nextContentUrl) WebViewJs(webJs) @@ -989,5 +989,6 @@ Download Fail Upload WebDavBook + diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index cfc19c003..d43903450 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -420,7 +420,7 @@ Volume mark(isVolume) VIP标识(isVip) 更新时间(ChapterInfo) - 刷新时重新获取目录Url(reGetTocUrlOnRefresh) + 更新之前Js 正文规则(content) 正文下一页URL规则(nextContentUrl) WebViewJs(webJs) @@ -992,5 +992,6 @@ Download Fail Upload WebDavBook + diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 36bfb527d..a493b6353 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -418,7 +418,7 @@ 卷标识(isVolume) VIP标识(éVip) 更新时间(capítuloInfo) - 刷新时重新获取目录Url(reGetTocUrlOnRefresh) + 更新之前Js 正文规则(conteúdo) 正文下一页URL规则(proxConteúdoUrl) WebViewJs(webJs) @@ -992,5 +992,6 @@ Download Fail Upload WebDavBook + diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 7d40929fb..740f013f0 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -415,7 +415,7 @@ Volume標識(isVolume) VIP 標識 (isVip) 更新時間 (ChapterInfo) - 刷新时重新获取目录Url(reGetTocUrlOnRefresh) + 更新之前Js 正文規則 (content) 正文下一頁 URL 規則 (nextContentUrl) WebViewJs (webJs) @@ -989,5 +989,6 @@ Download Fail Upload WebDav书籍 + diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 134e22b90..d3befce5c 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -419,7 +419,7 @@ Volume標識(isVolume) VIP標識(isVip) 更新時間(ChapterInfo) - 刷新时重新获取目录Url(reGetTocUrlOnRefresh) + 更新之前Js 正文規則(content) 正文下一頁URL規則(nextContentUrl) WebViewJs(webJs) @@ -991,5 +991,6 @@ Download Fail Upload WebDav书籍 + diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 5a6c7beeb..13fedb42f 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -419,7 +419,7 @@ Volume标识(isVolume) VIP标识(isVip) 更新时间(ChapterInfo) - 刷新时重新获取目录Url(reGetTocUrlOnRefresh) + 更新之前Js 正文规则(content) 正文下一页URL规则(nextContentUrl) WebViewJs(webJs) @@ -991,5 +991,6 @@ Download Fail 上传WebDav WebDav书籍 + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1a9f867cf..ab924253e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -420,7 +420,7 @@ 卷标识(isVolume) VIP标识(isVip) 更新时间(ChapterInfo) - 刷新时重新获取目录Url(reGetTocUrlOnRefresh) + 更新之前Js 正文规则(content) 正文下一页URL规则(nextContentUrl) WebViewJs(webJs) @@ -992,5 +992,6 @@ Download Fail Upload WebDavBook +