Skip to content

Commit

Permalink
fix novel parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed May 21, 2024
1 parent a6019ef commit 567a734
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
6 changes: 5 additions & 1 deletion lib/page/novel/new/novel_new_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NovelNewPage extends StatefulWidget {
}

class _NovelNewPageState extends State<NovelNewPage>
with TickerProviderStateMixin {
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
late TabController _tabController;

@override
Expand All @@ -47,6 +47,7 @@ class _NovelNewPageState extends State<NovelNewPage>

@override
Widget build(BuildContext context) {
super.build(context);
return Container(
child: Column(
children: [
Expand Down Expand Up @@ -108,4 +109,7 @@ class _NovelNewPageState extends State<NovelNewPage>
),
);
}

@override
bool get wantKeepAlive => true;
}
7 changes: 6 additions & 1 deletion lib/page/novel/rank/novel_rank_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class NovelRankPage extends StatefulWidget {
_NovelRankPageState createState() => _NovelRankPageState();
}

class _NovelRankPageState extends State<NovelRankPage> {
class _NovelRankPageState extends State<NovelRankPage>
with AutomaticKeepAliveClientMixin {
final modeList = [
"day",
"day_male",
Expand Down Expand Up @@ -41,6 +42,7 @@ class _NovelRankPageState extends State<NovelRankPage> {

@override
Widget build(BuildContext context) {
super.build(context);
List<String> w = I18n.of(context).novel_mode_list.split(" ");
return DefaultTabController(
length: modeList.length,
Expand Down Expand Up @@ -86,4 +88,7 @@ class _NovelRankPageState extends State<NovelRankPage> {
),
);
}

@override
bool get wantKeepAlive => true;
}
7 changes: 6 additions & 1 deletion lib/page/novel/recom/novel_recom_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class NovelRecomPage extends StatefulWidget {
_NovelRecomPageState createState() => _NovelRecomPageState();
}

class _NovelRecomPageState extends State<NovelRecomPage> {
class _NovelRecomPageState extends State<NovelRecomPage>
with AutomaticKeepAliveClientMixin {
late NovelLightingStore _store;
late EasyRefreshController _easyRefreshController;

Expand Down Expand Up @@ -74,6 +75,7 @@ class _NovelRecomPageState extends State<NovelRecomPage> {

@override
Widget build(BuildContext context) {
super.build(context);
return EasyRefresh.builder(
header: PixezDefault.header(context),
onRefresh: () => _store.fetch(),
Expand Down Expand Up @@ -207,4 +209,7 @@ class _NovelRecomPageState extends State<NovelRecomPage> {
),
);
}

@override
bool get wantKeepAlive => true;
}
18 changes: 5 additions & 13 deletions lib/page/novel/viewer/novel_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,11 @@ abstract class _NovelStoreBase with Store {
var document = parse(html);
final scriptElement = document.querySelector('script')!;
String scriptContent = scriptElement.innerHtml;

final novelStart = 'novel: ';
final startIndex = scriptContent.indexOf(novelStart) + novelStart.length;
final stack = <int>[];
for (var i = startIndex; i < scriptContent.length; i++) {
if (scriptContent[i] == '{') {
stack.add(i);
} else if (scriptContent[i] == '}') {
stack.removeLast();
if (stack.isEmpty) {
return scriptContent.substring(startIndex, i + 1);
}
}
final novelRegex = RegExp(r'novel: ({.*?}),\n\s*isOwnWork');
final match = novelRegex.firstMatch(scriptContent);
if (match != null) {
final novelJsonString = match.group(1);
return novelJsonString;
}
return null;
}
Expand Down
12 changes: 8 additions & 4 deletions lib/page/novel/viewer/novel_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ class _NovelViewerPageState extends State<NovelViewerPage> {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(':(',
style: Theme.of(context).textTheme.headlineMedium),
Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Text(':(',
style: Theme.of(context).textTheme.headlineMedium),
),
),
),
TextButton(
onPressed: () {
Expand Down
6 changes: 3 additions & 3 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
audio_session: dea1f41890dbf1718f04a56f1d6150fd50039b72
device_info_plus: 5401765fde0b8d062a2f8eb65510fb17e77cf07f
device_info_plus: ce1b7762849d3ec103d0e0517299f2db7ad60720
dynamic_color: 2eaa27267de1ca20d879fbd6e01259773fb1670f
file_selector_macos: 468fb6b81fac7c0e88d71317f3eec34c3b008ff9
flutter_inappwebview_macos: 9600c9df9fdb346aaa8933812009f8d94304203d
Expand All @@ -120,10 +120,10 @@ SPEC CHECKSUMS:
just_audio: 9b67ca7b97c61cfc9784ea23cd8cc55eb226d489
macos_window_utils: 933f91f64805e2eb91a5bd057cf97cd097276663
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce
package_info_plus: fa739dd842b393193c5ca93c26798dff6e3d0e0c
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
share_plus: 76dd39142738f7a68dd57b05093b5e8193f220f7
share_plus: 36537c04ce0c3e3f5bd297ce4318b6d5ee5fd6cf
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695
sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec
url_launcher_macos: d2691c7dd33ed713bf3544850a623080ec693d95
Expand Down

0 comments on commit 567a734

Please sign in to comment.