pull/1065/head
Celeter 4 years ago
parent 545a312e55
commit 9d69345023
  1. 69
      app/src/main/assets/help/ruleHelp.md
  2. 12
      app/src/main/assets/updateLog.md
  3. 16
      app/src/main/java/io/legado/app/constant/AppConst.kt
  4. 2
      app/src/main/java/io/legado/app/constant/AppPattern.kt
  5. 2
      app/src/main/java/io/legado/app/help/BookHelp.kt
  6. 22
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  7. 2
      app/src/main/java/io/legado/app/model/Debug.kt
  8. 8
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  9. 2
      app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
  10. 14
      build.gradle

@ -11,6 +11,12 @@
: regex规则,不可省略,只可以用在书籍列表和目录列表 : regex规则,不可省略,只可以用在书籍列表和目录列表
``` ```
* 获取登录后的cookie
```
java.getCookie("http://baidu.com", null) => userid=1234;pwd=adbcd
java.getCookie("http://baidu.com", "userid") => 1234
```
* 请求头,支持http代理,socks4 socks5代理设置 * 请求头,支持http代理,socks4 socks5代理设置
``` ```
socks5代理 socks5代理
@ -39,6 +45,49 @@ cache 变量-缓存操作类,方法见 io.legado.app.help.CacheManager
chapter 变量-当前目录类,方法见 io.legado.app.data.entities.BookChapter chapter 变量-当前目录类,方法见 io.legado.app.data.entities.BookChapter
title 变量-当前标题,String title 变量-当前标题,String
src 内容,源码 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<String, String>)`
* `java.post(urlStr: String, body: String, headers: Map<String, String>)`
* 对于搜索重定向的源,可以使用此方法获得重定向后的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;"}
};
'<img src="'+src+","+JSON.stringify(options)+'">'
``` ```
## 部分js对象属性说明 ## 部分js对象属性说明
@ -95,14 +144,16 @@ variable // 自定义书籍变量信息(用于书源规则检索书籍信息)
### 字体解析使用 ### 字体解析使用
> 使用方法,在正文替换规则中使用,原理根据f1字体的字形数据到f2中查找字形对应的编码 > 使用方法,在正文替换规则中使用,原理根据f1字体的字形数据到f2中查找字形对应的编码
``` ```
@js: <js>
var b64=String(src).match(/ttf;base64,([^\)]+)/); (function(){
if (b64) { var b64=String(src).match(/ttf;base64,([^\)]+)/);
var f1 = java.queryBase64TTF(b64[1]) if(b64){
var f2 = java.queryTTF("/storage/emulated/0/Fonts/Source Han Sans CN Regular.ttf") var f1 = java.queryBase64TTF(b64[1]);
java.replaceFont(result, f1, f2) var f2 = java.queryTTF("https://alanskycn.gitee.io/teachme/assets/font/Source Han Sans CN Regular.ttf");
}else{ return java.replaceFont(result, f1, f2);
result }
} return result;
})()
</js>
``` ```

@ -18,6 +18,18 @@
* 添加书架文件夹分组样式,未完成 * 添加书架文件夹分组样式,未完成
* viewPager2 3层嵌套有问题,书架换回viewPager * 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** **2021/05/26**
* 书签绑定书名与作者 * 书签绑定书名与作者
* 修复详情页目录问题 * 修复详情页目录问题

@ -38,9 +38,9 @@ object AppConst {
val keyboardToolChars: List<String> by lazy { val keyboardToolChars: List<String> by lazy {
arrayListOf( arrayListOf(
"", "@css:", "<js></js>", "{{}}", "&&", "%%", "||", "//", "$.", "@", "", "@css:", "<js></js>", "{{}}", "##", "&&", "%%", "||", "//", "$.",
"\\", ":", "class", "id", "href", "textNodes", "ownText", "all", "html", "@", ":", "class", "text", "href", "textNodes", "ownText", "all", "html",
"[", "]", "<", ">", "##", "!", ".", "+", "-", "*", "=",",{\"webView\":true}" "[", "]", "<", ">", "#", "!", ".", "+", "-", "*", "=", "{'webView': true}"
) )
} }
@ -57,10 +57,12 @@ object AppConst {
val urlOption: String by lazy { val urlOption: String by lazy {
""" """
,{ ,{
"charset": "", 'charset': '',
"method": "POST", 'method': 'POST',
"body": "", 'body': '',
"headers": {"User-Agent": ""} 'headers': {
'User-Agent': ''
}
} }
""".trimIndent() """.trimIndent()
} }

@ -9,7 +9,7 @@ object AppPattern {
val EXP_PATTERN: Pattern = Pattern.compile("\\{\\{([\\w\\W]*?)\\}\\}") val EXP_PATTERN: Pattern = Pattern.compile("\\{\\{([\\w\\W]*?)\\}\\}")
//图片有data-开头的数据属性时优先用数据属性作为src,没有数据属性时才匹配src //图片有data-开头的数据属性时优先用数据属性作为src,没有数据属性时才匹配src
val imgPattern: Pattern = val imgPattern: Pattern =
Pattern.compile("<img .*?src.*?=.*?\"(.*?(?:,\\{.*\\})?)\".*?>", Pattern.CASE_INSENSITIVE) Pattern.compile("<img\\s*[^>]*src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>", Pattern.CASE_INSENSITIVE)
val nameRegex = Regex("\\s+作\\s*者.*|\\s+\\S+\\s+著") val nameRegex = Regex("\\s+作\\s*者.*|\\s+\\S+\\s+著")
val authorRegex = Regex("^.*?作\\s*者[::\\s]*|\\s+著") val authorRegex = Regex("^.*?作\\s*者[::\\s]*|\\s+著")

@ -38,7 +38,7 @@ object BookHelp {
} }
/** /**
* 已删除书的缓存 * 已删除书的缓存
*/ */
fun clearRemovedCache() { fun clearRemovedCache() {
Coroutine.async { Coroutine.async {

@ -311,9 +311,9 @@ interface JsExtensions {
* @param font2 正确的字体 * @param font2 正确的字体
*/ */
fun replaceFont( fun replaceFont(
text: String, text: String,
font1: QueryTTF?, font1: QueryTTF?,
font2: QueryTTF? font2: QueryTTF?
): String { ): String {
if (font1 == null || font2 == null) return text if (font1 == null || font2 == null) return text
val contentArray = text.toCharArray() val contentArray = text.toCharArray()
@ -346,7 +346,7 @@ interface JsExtensions {
str: String, str: String,
key: String, key: String,
transformation: String, transformation: String,
iv: String = "" iv: String
): ByteArray? { ): ByteArray? {
return EncoderUtils.decryptAES( return EncoderUtils.decryptAES(
@ -369,7 +369,7 @@ interface JsExtensions {
str: String, str: String,
key: String, key: String,
transformation: String, transformation: String,
iv: String = "" iv: String
): String? { ): String? {
return aesDecodeToByteArray(str, key, transformation, iv)?.let { String(it) } return aesDecodeToByteArray(str, key, transformation, iv)?.let { String(it) }
} }
@ -386,7 +386,7 @@ interface JsExtensions {
str: String, str: String,
key: String, key: String,
transformation: String, transformation: String,
iv: String = "" iv: String
): ByteArray? { ): ByteArray? {
return EncoderUtils.decryptBase64AES( return EncoderUtils.decryptBase64AES(
data = str.encodeToByteArray(), data = str.encodeToByteArray(),
@ -408,7 +408,7 @@ interface JsExtensions {
str: String, str: String,
key: String, key: String,
transformation: String, transformation: String,
iv: String = "" iv: String
): String? { ): String? {
return aesBase64DecodeToByteArray(str, key, transformation, iv)?.let { String(it) } return aesBase64DecodeToByteArray(str, key, transformation, iv)?.let { String(it) }
} }
@ -422,7 +422,7 @@ interface JsExtensions {
*/ */
fun aesEncodeToByteArray( fun aesEncodeToByteArray(
data: String, key: String, transformation: String, data: String, key: String, transformation: String,
iv: String = "" iv: String
): ByteArray? { ): ByteArray? {
return EncoderUtils.encryptAES( return EncoderUtils.encryptAES(
data.encodeToByteArray(), data.encodeToByteArray(),
@ -441,7 +441,7 @@ interface JsExtensions {
*/ */
fun aesEncodeToString( fun aesEncodeToString(
data: String, key: String, transformation: String, data: String, key: String, transformation: String,
iv: String = "" iv: String
): String? { ): String? {
return aesEncodeToByteArray(data, key, transformation, iv)?.let { String(it) } return aesEncodeToByteArray(data, key, transformation, iv)?.let { String(it) }
} }
@ -455,7 +455,7 @@ interface JsExtensions {
*/ */
fun aesEncodeToBase64ByteArray( fun aesEncodeToBase64ByteArray(
data: String, key: String, transformation: String, data: String, key: String, transformation: String,
iv: String = "" iv: String
): ByteArray? { ): ByteArray? {
return EncoderUtils.encryptAES2Base64( return EncoderUtils.encryptAES2Base64(
data.encodeToByteArray(), data.encodeToByteArray(),
@ -474,7 +474,7 @@ interface JsExtensions {
*/ */
fun aesEncodeToBase64String( fun aesEncodeToBase64String(
data: String, key: String, transformation: String, data: String, key: String, transformation: String,
iv: String = "" iv: String
): String? { ): String? {
return aesEncodeToBase64ByteArray(data, key, transformation, iv)?.let { String(it) } return aesEncodeToBase64ByteArray(data, key, transformation, iv)?.let { String(it) }
} }

@ -187,7 +187,7 @@ object Debug {
private fun infoDebug(scope: CoroutineScope, webBook: WebBook, book: Book) { private fun infoDebug(scope: CoroutineScope, webBook: WebBook, book: Book) {
if (book.tocUrl.isNotBlank()) { if (book.tocUrl.isNotBlank()) {
log(debugSource, "目录url不为空,详情页已解析") log(debugSource, "≡已获取目录链接,跳过详情页")
log(debugSource, showTime = false) log(debugSource, showTime = false)
tocDebug(scope, webBook, book) tocDebug(scope, webBook, book)
return return

@ -190,12 +190,12 @@ object BookChapterList {
chapterList.add(bookChapter) 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, "${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, "${chapterList[0].url}", log)
Debug.log(bookSource.bookSourceUrl, "┌首章信息", log) Debug.log(bookSource.bookSourceUrl, "获取首章信息", log)
Debug.log(bookSource.bookSourceUrl, "${chapterList[0].tag}", log) Debug.log(bookSource.bookSourceUrl, "${chapterList[0].tag}", log)
} }
return ChapterData(chapterList, nextUrlList) return ChapterData(chapterList, nextUrlList)

@ -13,7 +13,7 @@ object HtmlFormatter {
html ?: return "" html ?: return ""
return html.replace(wrapHtmlRegex, "\n") return html.replace(wrapHtmlRegex, "\n")
.replace(otherRegex, "") .replace(otherRegex, "")
.replace("^[\\n\\s]+".toRegex(), "  ") .replace("^[\\n\\s]*".toRegex(), "  ")
.replace("[\\n\\s]+$".toRegex(), "") .replace("[\\n\\s]+$".toRegex(), "")
.replace("\\s*\\n+\\s*".toRegex(), "\n  ") .replace("\\s*\\n+\\s*".toRegex(), "\n  ")
} }

@ -4,24 +4,22 @@ buildscript {
ext.kotlin_version = '1.5.10' ext.kotlin_version = '1.5.10'
repositories { repositories {
google() google()
maven { url 'https://maven.aliyun.com/repository/public/'} 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://maven.aliyun.com/repository/gradle-plugin" } maven { url 'https://plugins.gradle.org/m2/' }
maven { url "https://plugins.gradle.org/m2/" }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.2.1' classpath 'com.android.tools.build:gradle:4.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.timfreiheit.resourceplaceholders:placeholders:0.3" classpath 'de.timfreiheit.resourceplaceholders:placeholders:0.3'
} }
} }
allprojects { allprojects {
repositories { repositories {
google() google()
maven { url 'https://maven.aliyun.com/repository/public/' } maven { url 'https://maven.aliyun.com/repository/public' }
maven { url "https://jitpack.io" } maven { url 'https://jitpack.io' }
maven { url "https://maven.google.com/" }
} }
} }

Loading…
Cancel
Save