登录ui按钮支持JavaScript (#2558)

* LoginUI button supports running JavaScript

* Update jsHelp.md

* Update ruleHelp.md
pull/2565/head
Xwite 2 years ago committed by GitHub
parent 1dac8be320
commit d301b8af09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      app/src/main/assets/help/jsHelp.md
  2. 5
      app/src/main/assets/help/ruleHelp.md
  3. 9
      app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt

@ -107,12 +107,12 @@ java.getVerificationCode(imageUrl)
java.longToast(msg: Any?) java.longToast(msg: Any?)
java.toast(msg: Any?) java.toast(msg: Any?)
``` ```
* 从网络(由java.cacheFile实现)、本地导入JavaScript脚本 * 从网络(由java.cacheFile实现)、本地读取JavaScript文件,导入上下文请手动`eval(String(...))`
``` ```
{{java.importScript(url)}} java.importScript(url)
//相对路径支持android/data/{package}/cache //相对路径支持android/data/{package}/cache
{{java.importScript(relativePath)}} java.importScript(relativePath)
{{java.importScript(absolutePath)}} java.importScript(absolutePath)
``` ```
* 缓存网络文件 * 缓存网络文件
``` ```
@ -293,7 +293,7 @@ cookie.getCookie(url)
获取cookie某一键值 获取cookie某一键值
cookie.getKey(url,key) cookie.getKey(url,key)
删除cookie 删除cookie
cookie.removeCookie(key) cookie.removeCookie(url)
``` ```
## cache对象的部分可用函数 ## cache对象的部分可用函数

@ -37,6 +37,11 @@
name: "注册", name: "注册",
type: "button", type: "button",
action: "http://www.yooike.com/xiaoshuo/#/register?title=%E6%B3%A8%E5%86%8C" action: "http://www.yooike.com/xiaoshuo/#/register?title=%E6%B3%A8%E5%86%8C"
},
{
name: "获取验证码",
type: "button",
action: "java.ajax(...)"
} }
] ]
成功登录后在js中获取读取登录信息 成功登录后在js中获取读取登录信息

@ -67,6 +67,15 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) {
it.root.onClick { it.root.onClick {
if (rowUi.action.isAbsUrl()) { if (rowUi.action.isAbsUrl()) {
context?.openUrl(rowUi.action!!) context?.openUrl(rowUi.action!!)
} else {
// JavaScript
rowUi.action?.let {
kotlin.runCatching {
source.evalJS(it)
}.onFailure {
AppLog.put("LoginUI Button ${rowUi.name} JavaScript error", it)
}
}
} }
} }
} }

Loading…
Cancel
Save