Skip to content

Commit 18313c2

Browse files
khaaleoowangrunlin
andauthored
feat: Enhance achievement parsing with image URL extraction (#1)
* feat: Enhance achievement parsing with image URL extraction Update regex pattern to capture achievement image URLs alongside type and tier information, expanding the achievement data model to include image source details * perf: Apply suggestions from code review --------- Co-authored-by: Leo <64216877+wangrunlin@users.noreply.github.com>
1 parent 14b3e9f commit 18313c2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,19 @@ export default {
8282
return createJsonResponse({ total: 0, achievements: [] });
8383
}
8484

85-
const achievements: { type: string; tier?: number }[] = [];
85+
const achievements: { type: string; tier?: number; image?: string }[] = [];
8686
const pattern = new RegExp(
87-
`<a[^>]*href="/${username}\\?achievement=([^&]+)[^>]*>.*?(?:class="Label[^>]*achievement-tier-label[^>]*>x(\\d+))?(?:</span>)?</a>`,
87+
`<a[^>]*href="/${username}\\?achievement=([^&]+)[^>]*>\\s*<img\\s+src="([^"]+)"[^>]*>.*?(?:class="Label[^>]*achievement-tier-label[^>]*>x(\\d+))?(?:</span>)?</a>`,
8888
'gs'
8989
);
9090

9191
let match;
9292
while ((match = pattern.exec(achievementsSection[0])) !== null) {
93-
const [, type, tier] = match;
93+
const [, type, image, tier] = match;
9494
achievements.push({
9595
type: type.trim(),
9696
tier: tier ? parseInt(tier) : 1,
97+
image
9798
});
9899
}
99100

0 commit comments

Comments
 (0)