Created
September 1, 2024 20:47
-
-
Save unitycoder/95e25faae79f6d05fb0d9ac3ede6f428 to your computer and use it in GitHub Desktop.
calculate top user submitted games count from itch.io games list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://itch.io/games/newest | |
| // Step 1: Select all elements with the class "game_cell has_cover" | |
| const gameCells = document.querySelectorAll('.game_cell.has_cover'); | |
| // Step 2: Create an empty object to store username counts and their display names | |
| const usernameData = {}; | |
| // Step 3: Loop through each "game_cell has_cover" element | |
| gameCells.forEach((cell) => { | |
| // Step 4: Find the link with the data-label attribute containing 'user:' | |
| const userLink = cell.querySelector('a[data-label*="user:"]'); | |
| if (userLink) { | |
| // Step 5: Extract the username part from the data-label attribute | |
| const dataLabel = userLink.getAttribute('data-label'); | |
| const username = dataLabel.split(':')[1]; | |
| // Step 6: Extract the displayed name from the link text content | |
| const displayName = userLink.textContent.trim(); | |
| // Step 7: Increment the count for this username in the usernameData object | |
| if (usernameData[username]) { | |
| usernameData[username].count++; | |
| } else { | |
| usernameData[username] = { | |
| displayName: displayName, | |
| count: 1 | |
| }; | |
| } | |
| } | |
| }); | |
| // Step 8: Convert the usernameData object into an array of [username, {displayName, count}] pairs | |
| const sortedUsernames = Object.entries(usernameData).sort((a, b) => b[1].count - a[1].count); | |
| // Step 9: Log the sorted list of usernames, their display names, and their counts | |
| console.log('Top list of usernames by occurrence:'); | |
| sortedUsernames.forEach(([username, data], index) => { | |
| console.log(`${index + 1}. Username: ${username}, Display Name: ${data.displayName}, Count: ${data.count} time(s)`); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment