Support absolute sponsor image URLs

This commit is contained in:
Carlos Polop
2026-07-04 13:35:45 +02:00
parent fdd3d95668
commit c4d28b9207
+23 -1
View File
@@ -107,8 +107,30 @@
return "" return ""
} }
function resolveSponsorImageUrl(imageUrl) {
var value = String(imageUrl || "").trim()
if (!value) {
return ""
}
if (/^https:\/\//i.test(value)) {
return value
}
if (/^\/\//.test(value)) {
return "https:" + value
}
if (value.charAt(0) === "/") {
return new URL(value, window.location.origin).href
}
return new URL(value, document.baseURI || window.location.href).href
}
function setLegacySponsorContent(sponsor, container, nodes) { function setLegacySponsorContent(sponsor, container, nodes) {
nodes.img.src = sponsor.image_url nodes.img.src = resolveSponsorImageUrl(sponsor.image_url)
nodes.img.alt = sponsor.name nodes.img.alt = sponsor.name
nodes.title.textContent = sponsor.name nodes.title.textContent = sponsor.name
nodes.description.innerHTML = sponsor.description nodes.description.innerHTML = sponsor.description