"The validatedTextField will format URLs to always be valid and have a https://-header (even though the 'https'-part will be hidden from the user. Furthermore, some tracking parameters will be removed",
"url"
)
}
reformat(str: string):string{
try{
leturl: URL
// str = str.toLowerCase() // URLS are case sensitive. Lowercasing them might break some URLS. See #763
if(
!str.startsWith("http://")&&
!str.startsWith("https://")&&
!str.startsWith("http:")
){
url=newURL("https://"+str)
}else{
url=newURL(str)
}
constblacklistedTrackingParams=[
"fbclid",// Oh god, how I hate the fbclid. Let it burn, burn in hell!
"gclid",
"cmpid",
"agid",
"utm",
"utm_source",
"utm_medium",
"campaignid",
"campaign",
"AdGroupId",
"AdGroup",
"TargetId",
"msclkid",
]
for(constdontLikeofblacklistedTrackingParams){
url.searchParams.delete(dontLike.toLowerCase())
}
letcleaned=url.toString()
if(cleaned.endsWith("/")&&!str.endsWith("/")){
// Do not add a trailing '/' if it wasn't typed originally