Merge pull request #498 from gedoor/master

update
pull/500/head
Antecer 4 years ago committed by GitHub
commit 964cc2d188
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      app/src/main/assets/updateLog.md
  2. 3
      app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt
  3. 22
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  4. 30
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  5. 9
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  7. 4
      app/src/main/res/values-zh-rHK/strings.xml
  8. 3
      app/src/main/res/values-zh-rTW/strings.xml
  9. 5
      app/src/main/res/values-zh/strings.xml
  10. 3
      app/src/main/res/values/strings.xml

@ -4,9 +4,13 @@
* 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。
**2020/11/22**
* 正文添加正确字体规则,可以通过文字轮廓对比将错误的文字替换为正确的文字
* js添加java.readFile("path")读取本地文件,返回BiteArray
* js添加java.queryTTF(font: ByteArray?),返回字体处理类,可以编码和轮廓互查,io.legado.app.model.analyzeRule.QueryTTF
* 正文字体处理规则修改,只能写js,不需要js标记
```
var b64=String(result).match(/ttf;base64,([^\)]+)/);
var f1 = java.queryBase64TTF(b64[1])
var f2 = java.queryTTF("/storage/emulated/0/Fonts/Source Han Sans CN Regular.ttf")
java.replaceFont(content, f1, f2, 58000,59000)
```
**2020/11/18**
* 优化导航栏

@ -9,6 +9,7 @@ data class ContentRule(
var nextContentUrl: String? = null,
var webJs: String? = null,
var sourceRegex: String? = null,
var replaceRegex: String? = null, //正文获取后处理规则
var replaceRegex: String? = null, //替换规则
var fontJs: String? = null,
var imageStyle: String? = null, //默认大小居中,FULL最大宽度
) : Parcelable

