mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: search trending
Closes #678 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -143,15 +143,54 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(6, 0, 6, 6),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'大家都在搜',
|
||||
strutStyle: StrutStyle(leading: 0, height: 1),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleMedium!
|
||||
.copyWith(fontWeight: FontWeight.bold),
|
||||
.copyWith(height: 1, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url':
|
||||
'https://www.bilibili.com/blackboard/activity-trending-topic.html?navhide=1&native.theme=1&night=${Get.isDarkMode ? 1 : 0}'
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 6, horizontal: 10),
|
||||
child: Text.rich(
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: '完整榜单',
|
||||
),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Icon(
|
||||
size: 16,
|
||||
Icons.keyboard_arrow_right,
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
SizedBox(
|
||||
height: 34,
|
||||
child: TextButton.icon(
|
||||
|
||||
@@ -177,16 +177,16 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
||||
URLRequest(url: WebUri.uri(Uri.tryParse(_url) ?? Uri())),
|
||||
onWebViewCreated: (InAppWebViewController controller) {
|
||||
_webViewController = controller;
|
||||
_webViewController?.addJavaScriptHandler(
|
||||
controller.addJavaScriptHandler(
|
||||
handlerName: 'finishButtonClicked',
|
||||
callback: (args) {
|
||||
Get.back();
|
||||
},
|
||||
);
|
||||
_webViewController?.addJavaScriptHandler(
|
||||
controller.addJavaScriptHandler(
|
||||
handlerName: 'infoBarClicked',
|
||||
callback: (args) async {
|
||||
WebUri? uri = await _webViewController?.getUrl();
|
||||
WebUri? uri = await controller.getUrl();
|
||||
if (uri != null) {
|
||||
String? oid =
|
||||
RegExp(r'oid=(\d+)').firstMatch(uri.toString())?.group(1);
|
||||
@@ -196,6 +196,20 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
||||
}
|
||||
},
|
||||
);
|
||||
controller.addJavaScriptHandler(
|
||||
handlerName: "onSearch",
|
||||
callback: (args) {
|
||||
dynamic title = args.firstOrNull;
|
||||
if (title != null) {
|
||||
Get.toNamed(
|
||||
'/searchResult',
|
||||
parameters: {
|
||||
'keyword': title,
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
onProgressChanged: (controller, progress) {
|
||||
this.progress.value = progress / 100;
|
||||
@@ -204,27 +218,41 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
||||
this.title.value = title ?? '';
|
||||
},
|
||||
onCloseWindow: (controller) => Get.back(),
|
||||
onLoadStop: (controller, url) {
|
||||
if (url
|
||||
.toString()
|
||||
.startsWith('https://www.bilibili.com/h5/note-app')) {
|
||||
_webViewController?.evaluateJavascript(source: """
|
||||
onLoadStop: (controller, uri) {
|
||||
final url = uri.toString();
|
||||
if (url.startsWith('https://www.bilibili.com/h5/note-app')) {
|
||||
controller.evaluateJavascript(source: """
|
||||
document.querySelector('.finish-btn').addEventListener('click', function() {
|
||||
window.flutter_inappwebview.callHandler('finishButtonClicked');
|
||||
});
|
||||
""");
|
||||
_webViewController?.evaluateJavascript(source: """
|
||||
controller.evaluateJavascript(source: """
|
||||
document.querySelector('.info-bar').addEventListener('click', function() {
|
||||
window.flutter_inappwebview.callHandler('infoBarClicked');
|
||||
});
|
||||
""");
|
||||
} else if (url.toString().startsWith('https://live.bilibili.com')) {
|
||||
_webViewController?.evaluateJavascript(
|
||||
} else if (url.startsWith('https://live.bilibili.com')) {
|
||||
controller.evaluateJavascript(
|
||||
source: '''
|
||||
document.styleSheets[0].insertRule('div.open-app-btn.bili-btn-warp {display:none;}', 0);
|
||||
document.styleSheets[0].insertRule('#app__display-area > div.control-panel {display:none;}', 0);
|
||||
''',
|
||||
);
|
||||
} else if (url.startsWith(
|
||||
'https://www.bilibili.com/blackboard/activity-trending-topic.html')) {
|
||||
controller.evaluateJavascript(source: '''
|
||||
document.addEventListener("click", function(e) {
|
||||
const parentElement = e.target.parentElement;
|
||||
if (parentElement) {
|
||||
const trendingTitleElement = parentElement.querySelector(".trending-title");
|
||||
if (trendingTitleElement) {
|
||||
const rankElement = trendingTitleElement.querySelector(".rank-index");
|
||||
const title = rankElement ? trendingTitleElement.innerText.replace(rankElement.innerText, "").trim() : trendingTitleElement.innerText;
|
||||
window.flutter_inappwebview.callHandler("onSearch", title);
|
||||
}
|
||||
}
|
||||
});
|
||||
''');
|
||||
}
|
||||
// _webViewController?.evaluateJavascript(
|
||||
// source: '''
|
||||
@@ -235,6 +263,11 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
||||
},
|
||||
onDownloadStartRequest: Platform.isAndroid
|
||||
? (controller, request) {
|
||||
if (_url.startsWith(
|
||||
'https://www.bilibili.com/blackboard/activity-trending-topic.html')) {
|
||||
progress.value = 1;
|
||||
return;
|
||||
}
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
@@ -286,6 +319,7 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
||||
String url = request.url.toString();
|
||||
if (url.startsWith(
|
||||
'https://passport.bilibili.com/x/passport-login/web')) {
|
||||
progress.value = 1;
|
||||
return WebResourceResponse();
|
||||
}
|
||||
return null;
|
||||
@@ -306,6 +340,9 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
} else if (RegExp(r'^(?!(https?://))\S+://', caseSensitive: false)
|
||||
.hasMatch(url)) {
|
||||
if (url.startsWith('bilibili://browser')) {
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
}
|
||||
if (context.mounted) {
|
||||
SnackBar snackBar = SnackBar(
|
||||
content: const Text('当前网页将要打开外部链接,是否打开'),
|
||||
|
||||
Reference in New Issue
Block a user