diff --git a/app/src/main/assets/help/jsHelp.md b/app/src/main/assets/help/jsHelp.md index 67f11dede..61531c215 100644 --- a/app/src/main/assets/help/jsHelp.md +++ b/app/src/main/assets/help/jsHelp.md @@ -107,12 +107,12 @@ java.getVerificationCode(imageUrl) java.longToast(msg: Any?) java.toast(msg: Any?) ``` -* 从网络(由java.cacheFile实现)、本地导入JavaScript脚本 +* 从网络(由java.cacheFile实现)、本地读取JavaScript文件,导入上下文请手动`eval(String(...))` ``` -{{java.importScript(url)}} +java.importScript(url) //相对路径支持android/data/{package}/cache -{{java.importScript(relativePath)}} -{{java.importScript(absolutePath)}} +java.importScript(relativePath) +java.importScript(absolutePath) ``` * 缓存网络文件 ``` @@ -293,7 +293,7 @@ cookie.getCookie(url) 获取cookie某一键值 cookie.getKey(url,key) 删除cookie -cookie.removeCookie(key) +cookie.removeCookie(url) ``` ## cache对象的部分可用函数 diff --git a/app/src/main/assets/help/ruleHelp.md b/app/src/main/assets/help/ruleHelp.md index 2d45f4180..15a13ed95 100644 --- a/app/src/main/assets/help/ruleHelp.md +++ b/app/src/main/assets/help/ruleHelp.md @@ -37,6 +37,11 @@ name: "注册", type: "button", action: "http://www.yooike.com/xiaoshuo/#/register?title=%E6%B3%A8%E5%86%8C" + }, + { + name: "获取验证码", + type: "button", + action: "java.ajax(...)" } ] 成功登录后在js中获取读取登录信息 diff --git a/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt b/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt index 4a956a4dd..7ba9f279d 100644 --- a/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt +++ b/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt @@ -67,6 +67,15 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) { it.root.onClick { if (rowUi.action.isAbsUrl()) { context?.openUrl(rowUi.action!!) + } else { + // JavaScript + rowUi.action?.let { + kotlin.runCatching { + source.evalJS(it) + }.onFailure { + AppLog.put("LoginUI Button ${rowUi.name} JavaScript error", it) + } + } } } } @@ -133,4 +142,4 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) { activity?.finish() } -} \ No newline at end of file +}