Skip to content

Commit 4c9041b

Browse files
authored
Flag on Profile
Adds a flag on your profile based on your respective location
1 parent 8a83221 commit 4c9041b

2 files changed

Lines changed: 242 additions & 0 deletions

File tree

features/flag-on-profile/data.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"title": "Flag on Profile",
3+
"description": "Adds flag emojis near selected locations on profile pages.",
4+
"credits": [
5+
{ "username": "MaterArc", "url": "https://scratch.mit.edu/users/MaterArc/" }
6+
],
7+
"type": ["Website"],
8+
"tags": ["New"],
9+
"dynamic": true,
10+
"styles": [{ "file": "flag.js", "runOn": "/users/*" }]
11+
}

features/flag-on-profile/flag.js

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
(function() {
2+
'use strict';
3+
4+
const locationElement = document.querySelector('.location');
5+
6+
if (locationElement) {
7+
const locationText = locationElement.textContent.trim();
8+
const countryFlag = getCountryFlag(locationText);
9+
const flagElement = document.createElement('span');
10+
flagElement.textContent = countryFlag;
11+
flagElement.style.marginRight = '4px';
12+
locationElement.insertBefore(flagElement, locationElement.firstChild);
13+
}
14+
function getCountryFlag(locationText) {
15+
const flags = {
16+
'Afghanistan': '🇦🇫',
17+
'Albania': '🇦🇱',
18+
'Algeria': '🇩🇿',
19+
'American Somoa': '🇦🇸',
20+
'Andorra': '🇦🇩',
21+
'Angola': '🇦🇴',
22+
'Antigua and Barbuda': '🇦🇬',
23+
'Argentina': '🇦🇷',
24+
'Armenia': '🇦🇲',
25+
'Australia': '🇦🇺',
26+
'Austria': '🇦🇹',
27+
'Azerbaijan': '🇦🇿',
28+
'Bahamas, The': '🇧🇸',
29+
'Bahrain': '🇧🇭',
30+
'Bangladesh': '🇧🇩',
31+
'Barbados': '🇧🇧',
32+
'Belarus': '🇧🇾',
33+
'Belgium': '🇧🇪',
34+
'Belize': '🇧🇿',
35+
'Benin': '🇧🇯',
36+
'Bhutan': '🇧🇹',
37+
'Bolivia': '🇧🇴',
38+
'Bosnia and Herzegovina': '🇧🇦',
39+
'Botswana': '🇧🇼',
40+
'Brazil': '🇧🇷',
41+
'Brunei': '🇧🇳',
42+
'Bulgaria': '🇧🇬',
43+
'Burkina Faso': '🇧🇫',
44+
'Burma': '🇲🇲',
45+
'Burundi': '🇧🇮',
46+
'Cabo Verde': '🇨🇻',
47+
'Cambodia': '🇰🇭',
48+
'Cameroon': '🇨🇲',
49+
'Canada': '🇨🇦',
50+
'Central African Republic': '🇨🇫',
51+
'Chad': '🇹🇩',
52+
'Chile': '🇨🇱',
53+
'China': '🇨🇳',
54+
'Colombia': '🇨🇴',
55+
'Comoros': '🇰🇲',
56+
'Congo Free State, The': '🇨🇬',
57+
'Costa Rica': '🇨🇷',
58+
'Cote d’Ivoire (Ivory Coast)': '🇨🇮',
59+
'Croatia': '🇭🇷',
60+
'Cuba': '🇨🇺',
61+
'Cyprus': '🇨🇾',
62+
'Czechia': '🇨🇿',
63+
'Czechoslovakia': '🇨🇿',
64+
'Democratic Republic of the Congo': '🇨🇩',
65+
'Denmark': '🇩🇰',
66+
'Djibouti': '🇩🇯',
67+
'Dominica': '🇩🇲',
68+
'Dominican Republic': '🇩🇴',
69+
'East Germany (German Democratic Republic)': '🇩🇪',
70+
'Ecuador': '🇪🇨',
71+
'Egypt': '🇪🇬',
72+
'El Salvador': '🇸🇻',
73+
'Equatorial Guinea': '🇬🇶',
74+
'Eritrea': '🇪🇷',
75+
'Estonia': '🇪🇪',
76+
'Eswatini': '🇸🇿',
77+
'Ethiopia': '🇪🇹',
78+
'Fiji': '🇫🇯',
79+
'Finland': '🇫🇮',
80+
'France': '🇫🇷',
81+
'Gabon': '🇬🇦',
82+
'Gambia, The': '🇬🇲',
83+
'Georgia': '🇬🇪',
84+
'Germany': '🇩🇪',
85+
'Ghana': '🇬🇭',
86+
'Greece': '🇬🇷',
87+
'Grenada': '🇬🇩',
88+
'Guatemala': '🇬🇹',
89+
'Guinea': '🇬🇳',
90+
'Guinea-Bissau': '🇬🇼',
91+
'Guyana': '🇬🇾',
92+
'Haiti': '🇭🇹',
93+
'Hanover': '🇩🇪',
94+
'Hanseatic Republics': '🇩🇪',
95+
'Hawaii': '🇺🇸',
96+
'Hesse': '🇩🇪',
97+
'Holy See': '🇻🇦',
98+
'Honduras': '🇭🇳',
99+
'Hungary': '🇭🇺',
100+
'Iceland': '🇮🇸',
101+
'India': '🇮🇳',
102+
'Indonesia': '🇮🇩',
103+
'Iran': '🇮🇷',
104+
'Iraq': '🇮🇶',
105+
'Ireland': '🇮🇪',
106+
'Israel': '🇮🇱',
107+
'Italy': '🇮🇹',
108+
'Jamaica': '🇯🇲',
109+
'Japan': '🇯🇵',
110+
'Jordan': '🇯🇴',
111+
'Kazakhstan': '🇰🇿',
112+
'Kenya': '🇰🇪',
113+
'Serbia': '🇷🇸',
114+
'Kiribati': '🇰🇮',
115+
'Korea': '🇰🇵',
116+
'Kosovo': '🇽🇰',
117+
'Kuwait': '🇰🇼',
118+
'Kyrgyzstan': '🇰🇬',
119+
'Laos': '🇱🇦',
120+
'Latvia': '🇱🇻',
121+
'Lebanon': '🇱🇧',
122+
'Lesotho': '🇱🇸',
123+
'Liberia': '🇱🇷',
124+
'Libya': '🇱🇾',
125+
'Liechtenstein': '🇱🇮',
126+
'Lithuania': '🇱🇹',
127+
'Luxembourg': '🇱🇺',
128+
'Madagascar': '🇲🇬',
129+
'Malawi': '🇲🇼',
130+
'Malaysia': '🇲🇾',
131+
'Maldives': '🇲🇻',
132+
'Mali': '🇲🇱',
133+
'Malta': '🇲🇹',
134+
'Marshall Islands': '🇲🇭',
135+
'Mauritania': '🇲🇷',
136+
'Mauritius': '🇲🇺',
137+
'Mexico': '🇲🇽',
138+
'Micronesia': '🇫🇲',
139+
'Moldova': '🇲🇩',
140+
'Monaco': '🇲🇨',
141+
'Mongolia': '🇲🇳',
142+
'Montenegro': '🇲🇪',
143+
'Morocco': '🇲🇦',
144+
'Mozambique': '🇲🇿',
145+
'Namibia': '🇳🇦',
146+
'Nauru': '🇳🇷',
147+
'Nepal': '🇳🇵',
148+
'Netherlands': '🇳🇱',
149+
'New Zealand': '🇳🇿',
150+
'Nicaragua': '🇳🇮',
151+
'Niger': '🇳🇪',
152+
'Nigeria': '🇳🇬',
153+
'North Macedonia': '🇲🇰',
154+
'Northern Mariana Islands': '🇲🇵',
155+
'Norway': '🇳🇴',
156+
'Oman': '🇴🇲',
157+
'Pakistan': '🇵🇰',
158+
'Palau': '🇵🇼',
159+
'Palestine, State of': '🇵🇸',
160+
'Panama': '🇵🇦',
161+
'Papua New Guinea': '🇵🇬',
162+
'Paraguay': '🇵🇾',
163+
'Peru': '🇵🇪',
164+
'Philippines': '🇵🇭',
165+
'Poland': '🇵🇱',
166+
'Portugal': '🇵🇹',
167+
'Qatar': '🇶🇦',
168+
'Romania': '🇷🇴',
169+
'Russia': '🇷🇺',
170+
'Rwanda': '🇷🇼',
171+
'Saint Kitts and Nevis': '🇰🇳',
172+
'Saint Lucia': '🇱🇨',
173+
'Saint Vincent and the Grenadines': '🇻🇨',
174+
'Samoa': '🇼🇸',
175+
'San Marino': '🇸🇲',
176+
'Sao Tome and Principe': '🇸🇹',
177+
'Saudi Arabia': '🇸🇦',
178+
'Senegal': '🇸🇳',
179+
'Serbia': '🇷🇸',
180+
'Seychelles': '🇸🇨',
181+
'Sierra Leone': '🇸🇱',
182+
'Singapore': '🇸🇬',
183+
'Slovakia': '🇸🇰',
184+
'Slovenia': '🇸🇮',
185+
'Solomon Islands': '🇸🇧',
186+
'Somalia': '🇸🇴',
187+
'South Africa': '🇿🇦',
188+
'South Sudan': '🇸🇸',
189+
'Spain': '🇪🇸',
190+
'Sri Lanka': '🇱🇰',
191+
'Sudan': '🇸🇩',
192+
'Suriname': '🇸🇷',
193+
'Sweden': '🇸🇪',
194+
'Switzerland': '🇨🇭',
195+
'Syria': '🇸🇾',
196+
'Taiwan': '🇹🇼',
197+
'Tajikistan': '🇹🇯',
198+
'Tanzania': '🇹🇿',
199+
'Thailand': '🇹🇭',
200+
'Timor-Leste': '🇹🇱',
201+
'Togo': '🇹🇬',
202+
'Tonga': '🇹🇴',
203+
'Trinidad and Tobago': '🇹🇹',
204+
'Tunisia': '🇹🇳',
205+
'Turkey': '🇹🇷',
206+
'Turkmenistan': '🇹🇲',
207+
'Tuvalu': '🇹🇻',
208+
'Uganda': '🇺🇬',
209+
'Ukraine': '🇺🇦',
210+
'United Arab Emirates': '🇦🇪',
211+
'United Kingdom': '🇬🇧',
212+
'United States': '🇺🇸',
213+
'Uruguay': '🇺🇾',
214+
'Uzbekistan': '🇺🇿',
215+
'Vanuatu': '🇻🇺',
216+
'Venezuela': '🇻🇪',
217+
'Vietnam': '🇻🇳',
218+
'Yemen': '🇾🇪',
219+
'Zambia': '🇿🇲',
220+
'Zimbabwe': '🇿🇼',
221+
'Antarctica': '🇦🇶',
222+
'French Southern Territories': '🇹🇫',
223+
'Bonaire, Sint Eustatius and Saba':' 🇧🇶',
224+
'Christmas Island': '🇨🇽',
225+
'Heard Island and McDonald Islands': '🇭🇲',
226+
'Location not given': '❓',
227+
};
228+
229+
return flags[locationText] || '';
230+
}
231+
})();

0 commit comments

Comments
 (0)