Skip to content
Merged
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
24 changes: 12 additions & 12 deletions features/profile-flag/script.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
export default async function ({ feature }) {
const locationElement = await ScratchTools.waitForElement(
"p.profile-details > span.location"
);
const locationHolder = await ScratchTools.waitForElement("p.profile-details > span.location");
if (!locationHolder) return;

const locationText = locationElement.textContent.trim();
const countryFlag = getCountryFlag(locationText);
if (!countryFlag) return;
const locationText = locationHolder.childNodes[0]?.nodeValue?.trim();
if (!locationText) return;

const flagUrl = getFlagUrl(locationText);
if (!flagUrl) return;

const imgElement = new Image();
imgElement.src = countryFlag;
imgElement.src = flagUrl;

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

feature.self.hideOnDisable(locationHolder);

function getCountryFlag(locationText) {
function getFlagUrl(locationText) {
const GithubUrl = "https://raw.githubusercontent.com/STForScratch/data/main/flags/";
const countryName = locationText.toLowerCase()
return GithubUrl + locationText.toLowerCase()
.replaceAll(" ", "-")
.replaceAll("(", "")
.replaceAll(")", "")
.replaceAll(",", "")
.replaceAll(".", "") + ".svg";
return GithubUrl + countryName;
}
}
}
Loading