From 0f63976a0020324889eb36bc549684544abcaae2 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Mon, 10 Feb 2025 12:01:19 +0800 Subject: [PATCH] mod: reply jump Signed-off-by: bggRGjQaUbCoE --- .../detail/reply/widgets/reply_item.dart | 23 +++++++++++++++++-- .../detail/reply/widgets/reply_item_grpc.dart | 22 ++++++++++++++++-- lib/utils/url_utils.dart | 3 +++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index c4031640..b0041abf 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -720,6 +720,9 @@ class ReplyItem extends StatelessWidget { // ?.call(replyItem.root == 0 ? replyItem : fReplyItem))))); } + late final bool enableWordRe = + GStorage.setting.get(SettingBoxKey.enableWordRe, defaultValue: false); + // 分割文本并处理每个部分 message.splitMapJoin( pattern, @@ -808,8 +811,6 @@ class ReplyItem extends StatelessWidget { ); } else { String appUrlSchema = ''; - final bool enableWordRe = GStorage.setting - .get(SettingBoxKey.enableWordRe, defaultValue: false) as bool; if (content.jumpUrl[matchStr] != null && !matchedStrs.contains(matchStr)) { appUrlSchema = content.jumpUrl[matchStr]['app_url_schema']; @@ -990,6 +991,11 @@ class ReplyItem extends StatelessWidget { if (unmatchedItems.isNotEmpty) { for (int i = 0; i < unmatchedItems.length; i++) { String patternStr = unmatchedItems[i]; + if (content.jumpUrl?[patternStr]?['extra']?['is_word_search'] == + true && + enableWordRe.not) { + continue; + } spanChildren.addAll( [ if (content.jumpUrl[patternStr]?['prefix_icon'] != null) ...[ @@ -1009,6 +1015,19 @@ class ReplyItem extends StatelessWidget { ), recognizer: TapGestureRecognizer() ..onTap = () { + String? cvid = RegExp(r'note-app/view\?cvid=(\d+)') + .firstMatch(patternStr) + ?.group(1); + if (cvid != null) { + Get.toNamed('/htmlRender', parameters: { + 'url': 'https://www.bilibili.com/read/cv$cvid', + 'title': '', + 'id': 'cv$cvid', + 'dynamicType': 'read' + }); + return; + } + Utils.handleWebview(patternStr); }, ) diff --git a/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart b/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart index 544d6462..ef53b0ce 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart @@ -761,6 +761,9 @@ class ReplyItemGrpc extends StatelessWidget { // ?.call(replyItem.root == 0 ? replyItem : fReplyItem))))); } + late final bool enableWordRe = + GStorage.setting.get(SettingBoxKey.enableWordRe, defaultValue: false); + // 分割文本并处理每个部分 message.splitMapJoin( pattern, @@ -849,8 +852,6 @@ class ReplyItemGrpc extends StatelessWidget { ); } else { String appUrlSchema = ''; - final bool enableWordRe = GStorage.setting - .get(SettingBoxKey.enableWordRe, defaultValue: false) as bool; if (content.url[matchStr] != null && !matchedStrs.contains(matchStr)) { appUrlSchema = content.url[matchStr]!.appUrlSchema; @@ -1030,6 +1031,10 @@ class ReplyItemGrpc extends StatelessWidget { if (unmatchedItems.isNotEmpty) { for (int i = 0; i < unmatchedItems.length; i++) { String patternStr = unmatchedItems[i]; + if (content.url[patternStr]?.extra.isWordSearch == true && + enableWordRe.not) { + continue; + } spanChildren.addAll( [ if (content.url[patternStr]?.hasPrefixIcon() == true) ...[ @@ -1048,6 +1053,19 @@ class ReplyItemGrpc extends StatelessWidget { ), recognizer: TapGestureRecognizer() ..onTap = () { + String? cvid = RegExp(r'note-app/view\?cvid=(\d+)') + .firstMatch(patternStr) + ?.group(1); + if (cvid != null) { + Get.toNamed('/htmlRender', parameters: { + 'url': 'https://www.bilibili.com/read/cv$cvid', + 'title': '', + 'id': 'cv$cvid', + 'dynamicType': 'read' + }); + return; + } + Utils.handleWebview(patternStr); }, ) diff --git a/lib/utils/url_utils.dart b/lib/utils/url_utils.dart index ac4b18bc..b1b6cf6c 100644 --- a/lib/utils/url_utils.dart +++ b/lib/utils/url_utils.dart @@ -24,6 +24,9 @@ class UrlUtils { if (response.statusCode == 302 || response.statusCode == 301) { String? redirectUrl = response.headers['location']?.first; if (redirectUrl != null) { + if (redirectUrl.startsWith('/')) { + return url; + } if (redirectUrl.endsWith('/')) { redirectUrl = redirectUrl.substring(0, redirectUrl.length - 1); }