mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-29 08:11:32 +00:00
22 lines
554 B
TypeScript
22 lines
554 B
TypeScript
import { sanitizeUrl } from '@/utils/url'
|
|
|
|
export function updateFavicon(logoUrl: string): void {
|
|
const sanitizedLogoUrl = sanitizeUrl(logoUrl, {
|
|
allowRelative: true,
|
|
allowDataUrl: true,
|
|
})
|
|
if (!sanitizedLogoUrl) {
|
|
return
|
|
}
|
|
|
|
let link = document.querySelector<HTMLLinkElement>('link[rel="icon"]')
|
|
if (!link) {
|
|
link = document.createElement('link')
|
|
link.rel = 'icon'
|
|
document.head.appendChild(link)
|
|
}
|
|
|
|
link.type = sanitizedLogoUrl.endsWith('.svg') ? 'image/svg+xml' : 'image/x-icon'
|
|
link.href = sanitizedLogoUrl
|
|
}
|