A Chrome extension that displays country flag emojis next to Twitter/X usernames based on the account's location information.
- Automatically detects usernames on Twitter/X pages
- Queries Twitter's GraphQL API to get account location information
- Displays the corresponding country flag emoji next to usernames
- Works with dynamically loaded content (infinite scroll)
- Caches location data to minimize API calls
- Clone or download this repository
- Open Chrome and navigate to
chrome://extensions/ - Enable "Developer mode" (toggle in the top right)
- Click "Load unpacked"
- Select the directory containing this extension
- The extension will now be active on Twitter/X pages
- The extension runs a content script on all Twitter/X pages
- It identifies username elements in tweets and user profiles
- For each username, it queries Twitter's GraphQL API endpoint (
AboutAccountQuery) to get the account's location - The location is mapped to a flag emoji using the country flags mapping
- The flag emoji is displayed next to the username
manifest.json- Chrome extension configurationcontent.js- Main content script that processes the page and injects page scripts for API callscountryFlags.js- Country name to flag emoji mappingREADME.md- This file
The extension uses a page script injection approach to make API requests. This allows it to:
- Access the same cookies and authentication as the logged-in user
- Make same-origin requests to Twitter's API without CORS issues
- Work seamlessly with Twitter's authentication system
The content script injects a script into the page context that listens for location fetch requests. When a username is detected, the content script sends a custom event to the page script, which makes the API request and returns the location data.
The extension uses Twitter's GraphQL API endpoint:
https://x.com/i/api/graphql/XRqGa7EeokUU5kppkh13EA/AboutAccountQuery
With variables:
{
"screenName": "username"
}The response contains account_based_in field in:
data.user_result_by_screen_name.result.about_profile.account_based_in
- Requires the user to be logged into Twitter/X
- Only works for accounts that have location information available
- Country names must match the mapping in
countryFlags.js(case-insensitive) - Rate limiting may apply if making too many requests
- The extension only queries public account information
- No data is stored or transmitted to third-party servers
- All API requests are made directly to Twitter/X servers
- Location data is cached locally in memory
If flags are not appearing:
- Make sure you're logged into Twitter/X
- Check the browser console for any error messages
- Verify that the account has location information available
- Try refreshing the page
MIT