fix preUpdateJs rule

pull/2048/head
821938089 2 years ago
parent 2e041fcf52
commit 664eca08d6
  1. 5
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  2. 5
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -18,6 +18,7 @@ import io.legado.app.help.BookHelp
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.BookCover import io.legado.app.model.BookCover
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
@ -153,6 +154,10 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
chapterListData.postValue(emptyList()) chapterListData.postValue(emptyList())
} else { } else {
bookSource?.let { bookSource -> bookSource?.let { bookSource ->
val preUpdateJs = bookSource.ruleToc?.preUpdateJs
if (!preUpdateJs.isNullOrBlank()) {
AnalyzeRule(book, bookSource).evalJS(preUpdateJs)
}
WebBook.getChapterList(this, bookSource, book) WebBook.getChapterList(this, bookSource, book)
.onSuccess(IO) { .onSuccess(IO) {
if (inBookshelf) { if (inBookshelf) {

@ -21,6 +21,7 @@ import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
@ -144,6 +145,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
} else { } else {
ReadBook.bookSource?.let { ReadBook.bookSource?.let {
val preUpdateJs = it.ruleToc?.preUpdateJs
if (!preUpdateJs.isNullOrBlank()) {
AnalyzeRule(book, it).evalJS(preUpdateJs)
}
WebBook.getChapterList(viewModelScope, it, book) WebBook.getChapterList(viewModelScope, it, book)
.onSuccess(IO) { cList -> .onSuccess(IO) { cList ->
appDb.bookChapterDao.insert(*cList.toTypedArray()) appDb.bookChapterDao.insert(*cList.toTypedArray())

Loading…
Cancel
Save