mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: jump url (#246)
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -104,13 +104,12 @@ InlineSpan? richNode(item, context) {
|
||||
return;
|
||||
}
|
||||
if (url.startsWith('//')) {
|
||||
url = url.replaceFirst('//', 'https://');
|
||||
PiliScheme.routePush(Uri.parse(url));
|
||||
PiliScheme.routePushFromUrl('https:$url');
|
||||
return;
|
||||
}
|
||||
Utils.handleWebview(url.startsWith('//')
|
||||
? "https://${url.split('//').last}"
|
||||
: url);
|
||||
Utils.handleWebview(
|
||||
url.startsWith('//') ? "https://$url" : url,
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
i.text ?? '',
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:PiliPlus/common/widgets/video_progress_indicator.dart';
|
||||
import 'package:PiliPlus/models/user/history.dart';
|
||||
import 'package:PiliPlus/pages/common/multi_select_controller.dart';
|
||||
import 'package:PiliPlus/pages/fav_search/controller.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -53,8 +52,15 @@ class HistoryItem extends StatelessWidget {
|
||||
// 'pageTitle': videoItem.title
|
||||
// },
|
||||
// );
|
||||
PiliScheme.routePush(Uri.parse(
|
||||
"https://www.bilibili.com/read/cv${videoItem.history.oid}"));
|
||||
Utils.toDupNamed(
|
||||
'/htmlRender',
|
||||
parameters: {
|
||||
'url': 'https://www.bilibili.com/read/cv${videoItem.history.oid}',
|
||||
'title': '',
|
||||
'id': 'cv${videoItem.history.oid}',
|
||||
'dynamicType': 'read'
|
||||
},
|
||||
);
|
||||
} else if (videoItem.history.business == 'live') {
|
||||
if (videoItem.liveStatus == 1) {
|
||||
// LiveItemModel liveItem = LiveItemModel.fromJson({
|
||||
|
||||
@@ -60,7 +60,7 @@ class _MemberArticleState extends State<MemberArticle>
|
||||
return ListTile(
|
||||
dense: true,
|
||||
onTap: () {
|
||||
PiliScheme.routePush(Uri.parse(item.uri ?? ''));
|
||||
PiliScheme.routePushFromUrl(item.uri ?? '');
|
||||
},
|
||||
leading: item.originImageUrls?.isNotEmpty == true
|
||||
? Container(
|
||||
|
||||
@@ -142,7 +142,7 @@ class _MemberFavoriteState extends State<MemberFavorite>
|
||||
});
|
||||
}
|
||||
} else if (item1.type == 21) {
|
||||
PiliScheme.routePush(Uri.parse(item1.link ?? ''));
|
||||
PiliScheme.routePushFromUrl(item1.link ?? '');
|
||||
} else if (item1.type == 11) {
|
||||
Get.toNamed(
|
||||
'/subDetail',
|
||||
|
||||
@@ -118,9 +118,9 @@ class _MemberHomeState extends State<MemberHome>
|
||||
child: ListTile(
|
||||
dense: true,
|
||||
onTap: () {
|
||||
PiliScheme.routePush(Uri.parse(
|
||||
loadingState.response.article.item.first.uri ??
|
||||
''));
|
||||
PiliScheme.routePushFromUrl(
|
||||
loadingState.response.article.item.first.uri ?? '',
|
||||
);
|
||||
},
|
||||
leading: loadingState.response.article.item.first
|
||||
.originImageUrls?.isNotEmpty ==
|
||||
|
||||
@@ -73,7 +73,7 @@ class _AtMePageState extends State<AtMePage> {
|
||||
String? nativeUri =
|
||||
_atMeController.msgFeedAtMeList[i].item?.nativeUri;
|
||||
if (nativeUri != null) {
|
||||
PiliScheme.routePush(Uri.parse(nativeUri));
|
||||
PiliScheme.routePushFromUrl(nativeUri);
|
||||
}
|
||||
// SmartDialog.showToast("跳转至:$nativeUri(暂未实现)");
|
||||
},
|
||||
|
||||
@@ -122,7 +122,7 @@ class LikeMeList extends StatelessWidget {
|
||||
onTap: () {
|
||||
String? nativeUri = msgFeedLikeMeList[i].item?.nativeUri;
|
||||
if (nativeUri != null) {
|
||||
PiliScheme.routePush(Uri.parse(nativeUri));
|
||||
PiliScheme.routePushFromUrl(nativeUri);
|
||||
}
|
||||
// SmartDialog.showToast("跳转至:$nativeUri(暂未实现)");
|
||||
},
|
||||
|
||||
@@ -72,7 +72,7 @@ class _ReplyMePageState extends State<ReplyMePage> {
|
||||
String? nativeUri = _replyMeController
|
||||
.msgFeedReplyMeList[i].item?.nativeUri;
|
||||
if (nativeUri != null) {
|
||||
PiliScheme.routePush(Uri.parse(nativeUri));
|
||||
PiliScheme.routePushFromUrl(nativeUri);
|
||||
}
|
||||
// SmartDialog.showToast("跳转至:$nativeUri(暂未实现)");
|
||||
},
|
||||
|
||||
@@ -184,8 +184,7 @@ class _SysMsgPageState extends State<SysMsgPage> {
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
try {
|
||||
Uri uri = Uri.parse(match[2]!.replaceAll('"', ''));
|
||||
PiliScheme.routePush(uri);
|
||||
PiliScheme.routePushFromUrl(match[2]!.replaceAll('"', ''));
|
||||
} catch (err) {
|
||||
SmartDialog.showToast(err.toString());
|
||||
}
|
||||
@@ -209,8 +208,7 @@ class _SysMsgPageState extends State<SysMsgPage> {
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
try {
|
||||
Uri uri = Uri.parse(match[3]!);
|
||||
PiliScheme.routePush(uri);
|
||||
PiliScheme.routePushFromUrl(match[3]!);
|
||||
} catch (err) {
|
||||
SmartDialog.showToast(err.toString());
|
||||
}
|
||||
@@ -231,8 +229,7 @@ class _SysMsgPageState extends State<SysMsgPage> {
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
try {
|
||||
Uri uri = Uri.parse(match[0]!);
|
||||
PiliScheme.routePush(uri);
|
||||
PiliScheme.routePushFromUrl(match[0]!);
|
||||
} catch (err) {
|
||||
SmartDialog.showToast(err.toString());
|
||||
Utils.copyText(match[0] ?? '');
|
||||
|
||||
@@ -67,18 +67,22 @@ class SearchPanelController extends CommonController {
|
||||
void jump2Video() {
|
||||
if (RegExp(r'^av\d+$', caseSensitive: false).hasMatch(keyword)) {
|
||||
hasJump2Video = true;
|
||||
PiliScheme.videoPush(int.parse(keyword.substring(2)), null, false);
|
||||
PiliScheme.videoPush(
|
||||
int.parse(keyword.substring(2)),
|
||||
null,
|
||||
showDialog: false,
|
||||
);
|
||||
} else if (RegExp(r'^bv[a-z\d]{10}$', caseSensitive: false)
|
||||
.hasMatch(keyword)) {
|
||||
hasJump2Video = true;
|
||||
PiliScheme.videoPush(null, keyword, false);
|
||||
PiliScheme.videoPush(null, keyword, showDialog: false);
|
||||
}
|
||||
}
|
||||
|
||||
void onPushDetail(resultList) async {
|
||||
int? aid = int.tryParse(keyword);
|
||||
if (aid != null && resultList.first.aid == aid) {
|
||||
PiliScheme.videoPush(aid, null, false);
|
||||
PiliScheme.videoPush(aid, null, showDialog: false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/url_utils.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import '../../../../../utils/app_scheme.dart';
|
||||
import 'zan.dart';
|
||||
import 'package:html/parser.dart' show parse;
|
||||
|
||||
@@ -863,56 +862,12 @@ class ReplyItem extends StatelessWidget {
|
||||
});
|
||||
return;
|
||||
}
|
||||
final String redirectUrl =
|
||||
(await UrlUtils.parseRedirectUrl(matchStr)) ??
|
||||
matchStr;
|
||||
// if (redirectUrl == matchStr) {
|
||||
// Clipboard.setData(ClipboardData(text: matchStr));
|
||||
// SmartDialog.showToast('地址可能有误');
|
||||
// return;
|
||||
// }
|
||||
Uri uri = Uri.parse(redirectUrl);
|
||||
PiliScheme.routePush(uri);
|
||||
// final String pathSegment = Uri.parse(redirectUrl).path;
|
||||
// final String lastPathSegment =
|
||||
// pathSegment.split('/').last;
|
||||
// if (lastPathSegment.startsWith('BV')) {
|
||||
// UrlUtils.matchUrlPush(
|
||||
// lastPathSegment,
|
||||
// title,
|
||||
// redirectUrl,
|
||||
// );
|
||||
// } else {
|
||||
// Get.toNamed(
|
||||
// '/webview',
|
||||
// parameters: {
|
||||
// 'url': redirectUrl,
|
||||
// 'type': 'url',
|
||||
// 'pageTitle': title
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
Utils.handleWebview(matchStr);
|
||||
}
|
||||
} else {
|
||||
if (appUrlSchema.startsWith('bilibili://search')) {
|
||||
Get.toNamed('/searchResult',
|
||||
parameters: {'keyword': title});
|
||||
} else if (matchStr.startsWith('https://b23.tv')) {
|
||||
final String redirectUrl =
|
||||
(await UrlUtils.parseRedirectUrl(matchStr)) ??
|
||||
matchStr;
|
||||
final String pathSegment =
|
||||
Uri.parse(redirectUrl).path;
|
||||
final String lastPathSegment =
|
||||
pathSegment.split('/').last;
|
||||
if (lastPathSegment.startsWith('BV')) {
|
||||
UrlUtils.matchUrlPush(
|
||||
lastPathSegment,
|
||||
redirectUrl,
|
||||
);
|
||||
} else {
|
||||
Utils.handleWebview(redirectUrl);
|
||||
}
|
||||
} else {
|
||||
Utils.handleWebview(matchStr);
|
||||
}
|
||||
@@ -949,25 +904,8 @@ class ReplyItem extends StatelessWidget {
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () async {
|
||||
if (matchStr.startsWith('https://b23.tv')) {
|
||||
final String redirectUrl =
|
||||
(await UrlUtils.parseRedirectUrl(matchStr)) ??
|
||||
matchStr;
|
||||
final String pathSegment = Uri.parse(redirectUrl).path;
|
||||
final String lastPathSegment =
|
||||
pathSegment.split('/').last;
|
||||
if (lastPathSegment.startsWith('BV')) {
|
||||
UrlUtils.matchUrlPush(
|
||||
lastPathSegment,
|
||||
redirectUrl,
|
||||
);
|
||||
} else {
|
||||
PiliScheme.routePush(Uri.parse(matchStr));
|
||||
}
|
||||
} else {
|
||||
PiliScheme.routePush(Uri.parse(matchStr));
|
||||
}
|
||||
..onTap = () {
|
||||
Utils.handleWebview(matchStr);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -20,7 +20,6 @@ import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/url_utils.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import '../../../../../utils/app_scheme.dart';
|
||||
import 'package:html/parser.dart' show parse;
|
||||
|
||||
class ReplyItemGrpc extends StatelessWidget {
|
||||
@@ -901,56 +900,12 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
});
|
||||
return;
|
||||
}
|
||||
final String redirectUrl =
|
||||
(await UrlUtils.parseRedirectUrl(matchStr)) ??
|
||||
matchStr;
|
||||
// if (redirectUrl == matchStr) {
|
||||
// Clipboard.setData(ClipboardData(text: matchStr));
|
||||
// SmartDialog.showToast('地址可能有误');
|
||||
// return;
|
||||
// }
|
||||
Uri uri = Uri.parse(redirectUrl);
|
||||
PiliScheme.routePush(uri);
|
||||
// final String pathSegment = Uri.parse(redirectUrl).path;
|
||||
// final String lastPathSegment =
|
||||
// pathSegment.split('/').last;
|
||||
// if (lastPathSegment.startsWith('BV')) {
|
||||
// UrlUtils.matchUrlPush(
|
||||
// lastPathSegment,
|
||||
// title,
|
||||
// redirectUrl,
|
||||
// );
|
||||
// } else {
|
||||
// Get.toNamed(
|
||||
// '/webview',
|
||||
// parameters: {
|
||||
// 'url': redirectUrl,
|
||||
// 'type': 'url',
|
||||
// 'pageTitle': title
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
Utils.handleWebview(matchStr);
|
||||
}
|
||||
} else {
|
||||
if (appUrlSchema.startsWith('bilibili://search')) {
|
||||
Get.toNamed('/searchResult',
|
||||
parameters: {'keyword': title});
|
||||
} else if (matchStr.startsWith('https://b23.tv')) {
|
||||
final String redirectUrl =
|
||||
(await UrlUtils.parseRedirectUrl(matchStr)) ??
|
||||
matchStr;
|
||||
final String pathSegment =
|
||||
Uri.parse(redirectUrl).path;
|
||||
final String lastPathSegment =
|
||||
pathSegment.split('/').last;
|
||||
if (lastPathSegment.startsWith('BV')) {
|
||||
UrlUtils.matchUrlPush(
|
||||
lastPathSegment,
|
||||
redirectUrl,
|
||||
);
|
||||
} else {
|
||||
Utils.handleWebview(redirectUrl);
|
||||
}
|
||||
} else {
|
||||
Utils.handleWebview(matchStr);
|
||||
}
|
||||
@@ -987,25 +942,8 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () async {
|
||||
if (matchStr.startsWith('https://b23.tv')) {
|
||||
final String redirectUrl =
|
||||
(await UrlUtils.parseRedirectUrl(matchStr)) ??
|
||||
matchStr;
|
||||
final String pathSegment = Uri.parse(redirectUrl).path;
|
||||
final String lastPathSegment =
|
||||
pathSegment.split('/').last;
|
||||
if (lastPathSegment.startsWith('BV')) {
|
||||
UrlUtils.matchUrlPush(
|
||||
lastPathSegment,
|
||||
redirectUrl,
|
||||
);
|
||||
} else {
|
||||
PiliScheme.routePush(Uri.parse(matchStr));
|
||||
}
|
||||
} else {
|
||||
PiliScheme.routePush(Uri.parse(matchStr));
|
||||
}
|
||||
..onTap = () {
|
||||
Utils.handleWebview(matchStr);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -5,8 +5,6 @@ import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:PiliPlus/utils/cache_manage.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
@@ -237,53 +235,20 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
||||
}
|
||||
: null,
|
||||
shouldOverrideUrlLoading: (controller, navigationAction) async {
|
||||
final String? str =
|
||||
navigationAction.request.url!.pathSegments.getOrNull(0);
|
||||
if (str != null) {
|
||||
final Map matchRes = IdUtils.matchAvorBv(input: str);
|
||||
if (matchRes.isNotEmpty) {
|
||||
Get.back();
|
||||
PiliScheme.videoPush(matchRes['AV'], matchRes['BV']);
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
}
|
||||
}
|
||||
|
||||
var url = navigationAction.request.url!.toString();
|
||||
|
||||
if (RegExp(
|
||||
r'^(https?://)?((www|m).)?(bilibili|b23).(com|tv)/video/BV[a-zA-Z\d]+')
|
||||
.hasMatch(url)) {
|
||||
try {
|
||||
String? bvid =
|
||||
RegExp(r'BV[a-zA-Z\d]+').firstMatch(url)?.group(0);
|
||||
if (bvid != null) {
|
||||
Get.back();
|
||||
PiliScheme.videoPush(null, bvid);
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
}
|
||||
} catch (_) {}
|
||||
} else if (RegExp(
|
||||
r'^(https?://)?((www|m).)?(bilibili|b23).(com|tv)/playlist')
|
||||
.hasMatch(url)) {
|
||||
try {
|
||||
String? bvid =
|
||||
RegExp(r'bvid=(BV[a-zA-Z\d]+)').firstMatch(url)?.group(1);
|
||||
if (bvid != null) {
|
||||
PiliScheme.videoPush(null, bvid);
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
}
|
||||
} catch (_) {}
|
||||
late String url = navigationAction.request.url.toString();
|
||||
bool hasMatch = await PiliScheme.routePush(
|
||||
navigationAction.request.url?.uriValue ?? Uri(),
|
||||
selfHandle: true,
|
||||
off: true,
|
||||
);
|
||||
// debugPrint('webview: [$url], [$hasMatch]');
|
||||
if (hasMatch) {
|
||||
_progressStream.add(1.0);
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
} else if (RegExp(r'^(?!(https?://))\S+://', caseSensitive: false)
|
||||
.hasMatch(url)) {
|
||||
if (url.startsWith('bilibili://video/')) {
|
||||
String? str =
|
||||
navigationAction.request.url!.pathSegments.getOrNull(0);
|
||||
Get.offAndToNamed(
|
||||
'/searchResult',
|
||||
parameters: {'keyword': str ?? ''},
|
||||
);
|
||||
} else {
|
||||
var snackBar = SnackBar(
|
||||
if (context.mounted) {
|
||||
SnackBar snackBar = SnackBar(
|
||||
content: const Text('当前网页将要打开外部链接,是否打开'),
|
||||
showCloseIcon: true,
|
||||
action: SnackBarAction(
|
||||
|
||||
Reference in New Issue
Block a user