Skip to content

Commit

Permalink
优化PROFILE命令, 现在可以输出愿望单数量和好友上限
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Apr 12, 2022
1 parent ca4cf7a commit e630a01
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 21 deletions.
4 changes: 2 additions & 2 deletions ASFEnhance/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reflection;

[assembly: System.CLSCompliant(false)]
[assembly: AssemblyVersion("1.5.15.257")]
[assembly: AssemblyFileVersion("1.5.15.257")]
[assembly: AssemblyVersion("1.5.16.260")]
[assembly: AssemblyFileVersion("1.5.16.260")]

[assembly: AssemblyCopyright("Copyright © 2022 Chr_")]
[assembly: AssemblyProduct("ASFEnhance")]
Expand Down
11 changes: 10 additions & 1 deletion ASFEnhance/Localization/Langs.Designer.cs

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

5 changes: 4 additions & 1 deletion ASFEnhance/Localization/Langs.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
<value>Badges: {0}</value>
</data>
<data name="ProfileFriends" xml:space="preserve">
<value>Friends: {0}</value>
<value>Friends: {0} / {1}</value>
</data>
<data name="ProfileGames" xml:space="preserve">
<value>Games: {0}</value>
Expand Down Expand Up @@ -342,4 +342,7 @@
<data name="GroupListTitle" xml:space="preserve">
<value>No | Group Name | Group ID</value>
</data>
<data name="Wishlist" xml:space="preserve">
<value>Wishlist: {0}</value>
</data>
</root>
5 changes: 4 additions & 1 deletion ASFEnhance/Localization/Langs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
<value>徽章: {0}</value>
</data>
<data name="ProfileFriends" xml:space="preserve">
<value>好友: {0}</value>
<value>好友: {0} / {1}</value>
</data>
<data name="ProfileGames" xml:space="preserve">
<value>游戏: {0}</value>
Expand Down Expand Up @@ -342,4 +342,7 @@
<data name="GroupListItem" xml:space="preserve">
<value>{0} | {1} | {2}</value>
</data>
<data name="Wishlist" xml:space="preserve">
<value>愿望单: {0}</value>
</data>
</root>
5 changes: 4 additions & 1 deletion ASFEnhance/Localization/Langs.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
<value>徽章: {0}</value>
</data>
<data name="ProfileFriends" xml:space="preserve">
<value>好友: {0}</value>
<value>好友: {0} / {1}</value>
</data>
<data name="ProfileGames" xml:space="preserve">
<value>游戏: {0}</value>
Expand Down Expand Up @@ -342,4 +342,7 @@
<data name="GroupListTitle" xml:space="preserve">
<value>No | 群组名称 | 群组ID</value>
</data>
<data name="Wishlist" xml:space="preserve">
<value>愿望单: {0}</value>
</data>
</root>
42 changes: 27 additions & 15 deletions ASFEnhance/Profile/HtmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Chrxw.ASFEnhance.Profile
{
internal static class HtmlParser
{

/// <summary>
/// 解析个人资料页
/// </summary>
Expand All @@ -24,43 +24,48 @@ internal static class HtmlParser
return null;
}

IElement? eleNickName = response.Content.SelectSingleNode("//div[@class='persona_name']/span[1]");
IDocument content = response.Content;

IElement? eleNickName = content.SelectSingleNode("//div[@class='persona_name']/span[1]");
string nickName = eleNickName?.TextContent ?? "";

IElement? eleLevel = response.Content.SelectSingleNode("//div[@class='profile_header_badgeinfo_badge_area']//span[@class='friendPlayerLevelNum']");
IElement? eleLevel = content.SelectSingleNode("//div[@class='profile_header_badgeinfo_badge_area']//span[@class='friendPlayerLevelNum']");
string strLevel = eleLevel?.TextContent ?? "0";

IElement? eleOnline = response.Content.SelectSingleNode("//div[@class='profile_in_game_name']");
IElement? eleOnline = content.SelectSingleNode("//div[@class='profile_in_game_name']");
bool online = eleOnline == null;

IElement? eleBadgesCount = response.Content.SelectSingleNode("//a[contains(@href,'/badges/')]/span[last()]");
IElement? eleBadgesCount = content.SelectSingleNode("//a[contains(@href,'/badges/')]/span[last()]");
string? strBadgesCount = eleBadgesCount?.TextContent.Replace(",", "");

IElement? eleGamesCount = response.Content.SelectSingleNode("//a[contains(@href,'/games/')]/span[last()]");
IElement? eleGamesCount = content.SelectSingleNode("//a[contains(@href,'/games/')]/span[last()]");
string? strGamesCount = eleGamesCount?.TextContent.Trim().Replace(",", "");

IElement? eleScreenshotsCount = response.Content.SelectSingleNode("//a[contains(@href,'/screenshots/')]/span[last()]");
IElement? eleWishlistCount = content.SelectSingleNode("//a[contains(@href,'/wishlist/')]/span[last()]");
string? strWishlistCount = eleWishlistCount?.TextContent.Trim().Replace(",", "");

IElement? eleScreenshotsCount = content.SelectSingleNode("//a[contains(@href,'/screenshots/')]/span[last()]");
string? strScreenshotsCount = eleScreenshotsCount?.TextContent.Replace(",", "");

IElement? eleVideosCount = response.Content.SelectSingleNode("//a[contains(@href,'/videos/')]/span[last()]");
IElement? eleVideosCount = content.SelectSingleNode("//a[contains(@href,'/videos/')]/span[last()]");
string? strVideosCount = eleVideosCount?.TextContent.Replace(",", "");

IElement? eleWorkshopCount = response.Content.SelectSingleNode("//a[contains(@href,'/myworkshopfiles/')]/span[last()]");
IElement? eleWorkshopCount = content.SelectSingleNode("//a[contains(@href,'/myworkshopfiles/')]/span[last()]");
string? strWorkshopCount = eleWorkshopCount?.TextContent.Replace(",", "");

IElement? eleRecommendedCount = response.Content.SelectSingleNode("//a[contains(@href,'/recommended/')]/span[last()]");
IElement? eleRecommendedCount = content.SelectSingleNode("//a[contains(@href,'/recommended/')]/span[last()]");
string? strRecommendedCount = eleRecommendedCount?.TextContent.Replace(",", "");

IElement? eleGuideCount = response.Content.SelectSingleNode("//a[contains(@href,'section=guides')]/span[last()]");
IElement? eleGuideCount = content.SelectSingleNode("//a[contains(@href,'section=guides')]/span[last()]");
string? strGuideCount = eleGuideCount?.TextContent.Replace(",", "");

IElement? eleImagesCount = response.Content.SelectSingleNode("//a[contains(@href,'/images/')]/span[last()]");
IElement? eleImagesCount = content.SelectSingleNode("//a[contains(@href,'/images/')]/span[last()]");
string? strImagesCount = eleImagesCount?.TextContent.Replace(",", "");

IElement? eleGroupsCount = response.Content.SelectSingleNode("//a[contains(@href,'/groups/')]/span[last()]");
IElement? eleGroupsCount = content.SelectSingleNode("//a[contains(@href,'/groups/')]/span[last()]");
string? strGroupsCount = eleGroupsCount?.TextContent.Replace(",", "");

IElement? eleFriendsCount = response.Content.SelectSingleNode("//a[contains(@href,'/friends/')]/span[last()]");
IElement? eleFriendsCount = content.SelectSingleNode("//a[contains(@href,'/friends/')]/span[last()]");
string? strFriendsCount = eleFriendsCount?.TextContent.Replace(",", "");

StringBuilder result = new();
Expand All @@ -69,8 +74,10 @@ internal static class HtmlParser
result.AppendLine(string.Format(CurrentCulture, Langs.ProfileNickname, nickName));
result.AppendLine(string.Format(CurrentCulture, Langs.ProfileState, online ? Langs.Online : Langs.Offline));

uint maxFriend = 0;
if (uint.TryParse(strLevel, out uint level))
{
maxFriend = 5 * level + 250;
result.AppendLine(string.Format(CurrentCulture, Langs.ProfileLevel, level));
}

Expand All @@ -84,6 +91,11 @@ internal static class HtmlParser
result.AppendLine(string.Format(CurrentCulture, Langs.ProfileGames, games));
}

if (uint.TryParse(strWishlistCount, out uint wishlist))
{
result.AppendLine(string.Format(CurrentCulture, Langs.Wishlist, wishlist));
}

if (uint.TryParse(strScreenshotsCount, out uint screenshots))
{
result.AppendLine(string.Format(CurrentCulture, Langs.ProfileScreenshots, screenshots));
Expand Down Expand Up @@ -121,7 +133,7 @@ internal static class HtmlParser

if (uint.TryParse(strFriendsCount, out uint friends))
{
result.AppendLine(string.Format(CurrentCulture, Langs.ProfileFriends, friends));
result.AppendLine(string.Format(CurrentCulture, Langs.ProfileFriends, friends, maxFriend > 0 ? maxFriend : "-"));
}

return result.ToString();
Expand Down

0 comments on commit e630a01

Please sign in to comment.