From 45259d0ef765bdc49aba31df7b665fbdecd1a05a Mon Sep 17 00:00:00 2001 From: WhiteScent Date: Tue, 21 Nov 2023 12:48:02 +0800 Subject: [PATCH] feat: remove "b23.tv" links for user profile page/live rooms (#1328) --- .../me/iacn/biliroaming/hook/ShareHook.kt | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/me/iacn/biliroaming/hook/ShareHook.kt b/app/src/main/java/me/iacn/biliroaming/hook/ShareHook.kt index 7cbf8d5dea..a97ad16434 100644 --- a/app/src/main/java/me/iacn/biliroaming/hook/ShareHook.kt +++ b/app/src/main/java/me/iacn/biliroaming/hook/ShareHook.kt @@ -27,9 +27,11 @@ class ShareHook(classLoader: ClassLoader) : BaseHook(classLoader) { private fun transformUrl(url: String, transformAv: Boolean): String { val target = Uri.parse(url) - val bv = if (transformAv) target.path?.split("/") - ?.firstOrNull { it.startsWith("BV") && it.length == 12 } - else null + val bv = if (transformAv) { + target.path?.split("/")?.firstOrNull { it.startsWith("BV") && it.length == 12 } + } else { + null + } val av = bv?.let { "av${bv2av(bv)}" } val newUrl = target.buildUpon() if (av != null) { @@ -42,9 +44,11 @@ class ShareHook(classLoader: ClassLoader) : BaseHook(classLoader) { }.filter { it.size == 2 }.mapNotNull { - if (it[0] == "p" || it[0] == "t") "${it[0]}=${it[1]}" - else if (it[0] == "start_progress") "start_progress=${it[1]}&t=${it[1].toLong() / 1000}" - else null + when { + it[0] == "p" || it[0] == "t" -> "${it[0]}=${it[1]}" + it[0] == "start_progress" -> "start_progress=${it[1]}&t=${it[1].toLong() / 1000}" + else -> null + } }.joinToString("&", postfix = "&unique_k=114514") newUrl.encodedQuery(query) } else { @@ -73,13 +77,9 @@ class ShareHook(classLoader: ClassLoader) : BaseHook(classLoader) { content?.let { contentUrlPattern.matchEntire(it)?.groups?.get(1)?.value }?.let { contentUrl -> - (param.thisObject.getObjectField("link")?.let { it as String } - ?: contentUrl).resolveB23URL().takeIf { it.contains("/video/") } - ?.let { realUrl -> - param.result = content.replace( - contentUrl, transformUrl(realUrl, miniProgramEnabled) - ) - } + val resolvedUrl = (param.thisObject.getObjectField("link")?.let { it as String } ?: contentUrl) + .resolveB23URL() + param.result = content.replace(contentUrl, transformUrl(resolvedUrl, miniProgramEnabled)) } } }