Skip to content

Instantly share code, notes, and snippets.

@SinghChinmay
Created April 24, 2024 15:05
Show Gist options
  • Select an option

  • Save SinghChinmay/e5530ef3d4b556d4e409b17bfa0ae34f to your computer and use it in GitHub Desktop.

Select an option

Save SinghChinmay/e5530ef3d4b556d4e409b17bfa0ae34f to your computer and use it in GitHub Desktop.
# GitHub User Stats Script
This script fetches and displays basic GitHub statistics for any user directly in the browser's console. It's a handy tool for quick insights into a user's GitHub profile, including follower count, total public repositories, and detailed repository statistics such as stars and forks.
## Features
- Fetches user details (Name, Bio, Location, etc.)
- Displays number of followers and following
- Lists all public repositories along with star and fork counts
## How to Use
1. **Open Your Browser**: This script works best on modern browsers like Chrome, Firefox, or Edge.
2. **Navigate to a Web Page**: It's recommended to use a neutral page, such as `about:blank`, to avoid cross-origin issues.
3. **Open Developer Tools**: Press `F12` or right-click and select "Inspect" to open the developer tools. Navigate to the "Console" tab.
4. **Paste and Run the Script**: Copy the JavaScript code provided below into the console and press `Enter`.
5. **Enter a GitHub Username**: When prompted, input the GitHub username you want to inquire about.
6. **View the Stats**: The script will display the user's stats in the console.
### JavaScript Code
```javascript
(function() {
const username = prompt("Enter the GitHub username:");
if (!username) {
console.log("No username provided!");
return;
}
console.log(`Fetching GitHub stats for user: ${username}`);
fetch(`https://api.github.com/users/${username}`)
.then(response => response.json())
.then(user => {
if (user.message) {
console.log("Error: " + user.message);
} else {
console.log("User Info:");
console.log("Name: " + (user.name || "N/A"));
console.log("Bio: " + (user.bio || "N/A"));
console.log("Location: " + (user.location || "N/A"));
console.log("Followers: " + user.followers);
console.log("Following: " + user.following);
console.log("Public Repositories: " + user.public_repos);
return fetch(user.repos_url);
}
})
.then(response => response ? response.json() : [])
.then(repos => {
if (repos.length) {
console.log("Repositories:");
repos.forEach(repo => {
console.log(`- ${repo.name}: Stars (${repo.stargazers_count}), Forks (${repo.forks_count})`);
});
}
})
.catch(error => console.log("Failed to fetch data: " + error));
})();
```
## Requirements
- Any modern web browser (Chrome, Firefox, Edge, etc.)
- Internet connection
## Limitations
- The GitHub API has a rate limit for unauthenticated requests (60 requests per hour). Exceeding this limit will temporarily block your IP from making further requests.
- Due to browser security policies, cross-origin requests on some websites might be blocked.
## Disclaimer
This script is for informational purposes only. Please respect privacy and use it responsibly. Also, consider GitHub's API usage policies and rate limits before using the script extensively.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment