去除刷新前重新获取目录url

添加刷新前js,功能更强大
pull/1931/head
kunfei 3 years ago
parent 43667be08a
commit ff8f06c578
  1. 5
      app/src/main/assets/updateLog.md
  2. 42
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  3. 3
      app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt
  4. 1
      app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt
  5. 2
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  6. 9
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  7. 8
      app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt
  8. 6
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  9. 7
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
  10. 3
      app/src/main/res/values-es-rES/strings.xml
  11. 3
      app/src/main/res/values-ja-rJP/strings.xml
  12. 3
      app/src/main/res/values-pt-rBR/strings.xml
  13. 3
      app/src/main/res/values-zh-rHK/strings.xml
  14. 3
      app/src/main/res/values-zh-rTW/strings.xml
  15. 3
      app/src/main/res/values-zh/strings.xml
  16. 3
      app/src/main/res/values/strings.xml

@ -11,6 +11,11 @@
* 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
**2022/05/28**
* 移除刷新时重新获取目录页链接Url的配置
* 添加刷新前Js,功能更强大
**2022/05/27** **2022/05/27**
* 书源详情页规则添加刷新时重新获取目录页链接Url的配置,true or false * 书源详情页规则添加刷新时重新获取目录页链接Url的配置,true or false

@ -130,21 +130,43 @@ data class BookSource(
return bookSourceUrl.hashCode() return bookSourceUrl.hashCode()
} }
override fun equals(other: Any?) = override fun equals(other: Any?): Boolean {
if (other is BookSource) other.bookSourceUrl == bookSourceUrl else false return if (other is BookSource) other.bookSourceUrl == bookSourceUrl else false
}
fun getSearchRule() = ruleSearch ?: SearchRule()
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 { fun getContentRule(): ContentRule {
return ruleBookInfo?.reGetTocUrlOnRefresh.isTrue() ruleContent?.let { return it }
val rule = ContentRule()
ruleContent = rule
return rule
} }
fun getDisPlayNameGroup(): String { fun getDisPlayNameGroup(): String {

@ -17,6 +17,5 @@ data class BookInfoRule(
var tocUrl: String? = null, var tocUrl: String? = null,
var wordCount: String? = null, var wordCount: String? = null,
var canReName: String? = null, var canReName: String? = null,
var downloadUrls: String? = null, var downloadUrls: String? = null
var reGetTocUrlOnRefresh: String? = null
) : Parcelable ) : Parcelable

@ -5,6 +5,7 @@ import kotlinx.parcelize.Parcelize
@Parcelize @Parcelize
data class TocRule( data class TocRule(
var preUpdateJs: String? = null,
var chapterList: String? = null, var chapterList: String? = null,
var chapterName: String? = null, var chapterName: String? = null,
var chapterUrl: String? = null, var chapterUrl: String? = null,

@ -634,7 +634,7 @@ class AnalyzeRule(
/** /**
* 执行JS * 执行JS
*/ */
fun evalJS(jsStr: String, result: Any?): Any? { fun evalJS(jsStr: String, result: Any? = null): Any? {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["java"] = this bindings["java"] = this
bindings["cookie"] = CookieStore bindings["cookie"] = CookieStore

@ -277,16 +277,15 @@ object LocalBook {
val defaultBookTreeUri = AppConfig.defaultBookTreeUri val defaultBookTreeUri = AppConfig.defaultBookTreeUri
if (defaultBookTreeUri.isNullOrBlank()) throw NoStackTraceException("没有设置书籍保存位置!") if (defaultBookTreeUri.isNullOrBlank()) throw NoStackTraceException("没有设置书籍保存位置!")
val treeUri = Uri.parse(defaultBookTreeUri) val treeUri = Uri.parse(defaultBookTreeUri)
var bookUrl: String = "" val bookUrl = if (treeUri.isContentScheme()) {
if (treeUri.isContentScheme()) {
val treeDoc = DocumentFile.fromTreeUri(appCtx, treeUri) val treeDoc = DocumentFile.fromTreeUri(appCtx, treeUri)
var doc = treeDoc!!.findFile(fileName) ?: return false val doc = treeDoc!!.findFile(fileName) ?: return false
bookUrl = doc.uri.toString() doc.uri.toString()
} else { } else {
val treeFile = File(treeUri.path!!) val treeFile = File(treeUri.path!!)
val file = treeFile.getFile(fileName) val file = treeFile.getFile(fileName)
if (!file.exists()) return false if (!file.exists()) return false
bookUrl = file.absolutePath file.absolutePath
} }
return appDb.bookDao.getBook(bookUrl) != null return appDb.bookDao.getBook(bookUrl) != null
} }

@ -2,8 +2,8 @@ package io.legado.app.ui.book.remote.manager
import android.net.Uri import android.net.Uri
import io.legado.app.constant.PreferKey
import io.legado.app.constant.AppPattern.bookFileRegex import io.legado.app.constant.AppPattern.bookFileRegex
import io.legado.app.constant.PreferKey
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.AppWebDav import io.legado.app.help.AppWebDav
import io.legado.app.help.config.AppConfig 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.model.localBook.LocalBook
import io.legado.app.ui.book.remote.RemoteBook import io.legado.app.ui.book.remote.RemoteBook
import io.legado.app.ui.book.remote.RemoteBookManager 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 kotlinx.coroutines.runBlocking
import splitties.init.appCtx import splitties.init.appCtx
import java.io.File import java.io.File
@ -96,7 +99,6 @@ object RemoteBookWebDav : RemoteBookManager() {
} }
}.onFailure { }.onFailure {
it.printStackTrace() it.printStackTrace()
null
}.getOrNull() }.getOrNull()
} }

