Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion features/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
{
"version": 2,
"id": "profile-flag",
"versionAdded": "v3.5.0"
"versionAdded": "v3.5.0",
"versionUpdated": "v3.10.0"
},
{
"version": 2,
Expand Down
5 changes: 3 additions & 2 deletions features/profile-flag/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"type": ["Website"],
"tags": ["New"],
"dynamic": true,
"scripts": [{ "file": "script.js", "runOn": "/users/*", "module": true }]
}
"styles": [{ "file": "style.css", "runOn": "/users/*" }],
"scripts": [{ "file": "script.js", "runOn": "/users/*" }]
}
244 changes: 21 additions & 223 deletions features/profile-flag/script.js
Original file line number Diff line number Diff line change
@@ -1,233 +1,31 @@
export default async function ({ feature, console }) {
window.feature = feature
export default async function ({ feature }) {
const locationElement = await ScratchTools.waitForElement(
"p.profile-details > span.location"
);

const locationText = locationElement.textContent.trim();
const countryFlag = getCountryFlag(locationText);
if (!countryFlag) return;
const flagElement = document.createElement("span");
flagElement.textContent = countryFlag;
flagElement.style.marginRight = "4px";
feature.self.hideOnDisable(flagElement);
locationElement.insertBefore(flagElement, locationElement.firstChild);

function getCountryFlag(locationText) {
const flags = {
Afghanistan: "🇦🇫",
Albania: "🇦🇱",
Algeria: "🇩🇿",
"American Somoa": "🇦🇸",
Andorra: "🇦🇩",
Angola: "🇦🇴",
"Antigua and Barbuda": "🇦🇬",
Argentina: "🇦🇷",
Armenia: "🇦🇲",
Australia: "🇦🇺",
Austria: "🇦🇹",
Azerbaijan: "🇦🇿",
"Bahamas, The": "🇧🇸",
Bahrain: "🇧🇭",
Bangladesh: "🇧🇩",
Barbados: "🇧🇧",
Belarus: "🇧🇾",
Belgium: "🇧🇪",
Belize: "🇧🇿",
Benin: "🇧🇯",
Bhutan: "🇧🇹",
Bolivia: "🇧🇴",
"Bosnia and Herzegovina": "🇧🇦",
Botswana: "🇧🇼",
Brazil: "🇧🇷",
Brunei: "🇧🇳",
Bulgaria: "🇧🇬",
"Burkina Faso": "🇧🇫",
Burma: "🇲🇲",
Burundi: "🇧🇮",
"Cabo Verde": "🇨🇻",
Cambodia: "🇰🇭",
Cameroon: "🇨🇲",
Canada: "🇨🇦",
"Central African Republic": "🇨🇫",
Chad: "🇹🇩",
Chile: "🇨🇱",
China: "🇨🇳",
Colombia: "🇨🇴",
Comoros: "🇰🇲",
"Congo Free State, The": "🇨🇬",
"Costa Rica": "🇨🇷",
"Cote d’Ivoire (Ivory Coast)": "🇨🇮",
Croatia: "🇭🇷",
Cuba: "🇨🇺",
Cyprus: "🇨🇾",
Czechia: "🇨🇿",
Czechoslovakia: "🇨🇿",
"Democratic Republic of the Congo": "🇨🇩",
Denmark: "🇩🇰",
Djibouti: "🇩🇯",
Dominica: "🇩🇲",
"Dominican Republic": "🇩🇴",
"East Germany (German Democratic Republic)": "🇩🇪",
Ecuador: "🇪🇨",
Egypt: "🇪🇬",
"El Salvador": "🇸🇻",
"Equatorial Guinea": "🇬🇶",
Eritrea: "🇪🇷",
Estonia: "🇪🇪",
Eswatini: "🇸🇿",
Ethiopia: "🇪🇹",
Fiji: "🇫🇯",
Finland: "🇫🇮",
France: "🇫🇷",
Gabon: "🇬🇦",
"Gambia, The": "🇬🇲",
Georgia: "🇬🇪",
Germany: "🇩🇪",
Ghana: "🇬🇭",
Greece: "🇬🇷",
Grenada: "🇬🇩",
Guatemala: "🇬🇹",
Guinea: "🇬🇳",
"Guinea-Bissau": "🇬🇼",
Guyana: "🇬🇾",
Haiti: "🇭🇹",
Hanover: "🇩🇪",
"Hanseatic Republics": "🇩🇪",
Hawaii: "🇺🇸",
Hesse: "🇩🇪",
"Holy See": "🇻🇦",
Honduras: "🇭🇳",
Hungary: "🇭🇺",
Iceland: "🇮🇸",
India: "🇮🇳",
Indonesia: "🇮🇩",
Iran: "🇮🇷",
Iraq: "🇮🇶",
Ireland: "🇮🇪",
Israel: "🇮🇱",
Italy: "🇮🇹",
Jamaica: "🇯🇲",
Japan: "🇯🇵",
Jordan: "🇯🇴",
Kazakhstan: "🇰🇿",
Kenya: "🇰🇪",
Serbia: "🇷🇸",
Kiribati: "🇰🇮",
Korea: "🇰🇵",
Kosovo: "🇽🇰",
Kuwait: "🇰🇼",
Kyrgyzstan: "🇰🇬",
Laos: "🇱🇦",
Latvia: "🇱🇻",
Lebanon: "🇱🇧",
Lesotho: "🇱🇸",
Liberia: "🇱🇷",
Libya: "🇱🇾",
Liechtenstein: "🇱🇮",
Lithuania: "🇱🇹",
Luxembourg: "🇱🇺",
Madagascar: "🇲🇬",
Malawi: "🇲🇼",
Malaysia: "🇲🇾",
Maldives: "🇲🇻",
Mali: "🇲🇱",
Malta: "🇲🇹",
"Marshall Islands": "🇲🇭",
Mauritania: "🇲🇷",
Mauritius: "🇲🇺",
Mexico: "🇲🇽",
Micronesia: "🇫🇲",
Moldova: "🇲🇩",
Monaco: "🇲🇨",
Mongolia: "🇲🇳",
Montenegro: "🇲🇪",
Morocco: "🇲🇦",
Mozambique: "🇲🇿",
Namibia: "🇳🇦",
Nauru: "🇳🇷",
Nepal: "🇳🇵",
Netherlands: "🇳🇱",
"New Zealand": "🇳🇿",
Nicaragua: "🇳🇮",
Niger: "🇳🇪",
Nigeria: "🇳🇬",
"North Macedonia": "🇲🇰",
"Northern Mariana Islands": "🇲🇵",
Norway: "🇳🇴",
Oman: "🇴🇲",
Pakistan: "🇵🇰",
Palau: "🇵🇼",
"Palestine, State of": "🇵🇸",
Panama: "🇵🇦",
"Papua New Guinea": "🇵🇬",
Paraguay: "🇵🇾",
Peru: "🇵🇪",
Philippines: "🇵🇭",
Poland: "🇵🇱",
Portugal: "🇵🇹",
Qatar: "🇶🇦",
Romania: "🇷🇴",
Russia: "🇷🇺",
Rwanda: "🇷🇼",
"Saint Kitts and Nevis": "🇰🇳",
"Saint Lucia": "🇱🇨",
"Saint Vincent and the Grenadines": "🇻🇨",
Samoa: "🇼🇸",
"San Marino": "🇸🇲",
"Sao Tome and Principe": "🇸🇹",
"Saudi Arabia": "🇸🇦",
Senegal: "🇸🇳",
Serbia: "🇷🇸",
Seychelles: "🇸🇨",
"Sierra Leone": "🇸🇱",
Singapore: "🇸🇬",
Slovakia: "🇸🇰",
Slovenia: "🇸🇮",
"Solomon Islands": "🇸🇧",
Somalia: "🇸🇴",
"South Africa": "🇿🇦",
"South Sudan": "🇸🇸",
Spain: "🇪🇸",
"Sri Lanka": "🇱🇰",
Sudan: "🇸🇩",
Suriname: "🇸🇷",
Sweden: "🇸🇪",
Switzerland: "🇨🇭",
Syria: "🇸🇾",
Taiwan: "🇹🇼",
Tajikistan: "🇹🇯",
Tanzania: "🇹🇿",
Thailand: "🇹🇭",
"Timor-Leste": "🇹🇱",
Togo: "🇹🇬",
Tonga: "🇹🇴",
"Trinidad and Tobago": "🇹🇹",
Tunisia: "🇹🇳",
Turkey: "🇹🇷",
Turkmenistan: "🇹🇲",
Tuvalu: "🇹🇻",
Uganda: "🇺🇬",
Ukraine: "🇺🇦",
"United Arab Emirates": "🇦🇪",
"United Kingdom": "🇬🇧",
"United States": "🇺🇸",
Uruguay: "🇺🇾",
Uzbekistan: "🇺🇿",
Vanuatu: "🇻🇺",
Venezuela: "🇻🇪",
Vietnam: "🇻🇳",
Yemen: "🇾🇪",
Zambia: "🇿🇲",
Zimbabwe: "🇿🇼",
Antarctica: "🇦🇶",
"French Southern Territories": "🇹🇫",
"Bonaire, Sint Eustatius and Saba": " 🇧🇶",
"Christmas Island": "🇨🇽",
"Heard Island and McDonald Islands": "🇭🇲",
"Location not given": "❓",
};
const imgElement = new Image();
imgElement.src = countryFlag;

ScratchTools.appendToSharedSpace({
space: "afterProfileCountry",
element: imgElement,
order: -1,
});

return flags[locationText] || "";
feature.self.hideOnDisable(locationHolder);

function getCountryFlag(locationText) {
const GithubUrl = "https://raw.githubusercontent.com/STForScratch/data/main/flags/";
const countryName = locationText.toLowerCase()
.replaceAll(" ", "-")
.replaceAll("(", "")
.replaceAll(")", "")
.replaceAll(",", "")
.replaceAll(".", "") + ".svg";
return GithubUrl + countryName;
}
}
}
8 changes: 8 additions & 0 deletions features/profile-flag/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.location img {
width: 15px;
height: auto;
margin-top: -1rem;
position: relative;
bottom: -.25rem;
margin-left: .4rem;
}