Skip to content

Commit

Permalink
Update cookie Manage
Browse files Browse the repository at this point in the history
  • Loading branch information
3003h committed Nov 1, 2024
1 parent 55c4974 commit ae78c80
Show file tree
Hide file tree
Showing 24 changed files with 210 additions and 144 deletions.
4 changes: 3 additions & 1 deletion jsons/eh_home.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"currentLimit?": 0,
"totLimit?": 5000,
"resetCost?": 100
"resetCost?": 100,
"high-resolutionLimited?": true,
"unlockCost?": 20000
}
1 change: 1 addition & 0 deletions jsons/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"sk?": "",
"yay?": "",
"star?": "",
"iq?": "",
"avatarUrl?": "",
"favcat?": "$[]favcat",
"lastUptTime?": 162234
Expand Down
38 changes: 31 additions & 7 deletions lib/common/parser/home_parser.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:eros_fe/utils/logger.dart';
import 'package:html/dom.dart';
import 'package:html/parser.dart' show parse;

Expand All @@ -6,17 +7,40 @@ import '../../models/base/eh_models.dart';
EhHome parserEhHome(String response) {
final Document document = parse(response);

final homeboxEml =
document.querySelector('body > div.stuffbox > div.homebox');
logger.d('homeboxEml: ${homeboxEml?.text}');

final bool highResolutionLimited =
homeboxEml?.text.contains('high-resolution images can be limited') ??
false;

final limitTextElms = document
.querySelectorAll('body > div.stuffbox > div.homebox > p > strong');
// logger.d('${limitTextElms.length}');
logger.d('limitTextElms len: ${limitTextElms.length}');

logger.d('limitTextElms: ${limitTextElms.map((e) => e.text).toList()}');

if (limitTextElms.length < 3) {
final unlockCost =
int.tryParse(limitTextElms[0].text.replaceAll(',', '')) ?? 0;
logger.d('unlockCost: $unlockCost');
return EhHome(
highResolutionLimited: highResolutionLimited,
unlockCost: unlockCost,
);
}

final _currentLimit = int.tryParse(limitTextElms[0].text) ?? 0;
final _totLimit = int.tryParse(limitTextElms[1].text) ?? 5000;
final _resetCost = int.tryParse(limitTextElms[2].text) ?? 0;
final currentLimit =
int.tryParse(limitTextElms[0].text.replaceAll(',', '')) ?? 0;
final totLimit = int.tryParse(limitTextElms[1].text.replaceAll(',', '')) ?? 0;
final resetCost =
int.tryParse(limitTextElms[2].text.replaceAll(',', '')) ?? 0;

return EhHome(
resetCost: _resetCost,
currentLimit: _currentLimit,
totLimit: _totLimit,
resetCost: resetCost,
currentLimit: currentLimit,
totLimit: totLimit,
highResolutionLimited: highResolutionLimited,
);
}
12 changes: 6 additions & 6 deletions lib/component/setting_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -905,12 +905,12 @@ Future<void> showCustomHostEditer(BuildContext context, {int? index}) async {
Future<void> showUserCookie() async {
final List<String> _c = Global.profile.user.cookie.split(';');

final List<Cookie> _cookies =
final List<Cookie> cookies =
_c.map((e) => Cookie.fromSetCookieValue(e)).toList();

final String _cookieString =
_cookies.map((e) => '${e.name}=${e.value}').join('\n');
logger.d('$_cookieString ');
final String cookieString =
cookies.map((e) => '${e.name}=${e.value}').join('\n');
logger.d('$cookieString ');

return showCupertinoDialog<void>(
context: Get.context!,
Expand All @@ -930,7 +930,7 @@ Future<void> showUserCookie() async {
CupertinoFormSection.insetGrouped(
margin: const EdgeInsetsDirectional.fromSTEB(0, 0.0, 0, 5.0),
backgroundColor: Colors.transparent,
children: _cookies
children: cookies
.map((e) => CupertinoTextFormFieldRow(
prefix: Text(
e.name,
Expand Down Expand Up @@ -958,7 +958,7 @@ Future<void> showUserCookie() async {
CupertinoDialogAction(
child: Text(L10n.of(context).copy),
onPressed: () {
Clipboard.setData(ClipboardData(text: _cookieString));
Clipboard.setData(ClipboardData(text: cookieString));
Get.back();
showToast(L10n.of(context).copied_to_clipboard);
},
Expand Down
10 changes: 6 additions & 4 deletions lib/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,34 +140,36 @@ extension ExtGalleryProvider on GalleryProvider {

extension ExtUser on User {
String get cookie {
final _list = <Cookie>[
final cookieList = <Cookie>[
Cookie('ipb_member_id', memberId ?? ''),
Cookie('ipb_pass_hash', passHash ?? ''),
Cookie('igneous', igneous ?? ''),
Cookie('sk', sk ?? ''),
Cookie('hath_perks', hathPerks ?? ''),
Cookie('star', star ?? ''),
Cookie('yay', yay ?? ''),
Cookie('iq', iq ?? ''),
];

return _list
return cookieList
.whereNot((e) => e.value.isEmpty)
.map((e) => '${e.name}=${e.value}')
.join('; ');
}

List<Cookie> get cookies {
final _list = <Cookie>[
final cookieList = <Cookie>[
Cookie('ipb_member_id', memberId ?? ''),
Cookie('ipb_pass_hash', passHash ?? ''),
Cookie('igneous', igneous ?? ''),
Cookie('sk', sk ?? ''),
Cookie('hath_perks', hathPerks ?? ''),
Cookie('star', star ?? ''),
Cookie('yay', yay ?? ''),
Cookie('iq', iq ?? ''),
];

return _list.whereNot((e) => e.value.isEmpty).toList();
return cookieList.whereNot((e) => e.value.isEmpty).toList();
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Hide Thumbnails"),
"hide_top_bar_on_scroll":
MessageLookupByLibrary.simpleMessage("Hide top bar on scroll"),
"high_resolution_images_limited": MessageLookupByLibrary.simpleMessage(
"High Resolution Images Limited"),
"horizontal_thumbnails":
MessageLookupByLibrary.simpleMessage("Horizontal Thumbnails"),
"host": MessageLookupByLibrary.simpleMessage("Host"),
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_ja.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class MessageLookup extends MessageLookupByLibrary {
"hide_thumbnails": MessageLookupByLibrary.simpleMessage("サムネイル(非表示)"),
"hide_top_bar_on_scroll":
MessageLookupByLibrary.simpleMessage("スクロール時にトップバーを隠す"),
"high_resolution_images_limited": MessageLookupByLibrary.simpleMessage(
"High Resolution Images Limited"),
"horizontal_thumbnails":
MessageLookupByLibrary.simpleMessage("水平サムネイル"),
"host": MessageLookupByLibrary.simpleMessage("Host"),
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_ko_KR.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Hide Thumbnails"),
"hide_top_bar_on_scroll":
MessageLookupByLibrary.simpleMessage("Hide top bar on scroll"),
"high_resolution_images_limited": MessageLookupByLibrary.simpleMessage(
"High Resolution Images Limited"),
"horizontal_thumbnails":
MessageLookupByLibrary.simpleMessage("Horizontal Thumbnails"),
"host": MessageLookupByLibrary.simpleMessage("Host"),
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Hide Thumbnails"),
"hide_top_bar_on_scroll":
MessageLookupByLibrary.simpleMessage("Hide top bar on scroll"),
"high_resolution_images_limited": MessageLookupByLibrary.simpleMessage(
"High Resolution Images Limited"),
"horizontal_thumbnails":
MessageLookupByLibrary.simpleMessage("Horizontal Thumbnails"),
"host": MessageLookupByLibrary.simpleMessage("Узел"),
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class MessageLookup extends MessageLookupByLibrary {
"hide_thumbnails": MessageLookupByLibrary.simpleMessage("隐藏缩略图"),
"hide_top_bar_on_scroll":
MessageLookupByLibrary.simpleMessage("滚动时隐藏顶栏"),
"high_resolution_images_limited":
MessageLookupByLibrary.simpleMessage("高分辨率图片限制"),
"horizontal_thumbnails": MessageLookupByLibrary.simpleMessage("水平缩略图"),
"host": MessageLookupByLibrary.simpleMessage("地址"),
"hours": MessageLookupByLibrary.simpleMessage("小时"),
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_zh_TW.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Hide Thumbnails"),
"hide_top_bar_on_scroll":
MessageLookupByLibrary.simpleMessage("滾動時隱藏頂欄"),
"high_resolution_images_limited": MessageLookupByLibrary.simpleMessage(
"High Resolution Images Limited"),
"horizontal_thumbnails":
MessageLookupByLibrary.simpleMessage("Horizontal Thumbnails"),
"host": MessageLookupByLibrary.simpleMessage("地址"),
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,6 @@
"regex_format_error": "Regex format error",
"experimental_feature": "Experimental feature",
"page_view_type": "Page View Type",
"slide_out_page": "Slide Out Page"
"slide_out_page": "Slide Out Page",
"high_resolution_images_limited": "High Resolution Images Limited"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,6 @@
"regex_format_error": "Regexフォーマットエラー",
"experimental_feature": "Experimental feature",
"page_view_type": "Page View Type",
"slide_out_page": "Slide Out Page"
"slide_out_page": "Slide Out Page",
"high_resolution_images_limited": "High Resolution Images Limited"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_ko_KR.arb
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,6 @@
"regex_format_error": "Regex format error",
"experimental_feature": "Experimental feature",
"page_view_type": "Page View Type",
"slide_out_page": "Slide Out Page"
"slide_out_page": "Slide Out Page",
"high_resolution_images_limited": "High Resolution Images Limited"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,6 @@
"regex_format_error": "Regex format error",
"experimental_feature": "Experimental feature",
"page_view_type": "Page View Type",
"slide_out_page": "Slide Out Page"
"slide_out_page": "Slide Out Page",
"high_resolution_images_limited": "High Resolution Images Limited"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,6 @@
"regex_format_error": "正则表达式格式错误",
"experimental_feature": "实验性功能",
"page_view_type": "页面视图类型",
"slide_out_page": "拖动返回"
"slide_out_page": "拖动返回",
"high_resolution_images_limited": "高分辨率图片限制"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_zh_TW.arb
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,6 @@
"regex_format_error": "Regex format error",
"experimental_feature": "Experimental feature",
"page_view_type": "Page View Type",
"slide_out_page": "Slide Out Page"
"slide_out_page": "Slide Out Page",
"high_resolution_images_limited": "High Resolution Images Limited"
}
26 changes: 20 additions & 6 deletions lib/models/eh_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,59 @@ class EhHome {
this.currentLimit,
this.totLimit,
this.resetCost,
this.highResolutionLimited,
this.unlockCost,
});

final int? currentLimit;
final int? totLimit;
final int? resetCost;
final bool? highResolutionLimited;
final int? unlockCost;

factory EhHome.fromJson(Map<String,dynamic> json) => EhHome(
currentLimit: json['currentLimit'] != null ? int.tryParse('${json['currentLimit']}') ?? 0 : null,
totLimit: json['totLimit'] != null ? int.tryParse('${json['totLimit']}') ?? 0 : null,
resetCost: json['resetCost'] != null ? int.tryParse('${json['resetCost']}') ?? 0 : null
resetCost: json['resetCost'] != null ? int.tryParse('${json['resetCost']}') ?? 0 : null,
highResolutionLimited: json['high-resolutionLimited'] != null ? bool.tryParse('${json['high-resolutionLimited']}', caseSensitive: false) ?? false : null,
unlockCost: json['unlockCost'] != null ? int.tryParse('${json['unlockCost']}') ?? 0 : null
);

Map<String, dynamic> toJson() => {
'currentLimit': currentLimit,
'totLimit': totLimit,
'resetCost': resetCost
'resetCost': resetCost,
'high-resolutionLimited': highResolutionLimited,
'unlockCost': unlockCost
};

EhHome clone() => EhHome(
currentLimit: currentLimit,
totLimit: totLimit,
resetCost: resetCost
resetCost: resetCost,
highResolutionLimited: highResolutionLimited,
unlockCost: unlockCost
);


EhHome copyWith({
Optional<int?>? currentLimit,
Optional<int?>? totLimit,
Optional<int?>? resetCost
Optional<int?>? resetCost,
Optional<bool?>? highResolutionLimited,
Optional<int?>? unlockCost
}) => EhHome(
currentLimit: checkOptional(currentLimit, () => this.currentLimit),
totLimit: checkOptional(totLimit, () => this.totLimit),
resetCost: checkOptional(resetCost, () => this.resetCost),
highResolutionLimited: checkOptional(highResolutionLimited, () => this.highResolutionLimited),
unlockCost: checkOptional(unlockCost, () => this.unlockCost),
);

@override
bool operator ==(Object other) => identical(this, other)
|| other is EhHome && currentLimit == other.currentLimit && totLimit == other.totLimit && resetCost == other.resetCost;
|| other is EhHome && currentLimit == other.currentLimit && totLimit == other.totLimit && resetCost == other.resetCost && highResolutionLimited == other.highResolutionLimited && unlockCost == other.unlockCost;

@override
int get hashCode => currentLimit.hashCode ^ totLimit.hashCode ^ resetCost.hashCode;
int get hashCode => currentLimit.hashCode ^ totLimit.hashCode ^ resetCost.hashCode ^ highResolutionLimited.hashCode ^ unlockCost.hashCode;
}
Loading

0 comments on commit ae78c80

Please sign in to comment.