Merge pull request #488 from gedoor/master

update
pull/489/head
Antecer 4 years ago committed by GitHub
commit bd28708c0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt
  2. 52
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  3. 4
      app/src/main/java/io/legado/app/model/analyzeRule/QueryTTF.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

@ -11,5 +11,6 @@ data class ContentRule(
var sourceRegex: String? = null, var sourceRegex: String? = null,
var replaceRegex: String? = null, var replaceRegex: String? = null,
var imageStyle: String? = null, //默认大小居中,FULL最大宽度 var imageStyle: String? = null, //默认大小居中,FULL最大宽度
var font: String? = null //必须返回ByteArray var font: String? = null, //网页内包含的字体必须返回ByteArray
var correctFont: String? = null, //正确的字体必须返回ByteArray
) : Parcelable ) : Parcelable

@ -10,6 +10,7 @@ import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jsoup.Connection import org.jsoup.Connection
import org.jsoup.Jsoup import org.jsoup.Jsoup
import java.io.File
import java.net.URLEncoder import java.net.URLEncoder
import java.nio.charset.Charset import java.nio.charset.Charset
import java.util.* import java.util.*
@ -19,7 +20,7 @@ import java.util.*
interface JsExtensions { interface JsExtensions {
/** /**
* js实现跨域访问,不能删 * 访问网络,返回String
*/ */
fun ajax(urlStr: String): String? { fun ajax(urlStr: String): String? {
return try { return try {
@ -32,6 +33,9 @@ interface JsExtensions {
} }
} }
/**
* 访问网络,返回Response<String>
*/
fun connect(urlStr: String): Any { fun connect(urlStr: String): Any {
return try { return try {
val analyzeUrl = AnalyzeUrl(urlStr) val analyzeUrl = AnalyzeUrl(urlStr)
@ -44,7 +48,7 @@ interface JsExtensions {
} }
/** /**
* js实现文件下载 * 实现文件下载,返回路径
*/ */
fun downloadFile(content: String, url: String): String { fun downloadFile(content: String, url: String): String {
val type = AnalyzeUrl(url).type ?: return "type为空,未下载" val type = AnalyzeUrl(url).type ?: return "type为空,未下载"
@ -111,6 +115,9 @@ interface JsExtensions {
.execute() .execute()
} }
/**
* 网络访问post
*/
fun post(urlStr: String, body: String, headers: Map<String, String>): Connection.Response { fun post(urlStr: String, body: String, headers: Map<String, String>): Connection.Response {
return Jsoup.connect(urlStr) return Jsoup.connect(urlStr)
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory) .sslSocketFactory(SSLHelper.unsafeSSLSocketFactory)
@ -146,6 +153,20 @@ interface JsExtensions {
return EncoderUtils.base64Decode(str, flags) return EncoderUtils.base64Decode(str, flags)
} }
fun base64DecodeToByteArray(str: String?): ByteArray? {
if (str.isNullOrBlank()) {
return null
}
return Base64.decode(str, Base64.DEFAULT)
}
fun base64DecodeToByteArray(str: String?, flags: Int): ByteArray? {
if (str.isNullOrBlank()) {
return null
}
return Base64.decode(str, flags)
}
fun base64Encode(str: String): String? { fun base64Encode(str: String): String? {
return EncoderUtils.base64Encode(str, Base64.NO_WRAP) return EncoderUtils.base64Encode(str, Base64.NO_WRAP)
} }
@ -162,11 +183,16 @@ interface JsExtensions {
return MD5Utils.md5Encode16(str) return MD5Utils.md5Encode16(str)
} }
/**
* 时间格式化
*/
fun timeFormat(time: Long): String { fun timeFormat(time: Long): String {
return dateFormat.format(Date(time)) return dateFormat.format(Date(time))
} }
//utf8编码转gbk编码 /**
* utf8编码转gbk编码
*/
fun utf8ToGbk(str: String): String { fun utf8ToGbk(str: String): String {
val utf8 = String(str.toByteArray(charset("UTF-8"))) val utf8 = String(str.toByteArray(charset("UTF-8")))
val unicode = String(utf8.toByteArray(), charset("UTF-8")) val unicode = String(utf8.toByteArray(), charset("UTF-8"))
@ -193,20 +219,16 @@ interface JsExtensions {
return str.htmlFormat() return str.htmlFormat()
} }
fun base64DecodeToByteArray(str: String?): ByteArray? { /**
if (str.isNullOrBlank()) { * 读取本地文件
return null */
} fun readFile(path: String): ByteArray? {
return Base64.decode(str, Base64.DEFAULT) return File(path).readBytes()
}
fun base64DecodeToByteArray(str: String?, flags: Int): ByteArray? {
if (str.isNullOrBlank()) {
return null
}
return Base64.decode(str, flags)
} }
/**
* 输出调试日志
*/
fun log(msg: String) { fun log(msg: String) {
Debug.log(msg) Debug.log(msg)
} }

@ -9,7 +9,7 @@ import kotlin.experimental.and
* @see <a href="https://docs.microsoft.com/en-us/typography/opentype/spec/">获取详情</a> * @see <a href="https://docs.microsoft.com/en-us/typography/opentype/spec/">获取详情</a>
* @see <a href="https://photopea.github.io/Typr.js/demo/index.html">基于Javascript的TTF解析器</a> * @see <a href="https://photopea.github.io/Typr.js/demo/index.html">基于Javascript的TTF解析器</a>
*/ */
class QueryTTF(var Font: Array<Byte>) : JsExtensions { class QueryTTF(var Font: ByteArray) : JsExtensions {
private class Header { private class Header {
var majorVersion: UShort = 0u var majorVersion: UShort = 0u
var minorVersion: UShort = 0u var minorVersion: UShort = 0u
@ -150,7 +150,7 @@ class QueryTTF(var Font: Array<Byte>) : JsExtensions {
lateinit var yCoordinates: ArrayList<Short> lateinit var yCoordinates: ArrayList<Short>
} }
private class ByteArrayReader(var Buffer: Array<Byte>, var Index: Int) { private class ByteArrayReader(var Buffer: ByteArray, var Index: Int) {
fun ReadUIntX(len: Long): ULong { fun ReadUIntX(len: Long): ULong {
var result: ULong = 0u; var result: ULong = 0u;
for (i in 0 until len) { for (i in 0 until len) {

@ -234,6 +234,7 @@ class BookSourceEditActivity :
add(EditEntity("replaceRegex", cr?.replaceRegex, R.string.rule_replace_regex)) add(EditEntity("replaceRegex", cr?.replaceRegex, R.string.rule_replace_regex))
add(EditEntity("imageStyle", cr?.imageStyle, R.string.rule_image_style)) add(EditEntity("imageStyle", cr?.imageStyle, R.string.rule_image_style))
add(EditEntity("font", cr?.font, R.string.rule_font)) add(EditEntity("font", cr?.font, R.string.rule_font))
add(EditEntity("correctFont", cr?.font, R.string.rule_correct_font))
} }
//发现 //发现
val er = source?.getExploreRule() val er = source?.getExploreRule()
@ -338,6 +339,7 @@ class BookSourceEditActivity :
"replaceRegex" -> contentRule.replaceRegex = it.value "replaceRegex" -> contentRule.replaceRegex = it.value
"imageStyle" -> contentRule.imageStyle = it.value "imageStyle" -> contentRule.imageStyle = it.value
"font" -> contentRule.font = it.value "font" -> contentRule.font = it.value
"correctFont" -> contentRule.font = it.value
} }
} }
source.ruleSearch = searchRule source.ruleSearch = searchRule

@ -412,7 +412,8 @@
<string name="rule_next_content">正文下一頁 URL 規則 (nextContentUrl)</string> <string name="rule_next_content">正文下一頁 URL 規則 (nextContentUrl)</string>
<string name="rule_web_js">webJs</string> <string name="rule_web_js">webJs</string>
<string name="rule_source_regex">資源正則 (sourceRegex)</string> <string name="rule_source_regex">資源正則 (sourceRegex)</string>
<string name="rule_font">字體(font)</string> <string name="rule_font">网页内嵌字體(font)</string>
<string name="rule_correct_font">正确字体(font)</string>
<string name="source_icon">圖標 (sourceIcon)</string> <string name="source_icon">圖標 (sourceIcon)</string>
<string name="r_articles">列表規則 (ruleArticles)</string> <string name="r_articles">列表規則 (ruleArticles)</string>

@ -413,7 +413,8 @@
<string name="rule_next_content">正文下一頁URL規則(nextContentUrl)</string> <string name="rule_next_content">正文下一頁URL規則(nextContentUrl)</string>
<string name="rule_web_js">webJs</string> <string name="rule_web_js">webJs</string>
<string name="rule_source_regex">資源正則(sourceRegex)</string> <string name="rule_source_regex">資源正則(sourceRegex)</string>
<string name="rule_font">字體(font)</string> <string name="rule_font">网页内嵌字體(font)</string>
<string name="rule_correct_font">正确字体(font)</string>
<string name="source_icon">圖示(sourceIcon)</string> <string name="source_icon">圖示(sourceIcon)</string>
<string name="r_articles">列表規則(ruleArticles)</string> <string name="r_articles">列表規則(ruleArticles)</string>

@ -418,7 +418,8 @@
<string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string> <string name="rule_next_content">正文下一页URL规则(nextContentUrl)</string>
<string name="rule_web_js">webJs</string> <string name="rule_web_js">webJs</string>
<string name="rule_source_regex">资源正则(sourceRegex)</string> <string name="rule_source_regex">资源正则(sourceRegex)</string>
<string name="rule_font">字体(font)</string> <string name="rule_font">网页内嵌字体(font)</string>
<string name="rule_correct_font">正确字体(font)</string>
<string name="source_icon">图标(sourceIcon)</string> <string name="source_icon">图标(sourceIcon)</string>
<string name="r_articles">列表规则(ruleArticles)</string> <string name="r_articles">列表规则(ruleArticles)</string>

@ -422,7 +422,8 @@
<string name="rule_source_regex">资源正则(sourceRegex)</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_image_style">图片样式(imageStyle)</string> <string name="rule_image_style">图片样式(imageStyle)</string>
<string name="rule_font">字体(font)</string> <string name="rule_font">网页内嵌字体(font)</string>
<string name="rule_correct_font">正确字体(font)</string>
<string name="source_icon">图标(sourceIcon)</string> <string name="source_icon">图标(sourceIcon)</string>
<string name="r_articles">列表规则(ruleArticles)</string> <string name="r_articles">列表规则(ruleArticles)</string>

Loading…
Cancel
Save