Fix placeholder style copying and root domain calculation

Only copy dimensional style properties (width, height, margin, etc.)
to placeholders instead of blindly copying all cssText, which could
override layout properties like display: flex.

Handle multi-part TLDs (e.g. .co.uk, .com.au) when computing the root
domain for cookie deletion.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-21 21:32:43 +04:00
parent 2b59a10c14
commit 140e614e4f

View File

@@ -129,7 +129,26 @@ function createPlaceholder(
const h = el.getAttribute("height");
if (h) placeholder.style.height = /^\d+$/.test(h) ? h + "px" : h;
if (htmlEl.style?.cssText) placeholder.style.cssText += htmlEl.style.cssText;
const DIMENSIONAL_PROPS = [
"width",
"height",
"min-width",
"min-height",
"max-width",
"max-height",
"aspect-ratio",
"margin",
"margin-top",
"margin-right",
"margin-bottom",
"margin-left",
];
if (htmlEl.style) {
for (const prop of DIMENSIONAL_PROPS) {
const val = htmlEl.style.getPropertyValue(prop);
if (val) placeholder.style.setProperty(prop, val);
}
}
placeholder.innerHTML = [
`<span class="probo-ph-icon">${LOCK_ICON}</span>`,
@@ -295,10 +314,49 @@ function deactivateElement(el: Element, label?: string): void {
}
}
const KNOWN_MULTI_PART_TLDS = new Set([
"co.uk",
"co.jp",
"co.kr",
"co.nz",
"co.za",
"co.in",
"co.id",
"com.au",
"com.br",
"com.cn",
"com.mx",
"com.tw",
"com.hk",
"com.sg",
"com.ar",
"com.co",
"com.tr",
"net.au",
"org.uk",
"org.au",
"ac.uk",
"gov.uk",
"ne.jp",
"or.jp",
]);
function getRootDomain(hostname: string): string {
const parts = hostname.split(".");
if (parts.length <= 2) {
return parts.length === 2 ? "." + hostname : hostname;
}
const lastTwo = parts.slice(-2).join(".");
if (KNOWN_MULTI_PART_TLDS.has(lastTwo)) {
return "." + parts.slice(-3).join(".");
}
return "." + lastTwo;
}
function removeCookies(names: string[]): void {
const parts = location.hostname.split(".");
const rootDomain =
parts.length > 1 ? "." + parts.slice(-2).join(".") : location.hostname;
const rootDomain = getRootDomain(location.hostname);
for (const name of names) {
document.cookie = `${name}=; path=/; max-age=0`;