@ -242,17 +242,18 @@ interface JsExtensions {
}
fun queryTTF(path: String): QueryTTF? {
val qTTF = CacheManager.getQueryTTF(path)
val key = md5Encode16(path)
var qTTF = CacheManager.getQueryTTF(key)
if (qTTF != null) {
return qTTF
}
val font: ByteArray? = when {
path.isAbsUrl() -> runBlocking {
var x = CacheManager.getByteArray(path)
var x = CacheManager.getByteArray(key)
if (x == null) {
x = HttpHelper.simpleGetBytesAsync(path)
x?.let {
CacheManager.put(path, it)
CacheManager.put(key, it)
}
}
return@runBlocking x
@ -265,10 +266,21 @@ interface JsExtensions {
}
}
font ?: return null
return QueryTTF(font)
qTTF = QueryTTF(font)
CacheManager.put(key, qTTF)
return qTTF
}
fun replaceFont(text: String, font1: QueryTTF, font2: QueryTTF, start: Int, end: Int): String {
fun replaceFont(
text: String,
font1: QueryTTF?,
font2: QueryTTF?,
start: Int,
end: Int
): String {
if (font1 == null || font2 == null) {
return ""
}
val contentArray = text.toCharArray()
contentArray.forEachIndexed { index, s ->
if (s > start.toChar() && s < end.toChar()) {

@ -298,34 +298,6 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
return ArrayList()
}
fun getContent(ruleStr: String, text: String?): String {
if (ruleStr.isEmpty()) return ""
val ruleList = splitSourceRule(ruleStr)
var result: Any? = null
content?.let { o ->
if (ruleList.isNotEmpty()) result = o
for (sourceRule in ruleList) {
putRule(sourceRule.putMap)
result?.let {
result = when (sourceRule.mode) {
Mode.Regex -> AnalyzeByRegex.getElements(
result.toString(),
sourceRule.rule.splitNotBlank("&&")
)
Mode.Js -> evalJS(sourceRule.rule, result, text)
Mode.Json -> getAnalyzeByJSonPath(it).getList(sourceRule.rule)
Mode.XPath -> getAnalyzeByXPath(it).getElements(sourceRule.rule)
else -> getAnalyzeByJSoup(it).getElements(sourceRule.rule)
}
if (sourceRule.replaceRegex.isNotEmpty()) {
result = replaceRegex(result.toString(), sourceRule)
}
}
}
}
return result?.toString() ?: ""
}
/**
* 保存变量
*/
@ -649,7 +621,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
/**
* 执行JS
*/
private fun evalJS(jsStr: String, result: Any?, content: String? = null): Any? {
fun evalJS(jsStr: String, result: Any?, content: String? = null): Any? {
val bindings = SimpleBindings()
bindings["java"] = this
bindings["cookie"] = CookieStore

@ -92,9 +92,14 @@ object BookContent {
}
content.deleteCharAt(content.length - 1)
var contentStr = content.toString().htmlFormat()
val replaceRegex = bookSource.ruleContent?.replaceRegex
val fontJs = contentRule.fontJs
if (!fontJs.isNullOrBlank()) {
contentStr = analyzeRule.evalJS(fontJs, body, contentStr)?.toString() ?: ""
}
val replaceRegex = contentRule.replaceRegex
if (!replaceRegex.isNullOrEmpty()) {
contentStr = analyzeRule.getContent(replaceRegex, contentStr)
analyzeRule.setContent(contentStr)
contentStr = analyzeRule.getString(replaceRegex)
}
Debug.log(bookSource.bookSourceUrl, "┌获取章节名称")
Debug.log(bookSource.bookSourceUrl, "${bookChapter.title}")

@ -236,6 +236,7 @@ class BookSourceEditActivity :
add(EditEntity("webJs", cr?.webJs, R.string.rule_web_js))
add(EditEntity("sourceRegex", cr?.sourceRegex, R.string.rule_source_regex))
add(EditEntity("replaceRegex", cr?.replaceRegex, R.string.rule_replace_regex))
add(EditEntity("fontJs", cr?.fontJs, R.string.rule_font_js))
add(EditEntity("imageStyle", cr?.imageStyle, R.string.rule_image_style))
}
//发现
@ -339,6 +340,7 @@ class BookSourceEditActivity :
"webJs" -> contentRule.webJs = it.value
"sourceRegex" -> contentRule.sourceRegex = it.value
"replaceRegex" -> contentRule.replaceRegex = it.value
"fontJs" -> contentRule.fontJs = it.value
"imageStyle" -> contentRule.imageStyle = it.value
}
}

@ -412,7 +412,7 @@
<string name="rule_next_content">正文下一頁 URL 規則 (nextContentUrl)</string>
<string name="rule_web_js">webJs</string>
<string name="rule_source_regex">資源正則 (sourceRegex)</string>
<string name="rule_font_js">字体处理js</string>
<string name="source_icon">圖標 (sourceIcon)</string>
<string name="r_articles">列表規則 (ruleArticles)</string>
<string name="r_next">列表下一頁規則 (ruleArticles)</string>
@ -730,7 +730,7 @@
<string name="restore_ignore_summary">恢復時忽略一些內容不恢復,方便不同手機配置不同</string>
<string name="read_config">閱讀界面設置</string>
<string name="rule_image_style">图片样式(imageStyle)</string>
<string name="rule_replace_regex">正文获取后处理规则(replaceRegex)</string>
<string name="rule_replace_regex">替换规则(replaceRegex)</string>
<string name="group_name">分組名稱</string>
<string name="note_content">備註內容</string>
<string name="replace_enable_default_t">默认启用替换净化</string>

@ -730,7 +730,8 @@
<string name="restore_ignore_summary">復原時忽略一些內容不復原,方便不同手機配置不同</string>
<string name="read_config">閱讀介面設定</string>
<string name="rule_image_style">圖片樣式(imageStyle)</string>
<string name="rule_replace_regex">正文获取后处理规则(replaceRegex)</string>
<string name="rule_replace_regex">取代規則(replaceRegex)</string>
<string name="rule_font_js">字体处理js</string>
<string name="group_name">分組名稱</string>
<string name="note_content">備註內容</string>
<string name="replace_enable_default_t">預設啟用取代淨化</string>

@ -417,6 +417,9 @@
<string name="rule_book_content">正文规则(content)</string>
<string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string>
<string name="rule_web_js">webJs</string>
<string name="rule_image_style">图片样式(imageStyle)</string>
<string name="rule_replace_regex">替换规则(replaceRegex)</string>
<string name="rule_font_js">字体处理js</string>
<string name="rule_source_regex">资源正则(sourceRegex)</string>
<string name="source_icon">图标(sourceIcon)</string>
@ -734,8 +737,6 @@
<string name="restore_ignore">恢复忽略列表</string>
<string name="restore_ignore_summary">恢复时忽略一些内容不恢复,方便不同手机配置不同</string>
<string name="read_config">阅读界面设置</string>
<string name="rule_image_style">图片样式(imageStyle)</string>
<string name="rule_replace_regex">正文获取后处理规则(replaceRegex)</string>
<string name="group_name">分组名称</string>
<string name="note_content">备注内容</string>
<string name="replace_enable_default_t">默认启用替换净化</string>

@ -420,7 +420,8 @@
<string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string>
<string name="rule_web_js">webJs</string>
<string name="rule_source_regex">资源正则(sourceRegex)</string>
<string name="rule_replace_regex">正文获取后处理规则(replaceRegex)</string>
<string name="rule_replace_regex">替换规则(replaceRegex)</string>
<string name="rule_font_js">字体处理js</string>
<string name="rule_image_style">图片样式(imageStyle)</string>
<string name="source_icon">图标(sourceIcon)</string>

Loading…
Cancel
Save