From d301b8af09817be39150cc879bbaa3aab4530842 Mon Sep 17 00:00:00 2001 From: Xwite <82232510+Xwite@users.noreply.github.com> Date: Sat, 12 Nov 2022 04:49:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95ui=E6=8C=89=E9=92=AE=E6=94=AF?= =?UTF-8?q?=E6=8C=81JavaScript=20(#2558)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * LoginUI button supports running JavaScript * Update jsHelp.md * Update ruleHelp.md --- app/src/main/assets/help/jsHelp.md | 10 +++++----- app/src/main/assets/help/ruleHelp.md | 5 +++++ .../java/io/legado/app/ui/login/SourceLoginDialog.kt | 11 ++++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) 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 +}