mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
@@ -59,6 +59,12 @@ java.ajaxAll(urlList: Array<String>): Array<StrResponse?>
|
||||
java.log(msg)
|
||||
java.logType(var)
|
||||
```
|
||||
* 从网络(由java.cacheFile实现)、本地导入JavaScript脚本
|
||||
```
|
||||
{{java.importScript(url)}}
|
||||
{{java.importScript(relativePath)}}
|
||||
{{java.importScript(absolutePath)}}
|
||||
```
|
||||
* 缓存网络文件
|
||||
```
|
||||
获取
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
* 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。
|
||||
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
|
||||
|
||||
**2022/03/31**
|
||||
|
||||
* 添加java.importScript,详情见js帮助文档
|
||||
* 本地书籍信息匹配`(.*?)《([^《》]+)》(.*)`, `(^)(.+) 作者:(.+)$`, `(^)(.+) by (.+)$`
|
||||
|
||||
**2022/03/29**
|
||||
|
||||
* 更新cronet: 100.0.4896.58
|
||||
|
||||
@@ -10,6 +10,8 @@ import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.AppConst.dateFormat
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.data.entities.BaseSource
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.http.*
|
||||
import io.legado.app.model.Debug
|
||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||
@@ -127,6 +129,35 @@ interface JsExtensions {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 可从网络,本地文件(阅读私有缓存目录和书籍保存位置支持相对路径)导入JavaScript脚本
|
||||
*/
|
||||
fun importScript(path: String): String {
|
||||
val result = when {
|
||||
path.startsWith("http") -> cacheFile(path) ?: ""
|
||||
path.isContentScheme() -> DocumentUtils.readText(appCtx, Uri.parse(path))
|
||||
path.startsWith("/storage") -> FileUtils.readText(path)
|
||||
else -> {
|
||||
//相对路径
|
||||
val jsPath = if (path.startsWith("/")) path else "/" + path
|
||||
//先找书籍保存目录下有没有
|
||||
val publicStoragePath = AppConfig.defaultBookTreeUri
|
||||
val jsString = publicStoragePath?.let {
|
||||
if (it.isContentScheme()) {
|
||||
val fileUri = Uri.parse(it + URLEncoder.encode(jsPath, "UTF-8"))
|
||||
DocumentUtils.readText(appCtx, fileUri)
|
||||
} else {
|
||||
FileUtils.readText(it + jsPath)
|
||||
}
|
||||
}
|
||||
//私有目录
|
||||
if (jsString.isNullOrBlank()) readTxtFile(path) else jsString
|
||||
}
|
||||
}
|
||||
if (result.isBlank()) throw NoStackTraceException("${path} 内容获取失败或者为空")
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存以文本方式保存的文件 如.js .txt等
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user