diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 011689a1b..10b2e6acb 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,7 +6,7 @@ **2020/10/23** * 修复选择错误的bug * 修复长图最后一张不能滚动的bug -* js添加java.getCookie(sourceUrl)来获取登录后的cookie by [AndyBernie](https://github.com/AndyBernie) +* js添加java.getCookie(sourceUrl:String, key:String ?=null)来获取登录后的cookie by [AndyBernie](https://github.com/AndyBernie) * 修复简繁转换没有处理标题 **2020/10/21** diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index ff7357ad4..f42828476 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -123,8 +123,14 @@ interface JsExtensions { /** *js实现读取cookie */ - fun getCookie(tag: String): String { - return CookieStore.getCookie(tag) + fun getCookie(tag: String, key: String? = null): String { + val cookie = CookieStore.getCookie(tag) + val cookieMap = CookieStore.cookieToMap(cookie) + return if (key != null) { + cookieMap.get(key) ?: "" + } else { + cookie + } } /** diff --git a/app/src/main/java/io/legado/app/help/http/CookieStore.kt b/app/src/main/java/io/legado/app/help/http/CookieStore.kt index 2f2bfaaec..f97588a87 100644 --- a/app/src/main/java/io/legado/app/help/http/CookieStore.kt +++ b/app/src/main/java/io/legado/app/help/http/CookieStore.kt @@ -43,7 +43,7 @@ object CookieStore : CookiePersistor { App.db.cookieDao().delete(NetworkUtils.getSubDomain(url)) } - private fun cookieToMap(cookie: String): MutableMap { + fun cookieToMap(cookie: String): MutableMap { val cookieMap = mutableMapOf() if (cookie.isBlank()) { return cookieMap