diff --git a/app/src/main/assets/help/jsHelp.md b/app/src/main/assets/help/jsHelp.md index b6b0a3c79..1d2ae5eaa 100644 --- a/app/src/main/assets/help/jsHelp.md +++ b/app/src/main/assets/help/jsHelp.md @@ -51,8 +51,17 @@ java.put(key, value) ``` * 网络请求 ``` -java.ajax(urlStr) +java.ajax(urlStr): String java.ajaxAll(urlList: Array): Array +//返回Response 方法body() code() message() header() raw() toString() +java.connect(urlStr): Response + +* 使用webView访问网络 +* @param html 直接用webView载入的html, 如果html为空直接访问url +* @param url html内如果有相对路径的资源不传入url访问不了 +* @param js 用来取返回值的js语句, 没有就返回整个源代码 +* @return 返回js获取的内容 +java.webView(html: String?, url: String?, js: String?): String ``` * 调试 ``` @@ -142,7 +151,8 @@ java.md5Encode(str) java.md5Encode16(str) ``` -## book对象的可用属性 +## book对象的可用属性和方法 +### 属性 > 使用方法: 在js中或{{}}中使用book.属性的方式即可获取.如在正文内容后加上 ##{{book.name+"正文卷"+title}} 可以净化 书名+正文卷+章节名称(如 我是大明星正文卷第二章我爸是豪门总裁) 这一类的字符. ``` bookUrl // 详情页Url(本地书源存储完整文件路径) @@ -174,6 +184,11 @@ order // 手动排序 originOrder //书源排序 variable // 自定义书籍变量信息(用于书源规则检索书籍信息) ``` +### 方法 +``` +//可在正文js中关闭净化 对于漫画源有用 +book.setUseReplaceRule(boolean) +``` ## chapter对象的部分可用属性 > 使用方法: 在js中或{{}}中使用chapter.属性的方式即可获取.如在正文内容后加上 ##{{chapter.title+chapter.index}} 可以净化 章节标题+序号(如 第二章 天仙下凡2) 这一类的字符. diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 5314ea84a..0e548a43b 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -123,7 +123,9 @@ interface JsExtensions { BackstageWebView( url = url, html = html, - javaScript = js + javaScript = js, + headerMap = getSource()?.getHeaderMap(true), + tag = getSource()?.getKey() ).getStrResponse().body } } diff --git a/app/src/main/java/io/legado/app/help/glide/ImageLoader.kt b/app/src/main/java/io/legado/app/help/glide/ImageLoader.kt index aca00cd6a..b60131995 100644 --- a/app/src/main/java/io/legado/app/help/glide/ImageLoader.kt +++ b/app/src/main/java/io/legado/app/help/glide/ImageLoader.kt @@ -7,6 +7,7 @@ import android.net.Uri import androidx.annotation.DrawableRes import com.bumptech.glide.RequestBuilder import io.legado.app.constant.AppPattern.dataUriRegex +import io.legado.app.data.appDb import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.isAbsUrl import io.legado.app.utils.isContentScheme @@ -18,7 +19,7 @@ object ImageLoader { /** * 自动判断path类型 */ - fun load(context: Context, path: String?): RequestBuilder { + fun load(context: Context, path: String?, sourceOrigin: String? = null): RequestBuilder { return when { path.isNullOrEmpty() -> GlideApp.with(context).load(path) dataUriRegex.find(path) != null -> { @@ -27,7 +28,10 @@ object ImageLoader { } path.isAbsUrl() -> { kotlin.runCatching { - val url = AnalyzeUrl(path).getGlideUrl() + val source = sourceOrigin?.let { + appDb.bookSourceDao.getBookSource(it) ?: appDb.rssSourceDao.getByKey(it) + } + val url = AnalyzeUrl(path, source = source).getGlideUrl() GlideApp.with(context).load(url) }.getOrDefault( GlideApp.with(context).load(path) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index c14543cc8..cc0d64a39 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -73,7 +73,7 @@ class AnalyzeUrl( init { val urlMatcher = paramPattern.matcher(baseUrl) if (urlMatcher.find()) baseUrl = baseUrl.substring(0, urlMatcher.start()) - headerMapF?.let { + (headerMapF ?: source?.getHeaderMap(true))?.let { headerMap.putAll(it) if (it.containsKey("proxy")) { proxy = it["proxy"] diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt index 323dbfc05..92b90ac94 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt @@ -35,7 +35,7 @@ class CoverAdapter(context: Context, val callBack: CallBack) : item: SearchBook, payloads: MutableList ) = binding.run { - ivCover.load(item.coverUrl, item.name, item.author) + ivCover.load(item.coverUrl, item.name, item.author, false, item.origin) tvSource.text = item.originName } diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt index f8702072f..dc85cca72 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt @@ -43,7 +43,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) : llKind.visible() llKind.setLabels(kinds) } - ivCover.load(item.coverUrl, item.name, item.author, AppConfig.loadOnlyWifi) + ivCover.load(item.coverUrl, item.name, item.author, AppConfig.loadOnlyWifi, item.origin) } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index b809f405a..86d0b569f 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -219,7 +219,7 @@ class BookInfoActivity : } private fun showCover(book: Book) { - binding.ivCover.load(book.getDisplayCover(), book.name, book.author) + binding.ivCover.load(book.getDisplayCover(), book.name, book.author, false, book.origin) BookCover.loadBlur(this, book.getDisplayCover()) .into(binding.bgBook) } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index 7e4146a4c..f31dea1ff 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -86,7 +86,8 @@ class SearchAdapter(context: Context, val callBack: CallBack) : searchBook.coverUrl, searchBook.name, searchBook.author, - AppConfig.loadOnlyWifi + AppConfig.loadOnlyWifi, + searchBook.origin ) } } @@ -99,7 +100,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : "last" -> upLasted(binding, searchBook.latestChapterTitle) "intro" -> tvIntroduce.text = searchBook.trimIntro(context) "kind" -> upKind(binding, searchBook.getKindList()) - "cover" -> ivCover.load(searchBook.coverUrl, searchBook.name, searchBook.author) + "cover" -> ivCover.load(searchBook.coverUrl, searchBook.name, searchBook.author, false, searchBook.origin) } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt index 93be8e464..b2c2211e0 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt @@ -27,13 +27,13 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) : val bundle = payloads.getOrNull(0) as? Bundle if (bundle == null) { tvName.text = item.name - ivCover.load(item.getDisplayCover(), item.name, item.author) + ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin) upRefresh(binding, item) } else { bundle.keySet().forEach { when (it) { "name" -> tvName.text = item.name - "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author) + "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin) "refresh" -> upRefresh(binding, item) } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt index 3d19dc36f..91f1173e1 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt @@ -30,7 +30,7 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : tvAuthor.text = item.author tvRead.text = item.durChapterTitle tvLast.text = item.latestChapterTitle - ivCover.load(item.getDisplayCover(), item.name, item.author) + ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin) upRefresh(binding, item) } else { tvRead.text = item.durChapterTitle @@ -39,7 +39,7 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : when (it) { "name" -> tvName.text = item.name "author" -> tvAuthor.text = item.author - "cover" -> ivCover.load(item.getDisplayCover()) + "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin) "refresh" -> upRefresh(binding, item) } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt index c82cf3d18..d62700156 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt @@ -63,7 +63,7 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) : bundle.keySet().forEach { when (it) { "name" -> tvName.text = item.name - "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author) + "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin) "refresh" -> upRefresh(this, item) } } @@ -98,7 +98,7 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) : val item = callBack.getItem(position) if (item is Book) { tvName.text = item.name - ivCover.load(item.getDisplayCover(), item.name, item.author) + ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin) upRefresh(this, item) } root.setOnClickListener { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt index f7364fc68..456f367e0 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt @@ -64,7 +64,7 @@ class BooksAdapterList(context: Context, callBack: CallBack) : when (it) { "name" -> tvName.text = item.name "author" -> tvAuthor.text = item.author - "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author) + "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin) "refresh" -> upRefresh(this, item) } } @@ -109,7 +109,7 @@ class BooksAdapterList(context: Context, callBack: CallBack) : tvAuthor.text = item.author tvRead.text = item.durChapterTitle tvLast.text = item.latestChapterTitle - ivCover.load(item.getDisplayCover(), item.name, item.author) + ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin) flHasNew.visible() ivAuthor.visible() ivLast.visible() diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt index b3df28b0d..0fa56a4a4 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt @@ -27,7 +27,7 @@ class RssAdapter(context: Context, val callBack: CallBack) : ) { binding.apply { tvName.text = item.sourceName - ImageLoader.load(context, item.sourceIcon) + ImageLoader.load(context, item.sourceIcon, item.sourceUrl) .centerCrop() .placeholder(R.drawable.image_rss) .error(R.drawable.image_rss) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt index b2d14e9f1..85c39d029 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt @@ -38,7 +38,7 @@ class RssArticlesAdapter(context: Context, callBack: CallBack) : if (item.image.isNullOrBlank() && !callBack.isGridLayout) { imageView.gone() } else { - ImageLoader.load(context, item.image).apply { + ImageLoader.load(context, item.image, item.origin).apply { if (callBack.isGridLayout) { placeholder(R.drawable.image_rss_article) } else { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt index d92fb4b94..40a53984d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt @@ -36,7 +36,7 @@ class RssArticlesAdapter1(context: Context, callBack: CallBack) : if (item.image.isNullOrBlank() && !callBack.isGridLayout) { imageView.gone() } else { - ImageLoader.load(context, item.image).apply { + ImageLoader.load(context, item.image, item.origin).apply { if (callBack.isGridLayout) { placeholder(R.drawable.image_rss_article) } else { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt index 5a512a063..99f892bda 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt @@ -36,7 +36,7 @@ class RssArticlesAdapter2(context: Context, callBack: CallBack) : if (item.image.isNullOrBlank() && !callBack.isGridLayout) { imageView.gone() } else { - ImageLoader.load(context, item.image).apply { + ImageLoader.load(context, item.image, item.origin).apply { if (callBack.isGridLayout) { placeholder(R.drawable.image_rss_article) } else { diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt index ba0a252c2..25cde23c0 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt @@ -35,7 +35,7 @@ class RssFavoritesAdapter(context: Context, val callBack: CallBack) : if (item.image.isNullOrBlank()) { imageView.gone() } else { - ImageLoader.load(context, item.image) + ImageLoader.load(context, item.image, item.origin) .addListener(object : RequestListener { override fun onLoadFailed( e: GlideException?, diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 61b0baebe..995b1a120 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -175,7 +175,8 @@ class CoverImageView @JvmOverloads constructor( path: String? = null, name: String? = null, author: String? = null, - loadOnlyWifi: Boolean = false + loadOnlyWifi: Boolean = false, + sourceOrigin: String? = null ) { this.bitmapPath = path this.name = name?.replace(AppPattern.bdRegex, "")?.trim() @@ -186,7 +187,7 @@ class CoverImageView @JvmOverloads constructor( .centerCrop() .into(this) } else { - ImageLoader.load(context, path)//Glide自动识别http://,content://和file:// + ImageLoader.load(context, path, sourceOrigin)//Glide自动识别http://,content://和file:// .apply(RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi)) .placeholder(BookCover.defaultDrawable) .error(BookCover.defaultDrawable)