Skip to content

Commit 1dc89ba

Browse files
authored
Merge pull request #873 from rgantzos/flag-on-profile
Update profile flags
2 parents c656acf + db5c446 commit 1dc89ba

File tree

4 files changed

+34
-226
lines changed

4 files changed

+34
-226
lines changed

features/features.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@
107107
{
108108
"version": 2,
109109
"id": "profile-flag",
110-
"versionAdded": "v3.5.0"
110+
"versionAdded": "v3.5.0",
111+
"versionUpdated": "v3.10.0"
111112
},
112113
{
113114
"version": 2,

features/profile-flag/data.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"type": ["Website"],
88
"tags": ["New"],
99
"dynamic": true,
10-
"scripts": [{ "file": "script.js", "runOn": "/users/*", "module": true }]
11-
}
10+
"styles": [{ "file": "style.css", "runOn": "/users/*" }],
11+
"scripts": [{ "file": "script.js", "runOn": "/users/*" }]
12+
}

features/profile-flag/script.js

Lines changed: 21 additions & 223 deletions
Original file line numberDiff line numberDiff line change
@@ -1,233 +1,31 @@
1-
export default async function ({ feature, console }) {
2-
window.feature = feature
1+
export default async function ({ feature }) {
32
const locationElement = await ScratchTools.waitForElement(
43
"p.profile-details > span.location"
54
);
65

76
const locationText = locationElement.textContent.trim();
87
const countryFlag = getCountryFlag(locationText);
98
if (!countryFlag) return;
10-
const flagElement = document.createElement("span");
11-
flagElement.textContent = countryFlag;
12-
flagElement.style.marginRight = "4px";
13-
feature.self.hideOnDisable(flagElement);
14-
locationElement.insertBefore(flagElement, locationElement.firstChild);
159

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

231-
return flags[locationText] || "";
19+
feature.self.hideOnDisable(locationHolder);
20+
21+
function getCountryFlag(locationText) {
22+
const GithubUrl = "https://raw.githubusercontent.com/STForScratch/data/main/flags/";
23+
const countryName = locationText.toLowerCase()
24+
.replaceAll(" ", "-")
25+
.replaceAll("(", "")
26+
.replaceAll(")", "")
27+
.replaceAll(",", "")
28+
.replaceAll(".", "") + ".svg";
29+
return GithubUrl + countryName;
23230
}
233-
}
31+
}

features/profile-flag/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.location img {
2+
width: 15px;
3+
height: auto;
4+
margin-top: -1rem;
5+
position: relative;
6+
bottom: -.25rem;
7+
margin-left: .4rem;
8+
}

0 commit comments

Comments
 (0)