去掉fontJs,直接写在替换规则里

pull/517/head
gedoor 4 years ago
parent 9f46e1031e
commit 8c9ef11fcc
  1. 1
      app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt
  2. 25
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  3. 7
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  5. 3
      app/src/main/res/values-zh-rHK/strings.xml
  6. 3
      app/src/main/res/values-zh-rTW/strings.xml
  7. 3
      app/src/main/res/values-zh/strings.xml
  8. 3
      app/src/main/res/values/strings.xml

@ -10,6 +10,5 @@ data class ContentRule(
var webJs: String? = null,
var sourceRegex: String? = null,
var replaceRegex: String? = null, //替换规则
var fontJs: String? = null,
var imageStyle: String? = null, //默认大小居中,FULL最大宽度
) : Parcelable

@ -25,8 +25,7 @@ import kotlin.collections.HashMap
@Suppress("unused", "RegExpRedundantEscape")
class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
var chapter: BookChapter? = null
var content: Any? = null
private set
private var content: Any? = null
private var baseUrl: String? = null
private var baseURL: URL? = null
private var isJSON: Boolean = false
@ -178,20 +177,24 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
* 获取文本
*/
@JvmOverloads
fun getString(ruleStr: String?, isUrl: Boolean = false): String {
fun getString(ruleStr: String?, isUrl: Boolean = false, value: String? = null): String {
if (TextUtils.isEmpty(ruleStr)) return ""
val ruleList = splitSourceRule(ruleStr)
return getString(ruleList, isUrl)
return getString(ruleList, isUrl, value)
}
@JvmOverloads
fun getString(ruleList: List<SourceRule>, isUrl: Boolean = false): String {
var result: Any? = null
fun getString(
ruleList: List<SourceRule>,
isUrl: Boolean = false,
value: String? = null
): String {
var result: Any? = value
val content = this.content
if (content != null && ruleList.isNotEmpty()) {
result = content
if (content is NativeObject) {
result = content[ruleList[0].rule]?.toString()
if ((content != null || result != null) && ruleList.isNotEmpty()) {
if (result == null) result = content
if (result is NativeObject) {
result = result[ruleList[0].rule]?.toString()
} else {
for (sourceRule in ruleList) {
putRule(sourceRule.putMap)
@ -622,7 +625,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
/**
* 执行JS
*/
fun evalJS(jsStr: String, result: Any?, content: String? = null): Any? {
fun evalJS(jsStr: String, result: Any?): Any? {
val bindings = SimpleBindings()
bindings["java"] = this
bindings["cookie"] = CookieStore

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

@ -236,7 +236,6 @@ 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))
}
//发现
@ -340,7 +339,6 @@ 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
}
}

@ -410,9 +410,8 @@
<string name="rule_update_time">更新時間 (ChapterInfo)</string>
<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_web_js">WebViewJs(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>

@ -411,7 +411,7 @@
<string name="rule_update_time">更新時間(ChapterInfo)</string>
<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_web_js">WebViewJs(webJs)</string>
<string name="rule_source_regex">資源正則(sourceRegex)</string>
<string name="source_icon">圖示(sourceIcon)</string>
@ -729,7 +729,6 @@
<string name="read_config">閱讀介面設定</string>
<string name="rule_image_style">圖片樣式(imageStyle)</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>

@ -416,10 +416,9 @@
<string name="rule_update_time">更新时间(ChapterInfo)</string>
<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_web_js">WebViewJs(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>

@ -418,10 +418,9 @@
<string name="rule_update_time">更新时间(ChapterInfo)</string>
<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_web_js">WebViewJs(webJs)</string>
<string name="rule_source_regex">资源正则(sourceRegex)</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