Skip to content

Commit 0dfbb61

Browse files
authored
Fix Flag Feature
1 parent bfde8de commit 0dfbb61

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

features/profile-flag/script.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
export default async function ({ feature }) {
2-
const locationElement = await ScratchTools.waitForElement(
3-
"p.profile-details > span.location"
4-
);
2+
const locationHolder = await ScratchTools.waitForElement("p.profile-details > span.location");
3+
if (!locationHolder) return;
54

6-
const locationText = locationElement.textContent.trim();
7-
const countryFlag = getCountryFlag(locationText);
8-
if (!countryFlag) return;
5+
const locationText = locationHolder.childNodes[0]?.nodeValue?.trim();
6+
if (!locationText) return;
7+
8+
const flagUrl = getFlagUrl(locationText);
9+
if (!flagUrl) return;
910

1011
const imgElement = new Image();
11-
imgElement.src = countryFlag;
12+
imgElement.src = flagUrl;
1213

1314
ScratchTools.appendToSharedSpace({
1415
space: "afterProfileCountry",
1516
element: imgElement,
16-
order: -1,
17+
order: -1
1718
});
1819

1920
feature.self.hideOnDisable(locationHolder);
2021

21-
function getCountryFlag(locationText) {
22+
function getFlagUrl(locationText) {
2223
const GithubUrl = "https://raw.githubusercontent.com/STForScratch/data/main/flags/";
23-
const countryName = locationText.toLowerCase()
24+
return GithubUrl + locationText.toLowerCase()
2425
.replaceAll(" ", "-")
2526
.replaceAll("(", "")
2627
.replaceAll(")", "")
2728
.replaceAll(",", "")
2829
.replaceAll(".", "") + ".svg";
29-
return GithubUrl + countryName;
3030
}
31-
}
31+
}

0 commit comments

Comments
 (0)