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(
|
||||||
padding: const EdgeInsets.fromLTRB(6, 0, 6, 6),
|
padding: const EdgeInsets.fromLTRB(6, 0, 6, 6),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'大家都在搜',
|
'大家都在搜',
|
||||||
|
strutStyle: StrutStyle(leading: 0, height: 1),
|
||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.titleMedium!
|
.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(
|
SizedBox(
|
||||||
height: 34,
|
height: 34,
|
||||||
child: TextButton.icon(
|
child: TextButton.icon(
|
||||||
|
|||||||
@@ -177,16 +177,16 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
URLRequest(url: WebUri.uri(Uri.tryParse(_url) ?? Uri())),
|
URLRequest(url: WebUri.uri(Uri.tryParse(_url) ?? Uri())),
|
||||||
onWebViewCreated: (InAppWebViewController controller) {
|
onWebViewCreated: (InAppWebViewController controller) {
|
||||||
_webViewController = controller;
|
_webViewController = controller;
|
||||||
_webViewController?.addJavaScriptHandler(
|
controller.addJavaScriptHandler(
|
||||||
handlerName: 'finishButtonClicked',
|
handlerName: 'finishButtonClicked',
|
||||||
callback: (args) {
|
callback: (args) {
|
||||||
Get.back();
|
Get.back();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
_webViewController?.addJavaScriptHandler(
|
controller.addJavaScriptHandler(
|
||||||
handlerName: 'infoBarClicked',
|
handlerName: 'infoBarClicked',
|
||||||
callback: (args) async {
|
callback: (args) async {
|
||||||
WebUri? uri = await _webViewController?.getUrl();
|
WebUri? uri = await controller.getUrl();
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
String? oid =
|
String? oid =
|
||||||
RegExp(r'oid=(\d+)').firstMatch(uri.toString())?.group(1);
|
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) {
|
onProgressChanged: (controller, progress) {
|
||||||
this.progress.value = progress / 100;
|
this.progress.value = progress / 100;
|
||||||
@@ -204,27 +218,41 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
this.title.value = title ?? '';
|
this.title.value = title ?? '';
|
||||||
},
|
},
|
||||||
onCloseWindow: (controller) => Get.back(),
|
onCloseWindow: (controller) => Get.back(),
|
||||||
onLoadStop: (controller, url) {
|
onLoadStop: (controller, uri) {
|
||||||
if (url
|
final url = uri.toString();
|
||||||
.toString()
|
if (url.startsWith('https://www.bilibili.com/h5/note-app')) {
|
||||||
.startsWith('https://www.bilibili.com/h5/note-app')) {
|
controller.evaluateJavascript(source: """
|
||||||
_webViewController?.evaluateJavascript(source: """
|
|
||||||
document.querySelector('.finish-btn').addEventListener('click', function() {
|
document.querySelector('.finish-btn').addEventListener('click', function() {
|
||||||
window.flutter_inappwebview.callHandler('finishButtonClicked');
|
window.flutter_inappwebview.callHandler('finishButtonClicked');
|
||||||
});
|
});
|
||||||
""");
|
""");
|
||||||
_webViewController?.evaluateJavascript(source: """
|
controller.evaluateJavascript(source: """
|
||||||
document.querySelector('.info-bar').addEventListener('click', function() {
|
document.querySelector('.info-bar').addEventListener('click', function() {
|
||||||
window.flutter_inappwebview.callHandler('infoBarClicked');
|
window.flutter_inappwebview.callHandler('infoBarClicked');
|
||||||
});
|
});
|
||||||
""");
|
""");
|
||||||
} else if (url.toString().startsWith('https://live.bilibili.com')) {
|
} else if (url.startsWith('https://live.bilibili.com')) {
|
||||||
_webViewController?.evaluateJavascript(
|
controller.evaluateJavascript(
|
||||||
source: '''
|
source: '''
|
||||||
document.styleSheets[0].insertRule('div.open-app-btn.bili-btn-warp {display:none;}', 0);
|
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);
|
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(
|
// _webViewController?.evaluateJavascript(
|
||||||
// source: '''
|
// source: '''
|
||||||
@@ -235,6 +263,11 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
},
|
},
|
||||||
onDownloadStartRequest: Platform.isAndroid
|
onDownloadStartRequest: Platform.isAndroid
|
||||||
? (controller, request) {
|
? (controller, request) {
|
||||||
|
if (_url.startsWith(
|
||||||
|
'https://www.bilibili.com/blackboard/activity-trending-topic.html')) {
|
||||||
|
progress.value = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
@@ -286,6 +319,7 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
String url = request.url.toString();
|
String url = request.url.toString();
|
||||||
if (url.startsWith(
|
if (url.startsWith(
|
||||||
'https://passport.bilibili.com/x/passport-login/web')) {
|
'https://passport.bilibili.com/x/passport-login/web')) {
|
||||||
|
progress.value = 1;
|
||||||
return WebResourceResponse();
|
return WebResourceResponse();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -306,6 +340,9 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
return NavigationActionPolicy.CANCEL;
|
return NavigationActionPolicy.CANCEL;
|
||||||
} else if (RegExp(r'^(?!(https?://))\S+://', caseSensitive: false)
|
} else if (RegExp(r'^(?!(https?://))\S+://', caseSensitive: false)
|
||||||
.hasMatch(url)) {
|
.hasMatch(url)) {
|
||||||
|
if (url.startsWith('bilibili://browser')) {
|
||||||
|
return NavigationActionPolicy.CANCEL;
|
||||||
|
}
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
SnackBar snackBar = SnackBar(
|
SnackBar snackBar = SnackBar(
|
||||||
content: const Text('当前网页将要打开外部链接,是否打开'),
|
content: const Text('当前网页将要打开外部链接,是否打开'),
|
||||||
|
|||||||
Reference in New Issue
Block a user