From 9d69345023cf883b658931ca76a5d783c810cfd7 Mon Sep 17 00:00:00 2001 From: Celeter Date: Tue, 15 Jun 2021 16:35:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/help/ruleHelp.md | 69 ++++++++++++++++--- app/src/main/assets/updateLog.md | 12 ++++ .../java/io/legado/app/constant/AppConst.kt | 16 +++-- .../java/io/legado/app/constant/AppPattern.kt | 2 +- .../main/java/io/legado/app/help/BookHelp.kt | 2 +- .../java/io/legado/app/help/JsExtensions.kt | 22 +++--- .../main/java/io/legado/app/model/Debug.kt | 2 +- .../app/model/webBook/BookChapterList.kt | 8 +-- .../java/io/legado/app/utils/HtmlFormatter.kt | 2 +- build.gradle | 14 ++-- 10 files changed, 106 insertions(+), 43 deletions(-) diff --git a/app/src/main/assets/help/ruleHelp.md b/app/src/main/assets/help/ruleHelp.md index 4d50dde6c..01eb44eba 100644 --- a/app/src/main/assets/help/ruleHelp.md +++ b/app/src/main/assets/help/ruleHelp.md @@ -11,6 +11,12 @@ : regex规则,不可省略,只可以用在书籍列表和目录列表 ``` +* 获取登录后的cookie +``` +java.getCookie("http://baidu.com", null) => userid=1234;pwd=adbcd +java.getCookie("http://baidu.com", "userid") => 1234 +``` + * 请求头,支持http代理,socks4 socks5代理设置 ``` socks5代理 @@ -39,6 +45,49 @@ cache 变量-缓存操作类,方法见 io.legado.app.help.CacheManager chapter 变量-当前目录类,方法见 io.legado.app.data.entities.BookChapter title 变量-当前标题,String src 内容,源码 +``` + +* url添加js参数,解析url时执行,可在访问url时处理url,例 +``` +https://www.baidu.com,{"js":"java.headerMap.put('xxx', 'yyy')"} +https://www.baidu.com,{"js":"java.url=java.url+'yyyy'"} +``` + +* 增加js方法,用于重定向拦截 + * `java.get(urlStr: String, headers: Map)` + * `java.post(urlStr: String, body: String, headers: Map)` +* 对于搜索重定向的源,可以使用此方法获得重定向后的url +``` +(()=>{ + if(page==1){ + let url='https://www.yooread.net/e/search/index.php,'+JSON.stringify({ + "method":"POST", + "body":"show=title&tempid=1&keyboard="+key + }); + return java.put('surl',String(java.connect(url).raw().request().url())); + } else { + return java.get('surl')+'&page='+(page-1) + } +})() +或者 +(()=>{ + let base='https://www.yooread.net/e/search/'; + if(page==1){ + let url=base+'index.php'; + let body='show=title&tempid=1&keyboard='+key; + return base+java.put('surl',java.post(url,body,{}).header("Location")); + } else { + return base+java.get('surl')+'&page='+(page-1); + } +})() +``` + +* 正文图片链接支持修改headers +``` +let options = { +"headers": {"User-Agent": "xxxx","Referrer":baseUrl,"Cookie":"aaa=vbbb;"} +}; +'' ``` ## 部分js对象属性说明 @@ -95,14 +144,16 @@ variable // 自定义书籍变量信息(用于书源规则检索书籍信息) ### 字体解析使用 > 使用方法,在正文替换规则中使用,原理根据f1字体的字形数据到f2中查找字形对应的编码 ``` -@js: -var b64=String(src).match(/ttf;base64,([^\)]+)/); -if (b64) { - var f1 = java.queryBase64TTF(b64[1]) - var f2 = java.queryTTF("/storage/emulated/0/Fonts/Source Han Sans CN Regular.ttf") - java.replaceFont(result, f1, f2) -}else{ - result -} + +(function(){ + var b64=String(src).match(/ttf;base64,([^\)]+)/); + if(b64){ + var f1 = java.queryBase64TTF(b64[1]); + var f2 = java.queryTTF("https://alanskycn.gitee.io/teachme/assets/font/Source Han Sans CN Regular.ttf"); + return java.replaceFont(result, f1, f2); + } + return result; +})() + ``` diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 0daafa351..20e915987 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -18,6 +18,18 @@ * 添加书架文件夹分组样式,未完成 * viewPager2 3层嵌套有问题,书架换回viewPager +**2021/05/29** +* 谷歌版可使用外部epub模板 +* Asset文件夹下二级以内目录全文件读取,Asset->文件夹->文件 +* epub元数据修改,使修改字体只对正文生效 +* 修复epub模板文件的排序问题 +* epub可自定义模板,模板路径为书籍导出目录的Asset文件夹,[模板范例](https://wwa.lanzoux.com/ibjBspkn05i) +``` +Asset中里面必须有Text文件夹,Text文件夹里必须有chapter.html,否则导出正文会为空 +chapter.html的关键字有{title}、{content} +其他html文件的关键字有{name}、{author}、{intro}、{kind}、{wordCount} +``` + **2021/05/26** * 书签绑定书名与作者 * 修复详情页目录问题 diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index a7db60a2d..e76b28df3 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -38,9 +38,9 @@ object AppConst { val keyboardToolChars: List by lazy { arrayListOf( - "❓", "@css:", "", "{{}}", "&&", "%%", "||", "//", "$.", "@", - "\\", ":", "class", "id", "href", "textNodes", "ownText", "all", "html", - "[", "]", "<", ">", "##", "!", ".", "+", "-", "*", "=",",{\"webView\":true}" + "❓", "@css:", "", "{{}}", "##", "&&", "%%", "||", "//", "$.", + "@", ":", "class", "text", "href", "textNodes", "ownText", "all", "html", + "[", "]", "<", ">", "#", "!", ".", "+", "-", "*", "=", "{'webView': true}" ) } @@ -57,10 +57,12 @@ object AppConst { val urlOption: String by lazy { """ ,{ - "charset": "", - "method": "POST", - "body": "", - "headers": {"User-Agent": ""} + 'charset': '', + 'method': 'POST', + 'body': '', + 'headers': { + 'User-Agent': '' + } } """.trimIndent() } diff --git a/app/src/main/java/io/legado/app/constant/AppPattern.kt b/app/src/main/java/io/legado/app/constant/AppPattern.kt index cea60d9c5..342f2a207 100644 --- a/app/src/main/java/io/legado/app/constant/AppPattern.kt +++ b/app/src/main/java/io/legado/app/constant/AppPattern.kt @@ -9,7 +9,7 @@ object AppPattern { val EXP_PATTERN: Pattern = Pattern.compile("\\{\\{([\\w\\W]*?)\\}\\}") //图片有data-开头的数据属性时优先用数据属性作为src,没有数据属性时才匹配src val imgPattern: Pattern = - Pattern.compile("", Pattern.CASE_INSENSITIVE) + Pattern.compile("]*src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>", Pattern.CASE_INSENSITIVE) val nameRegex = Regex("\\s+作\\s*者.*|\\s+\\S+\\s+著") val authorRegex = Regex("^.*?作\\s*者[::\\s]*|\\s+著") diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 99adf90b1..6379d4cc3 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -38,7 +38,7 @@ object BookHelp { } /** - * 清楚已删除书的缓存 + * 清除已删除书的缓存 */ fun clearRemovedCache() { Coroutine.async { 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 43fcd60a9..a3698c76c 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -311,9 +311,9 @@ interface JsExtensions { * @param font2 正确的字体 */ fun replaceFont( - text: String, - font1: QueryTTF?, - font2: QueryTTF? + text: String, + font1: QueryTTF?, + font2: QueryTTF? ): String { if (font1 == null || font2 == null) return text val contentArray = text.toCharArray() @@ -346,7 +346,7 @@ interface JsExtensions { str: String, key: String, transformation: String, - iv: String = "" + iv: String ): ByteArray? { return EncoderUtils.decryptAES( @@ -369,7 +369,7 @@ interface JsExtensions { str: String, key: String, transformation: String, - iv: String = "" + iv: String ): String? { return aesDecodeToByteArray(str, key, transformation, iv)?.let { String(it) } } @@ -386,7 +386,7 @@ interface JsExtensions { str: String, key: String, transformation: String, - iv: String = "" + iv: String ): ByteArray? { return EncoderUtils.decryptBase64AES( data = str.encodeToByteArray(), @@ -408,7 +408,7 @@ interface JsExtensions { str: String, key: String, transformation: String, - iv: String = "" + iv: String ): String? { return aesBase64DecodeToByteArray(str, key, transformation, iv)?.let { String(it) } } @@ -422,7 +422,7 @@ interface JsExtensions { */ fun aesEncodeToByteArray( data: String, key: String, transformation: String, - iv: String = "" + iv: String ): ByteArray? { return EncoderUtils.encryptAES( data.encodeToByteArray(), @@ -441,7 +441,7 @@ interface JsExtensions { */ fun aesEncodeToString( data: String, key: String, transformation: String, - iv: String = "" + iv: String ): String? { return aesEncodeToByteArray(data, key, transformation, iv)?.let { String(it) } } @@ -455,7 +455,7 @@ interface JsExtensions { */ fun aesEncodeToBase64ByteArray( data: String, key: String, transformation: String, - iv: String = "" + iv: String ): ByteArray? { return EncoderUtils.encryptAES2Base64( data.encodeToByteArray(), @@ -474,7 +474,7 @@ interface JsExtensions { */ fun aesEncodeToBase64String( data: String, key: String, transformation: String, - iv: String = "" + iv: String ): String? { return aesEncodeToBase64ByteArray(data, key, transformation, iv)?.let { String(it) } } diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index d8e606b0f..dc6259cc4 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -187,7 +187,7 @@ object Debug { private fun infoDebug(scope: CoroutineScope, webBook: WebBook, book: Book) { if (book.tocUrl.isNotBlank()) { - log(debugSource, "目录url不为空,详情页已解析") + log(debugSource, "≡已获取目录链接,跳过详情页") log(debugSource, showTime = false) tocDebug(scope, webBook, book) return diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 06ae294b4..24bf4981e 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -190,12 +190,12 @@ object BookChapterList { chapterList.add(bookChapter) } } - Debug.log(bookSource.bookSourceUrl, "└解析目录列表完成", log) - Debug.log(bookSource.bookSourceUrl, "┌首章名称", log) + Debug.log(bookSource.bookSourceUrl, "└目录列表解析完成", log) + Debug.log(bookSource.bookSourceUrl, "┌获取首章名称", log) Debug.log(bookSource.bookSourceUrl, "└${chapterList[0].title}", log) - Debug.log(bookSource.bookSourceUrl, "┌首章链接", log) + Debug.log(bookSource.bookSourceUrl, "┌获取首章链接", log) Debug.log(bookSource.bookSourceUrl, "└${chapterList[0].url}", log) - Debug.log(bookSource.bookSourceUrl, "┌首章信息", log) + Debug.log(bookSource.bookSourceUrl, "┌获取首章信息", log) Debug.log(bookSource.bookSourceUrl, "└${chapterList[0].tag}", log) } return ChapterData(chapterList, nextUrlList) diff --git a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt index 21d45d62c..7d11df2b4 100644 --- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt +++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt @@ -13,7 +13,7 @@ object HtmlFormatter { html ?: return "" return html.replace(wrapHtmlRegex, "\n") .replace(otherRegex, "") - .replace("^[\\n\\s]+".toRegex(), "  ") + .replace("^[\\n\\s]*".toRegex(), "  ") .replace("[\\n\\s]+$".toRegex(), "") .replace("\\s*\\n+\\s*".toRegex(), "\n  ") } diff --git a/build.gradle b/build.gradle index 894cbf12f..ae689e1a9 100644 --- a/build.gradle +++ b/build.gradle @@ -4,24 +4,22 @@ buildscript { ext.kotlin_version = '1.5.10' repositories { google() - maven { url 'https://maven.aliyun.com/repository/public/'} - maven { url "https://s3.amazonaws.com/fabric-artifacts/public" } - maven { url "https://maven.aliyun.com/repository/gradle-plugin" } - maven { url "https://plugins.gradle.org/m2/" } + maven { url 'https://maven.aliyun.com/repository/public' } + maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } + maven { url 'https://plugins.gradle.org/m2/' } } dependencies { classpath 'com.android.tools.build:gradle:4.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "de.timfreiheit.resourceplaceholders:placeholders:0.3" + classpath 'de.timfreiheit.resourceplaceholders:placeholders:0.3' } } allprojects { repositories { google() - maven { url 'https://maven.aliyun.com/repository/public/' } - maven { url "https://jitpack.io" } - maven { url "https://maven.google.com/" } + maven { url 'https://maven.aliyun.com/repository/public' } + maven { url 'https://jitpack.io' } } }