优化链接分割规则,避免附加参数中存在 ,{ 时导致规则切错

修复<str0,str2,...{{js}}>这种页数列表写法中,js部分内含 < 或 > 会切割错误的问题

格式化图片和匹配图片规则不在使用同一个正则,加快图片处理速度。

优化一下不需要循环执行却被循环执行的操作
pull/1123/head
bushixuanqi 3 years ago
parent 5a4cbba1d2
commit 223b724306
  1. 3
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  2. 10
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  3. 9
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@ -394,10 +394,7 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
1 1
}else 0 }else 0
var tmp: String var tmp: String
val jsMatcher = JS_PATTERN.matcher(ruleStr) val jsMatcher = JS_PATTERN.matcher(ruleStr)
while (jsMatcher.find()){ while (jsMatcher.find()){
if (jsMatcher.start() > start) { if (jsMatcher.start() > start) {
tmp = ruleStr.substring(start, jsMatcher.start()).trim { it <= ' ' } tmp = ruleStr.substring(start, jsMatcher.start()).trim { it <= ' ' }

@ -142,18 +142,14 @@ class AnalyzeUrl(
*/ */
private fun initUrl() { //replaceKeyPageJs已经替换掉额外内容,此处url是基础形式,可以直接切首个‘,’之前字符串。 private fun initUrl() { //replaceKeyPageJs已经替换掉额外内容,此处url是基础形式,可以直接切首个‘,’之前字符串。
var pos = ruleUrl.indexOf(',')
urlHasQuery = ruleUrl.substringBefore(',') urlHasQuery = ruleUrl.substringBefore(',')
url = NetworkUtils.getAbsoluteURL(baseUrl,urlHasQuery ) url = NetworkUtils.getAbsoluteURL(baseUrl,urlHasQuery )
NetworkUtils.getBaseUrl(url)?.let { NetworkUtils.getBaseUrl(url)?.let {
baseUrl = it baseUrl = it
} }
if(pos != -1 ) { if(urlHasQuery.length != ruleUrl.length ) {
GSON.fromJsonObject<UrlOption>(ruleUrl.substring(pos + 1).trim{ it < '!'})?.let { option -> GSON.fromJsonObject<UrlOption>(ruleUrl.substring(urlHasQuery.length + 1).trim{ it < '!'})?.let { option ->
option.method?.let { option.method?.let {
if (it.equals("POST", true)) method = RequestMethod.POST if (it.equals("POST", true)) method = RequestMethod.POST
@ -191,7 +187,7 @@ class AnalyzeUrl(
when (method) { when (method) {
RequestMethod.GET -> { RequestMethod.GET -> {
if (!useWebView) { if (!useWebView) {
pos = url.indexOf('?') val pos = url.indexOf('?')
if(pos != -1) { if(pos != -1) {
analyzeFields(url.substring(pos + 1)) analyzeFields(url.substring(pos + 1))
url = url.substring(0,pos) url = url.substring(0,pos)

@ -111,11 +111,9 @@ object ChapterProvider {
) )
} }
} else if (book.getImageStyle() != Book.imgStyleText) { } else if (book.getImageStyle() != Book.imgStyleText) {
var contentX = content.replace(AppPattern.imgPattern.toRegex(), "\n\$0\n").split("\n") content.replace(AppPattern.imgPattern.toRegex(), "\n\$0\n").split("\n")
val start = contentX.first() == "\n" .forEach { text ->
val end = contentX.last() == "\n" if(text.isNotBlank()){
if(start || end )contentX = contentX.subList(if(start) 1 else 0,if(end) contentX.size-1 else contentX.size )
contentX.forEach { text ->
if (!text.startsWith("<img src=\"")) { //非图片 if (!text.startsWith("<img src=\"")) { //非图片
val isTitle = index == 0 val isTitle = index == 0
val textPaint = if (isTitle) titlePaint else contentPaint val textPaint = if (isTitle) titlePaint else contentPaint
@ -134,6 +132,7 @@ object ChapterProvider {
} }
} }
} }
}
textPages.last().height = durY + 20.dp textPages.last().height = durY + 20.dp
textPages.last().text = stringBuilder.toString() textPages.last().text = stringBuilder.toString()
textPages.forEachIndexed { index, item -> textPages.forEachIndexed { index, item ->

Loading…
Cancel
Save