@ -269,12 +269,12 @@ class BookSourceEditActivity :
add(EditEntity("tocUrl", ir?.tocUrl, R.string.rule_toc_url)) add(EditEntity("tocUrl", ir?.tocUrl, R.string.rule_toc_url))
add(EditEntity("canReName", ir?.canReName, R.string.rule_can_re_name)) add(EditEntity("canReName", ir?.canReName, R.string.rule_can_re_name))
add(EditEntity("downloadUrls", ir?.downloadUrls, R.string.download_url_rule)) 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() val tr = source?.getTocRule()
tocEntities.clear() tocEntities.clear()
tocEntities.apply { tocEntities.apply {
add(EditEntity("preUpdateJs", tr?.preUpdateJs, R.string.pre_update_js))
add(EditEntity("chapterList", tr?.chapterList, R.string.rule_chapter_list)) add(EditEntity("chapterList", tr?.chapterList, R.string.rule_chapter_list))
add(EditEntity("chapterName", tr?.chapterName, R.string.rule_chapter_name)) add(EditEntity("chapterName", tr?.chapterName, R.string.rule_chapter_name))
add(EditEntity("chapterUrl", tr?.chapterUrl, R.string.rule_chapter_url)) add(EditEntity("chapterUrl", tr?.chapterUrl, R.string.rule_chapter_url))
@ -402,12 +402,12 @@ class BookSourceEditActivity :
"canReName" -> bookInfoRule.canReName = it.value "canReName" -> bookInfoRule.canReName = it.value
"downloadUrls" -> bookInfoRule.downloadUrls = "downloadUrls" -> bookInfoRule.downloadUrls =
viewModel.ruleComplete(it.value, bookInfoRule.init) viewModel.ruleComplete(it.value, bookInfoRule.init)
"reGetTocUrl" -> bookInfoRule.reGetTocUrlOnRefresh = it.value
} }
} }
tocEntities.forEach { tocEntities.forEach {
when (it.key) { when (it.key) {
"chapterList" -> tocRule.chapterList = it.value ?: "" "preUpdateJs" -> tocRule.preUpdateJs = it.value
"chapterList" -> tocRule.chapterList = it.value
"chapterName" -> tocRule.chapterName = "chapterName" -> tocRule.chapterName =
viewModel.ruleComplete(it.value, tocRule.chapterList) viewModel.ruleComplete(it.value, tocRule.chapterList)
"chapterUrl" -> tocRule.chapterUrl = "chapterUrl" -> tocRule.chapterUrl =

@ -15,6 +15,7 @@ import io.legado.app.help.DefaultData
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.LocalConfig import io.legado.app.help.config.LocalConfig
import io.legado.app.model.CacheBook import io.legado.app.model.CacheBook
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.service.CacheBookService import io.legado.app.service.CacheBookService
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
@ -116,7 +117,11 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
onUpTocBooks.add(book.bookUrl) onUpTocBooks.add(book.bookUrl)
postEvent(EventBus.UP_BOOKSHELF, book.bookUrl) postEvent(EventBus.UP_BOOKSHELF, book.bookUrl)
execute(context = upTocPool) { 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) WebBook.getBookInfoAwait(this, source, book)
} }
val toc = WebBook.getChapterListAwait(this, source, book).getOrThrow() val toc = WebBook.getChapterListAwait(this, source, book).getOrThrow()

@ -416,7 +416,7 @@
<string name="rule_is_volume">Volume mark(isVolume)</string> <string name="rule_is_volume">Volume mark(isVolume)</string>
<string name="rule_is_vip">VIP标识(isVip)</string> <string name="rule_is_vip">VIP标识(isVip)</string>
<string name="rule_update_time">更新时间(ChapterInfo)</string> <string name="rule_update_time">更新时间(ChapterInfo)</string>
<string name="rule_re_get_toc_url">刷新时重新获取目录Url(reGetTocUrlOnRefresh)</string> <string name="pre_update_js">更新之前Js</string>
<string name="rule_book_content">正文规则(content)</string> <string name="rule_book_content">正文规则(content)</string>
<string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string> <string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string>
<string name="rule_web_js">WebViewJs(webJs)</string> <string name="rule_web_js">WebViewJs(webJs)</string>
@ -989,5 +989,6 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</string> <string name="add_remote_book">WebDavBook</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -420,7 +420,7 @@
<string name="rule_is_volume">Volume mark(isVolume)</string> <string name="rule_is_volume">Volume mark(isVolume)</string>
<string name="rule_is_vip">VIP标识(isVip)</string> <string name="rule_is_vip">VIP标识(isVip)</string>
<string name="rule_update_time">更新时间(ChapterInfo)</string> <string name="rule_update_time">更新时间(ChapterInfo)</string>
<string name="rule_re_get_toc_url">刷新时重新获取目录Url(reGetTocUrlOnRefresh)</string> <string name="pre_update_js">更新之前Js</string>
<string name="rule_book_content">正文规则(content)</string> <string name="rule_book_content">正文规则(content)</string>
<string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string> <string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string>
<string name="rule_web_js">WebViewJs(webJs)</string> <string name="rule_web_js">WebViewJs(webJs)</string>
@ -992,5 +992,6 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</string> <string name="add_remote_book">WebDavBook</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -418,7 +418,7 @@
<string name="rule_is_volume">卷标识(isVolume)</string> <string name="rule_is_volume">卷标识(isVolume)</string>
<string name="rule_is_vip">VIP标识(éVip)</string> <string name="rule_is_vip">VIP标识(éVip)</string>
<string name="rule_update_time">更新时间(capítuloInfo)</string> <string name="rule_update_time">更新时间(capítuloInfo)</string>
<string name="rule_re_get_toc_url">刷新时重新获取目录Url(reGetTocUrlOnRefresh)</string> <string name="pre_update_js">更新之前Js</string>
<string name="rule_book_content">正文规则(conteúdo)</string> <string name="rule_book_content">正文规则(conteúdo)</string>
<string name="rule_next_content">正文下一页URL规则(proxConteúdoUrl)</string> <string name="rule_next_content">正文下一页URL规则(proxConteúdoUrl)</string>
<string name="rule_web_js">WebViewJs(webJs)</string> <string name="rule_web_js">WebViewJs(webJs)</string>
@ -992,5 +992,6 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</string> <string name="add_remote_book">WebDavBook</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -415,7 +415,7 @@
<string name="rule_is_volume">Volume標識(isVolume)</string> <string name="rule_is_volume">Volume標識(isVolume)</string>
<string name="rule_is_vip">VIP 標識 (isVip)</string> <string name="rule_is_vip">VIP 標識 (isVip)</string>
<string name="rule_update_time">更新時間 (ChapterInfo)</string> <string name="rule_update_time">更新時間 (ChapterInfo)</string>
<string name="rule_re_get_toc_url">刷新时重新获取目录Url(reGetTocUrlOnRefresh)</string> <string name="pre_update_js">更新之前Js</string>
<string name="rule_book_content">正文規則 (content)</string> <string name="rule_book_content">正文規則 (content)</string>
<string name="rule_next_content">正文下一頁 URL 規則 (nextContentUrl)</string> <string name="rule_next_content">正文下一頁 URL 規則 (nextContentUrl)</string>
<string name="rule_web_js">WebViewJs (webJs)</string> <string name="rule_web_js">WebViewJs (webJs)</string>
@ -989,5 +989,6 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDav书籍</string> <string name="add_remote_book">WebDav书籍</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -419,7 +419,7 @@
<string name="rule_is_volume">Volume標識(isVolume)</string> <string name="rule_is_volume">Volume標識(isVolume)</string>
<string name="rule_is_vip">VIP標識(isVip)</string> <string name="rule_is_vip">VIP標識(isVip)</string>
<string name="rule_update_time">更新時間(ChapterInfo)</string> <string name="rule_update_time">更新時間(ChapterInfo)</string>
<string name="rule_re_get_toc_url">刷新时重新获取目录Url(reGetTocUrlOnRefresh)</string> <string name="pre_update_js">更新之前Js</string>
<string name="rule_book_content">正文規則(content)</string> <string name="rule_book_content">正文規則(content)</string>
<string name="rule_next_content">正文下一頁URL規則(nextContentUrl)</string> <string name="rule_next_content">正文下一頁URL規則(nextContentUrl)</string>
<string name="rule_web_js">WebViewJs(webJs)</string> <string name="rule_web_js">WebViewJs(webJs)</string>
@ -991,5 +991,6 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDav书籍</string> <string name="add_remote_book">WebDav书籍</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -419,7 +419,7 @@
<string name="rule_is_volume">Volume标识(isVolume)</string> <string name="rule_is_volume">Volume标识(isVolume)</string>
<string name="rule_is_vip">VIP标识(isVip)</string> <string name="rule_is_vip">VIP标识(isVip)</string>
<string name="rule_update_time">更新时间(ChapterInfo)</string> <string name="rule_update_time">更新时间(ChapterInfo)</string>
<string name="rule_re_get_toc_url">刷新时重新获取目录Url(reGetTocUrlOnRefresh)</string> <string name="pre_update_js">更新之前Js</string>
<string name="rule_book_content">正文规则(content)</string> <string name="rule_book_content">正文规则(content)</string>
<string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string> <string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string>
<string name="rule_web_js">WebViewJs(webJs)</string> <string name="rule_web_js">WebViewJs(webJs)</string>
@ -991,5 +991,6 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">上传WebDav</string> <string name="upload_to_remote">上传WebDav</string>
<string name="add_remote_book">WebDav书籍</string> <string name="add_remote_book">WebDav书籍</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -420,7 +420,7 @@
<string name="rule_is_volume">卷标识(isVolume)</string> <string name="rule_is_volume">卷标识(isVolume)</string>
<string name="rule_is_vip">VIP标识(isVip)</string> <string name="rule_is_vip">VIP标识(isVip)</string>
<string name="rule_update_time">更新时间(ChapterInfo)</string> <string name="rule_update_time">更新时间(ChapterInfo)</string>
<string name="rule_re_get_toc_url">刷新时重新获取目录Url(reGetTocUrlOnRefresh)</string> <string name="pre_update_js">更新之前Js</string>
<string name="rule_book_content">正文规则(content)</string> <string name="rule_book_content">正文规则(content)</string>
<string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string> <string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string>
<string name="rule_web_js">WebViewJs(webJs)</string> <string name="rule_web_js">WebViewJs(webJs)</string>
@ -992,5 +992,6 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</string> <string name="add_remote_book">WebDavBook</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

Loading…
Cancel
Save