File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed
Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change 11export 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+ }
You can’t perform that action at this time.
0 commit comments