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 1
1
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 ;
5
4
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 ;
9
10
10
11
const imgElement = new Image ( ) ;
11
- imgElement . src = countryFlag ;
12
+ imgElement . src = flagUrl ;
12
13
13
14
ScratchTools . appendToSharedSpace ( {
14
15
space : "afterProfileCountry" ,
15
16
element : imgElement ,
16
- order : - 1 ,
17
+ order : - 1
17
18
} ) ;
18
19
19
20
feature . self . hideOnDisable ( locationHolder ) ;
20
21
21
- function getCountryFlag ( locationText ) {
22
+ function getFlagUrl ( locationText ) {
22
23
const GithubUrl = "https://raw.githubusercontent.com/STForScratch/data/main/flags/" ;
23
- const countryName = locationText . toLowerCase ( )
24
+ return GithubUrl + locationText . toLowerCase ( )
24
25
. replaceAll ( " " , "-" )
25
26
. replaceAll ( "(" , "" )
26
27
. replaceAll ( ")" , "" )
27
28
. replaceAll ( "," , "" )
28
29
. replaceAll ( "." , "" ) + ".svg" ;
29
- return GithubUrl + countryName ;
30
30
}
31
- }
31
+ }
You can’t perform that action at this time.
0 commit comments