mirror of
https://github.com/thegeneralist01/archivr
synced 2026-07-21 18:55:36 +02:00
fix: remove ad placeholders when uBlock active; kept height causes blank gap
uBlock Origin Lite blocks ad network requests but first-party placeholder elements (ins.adsbygoogle, #aswift_* iframe hosts) retain their computed height (e.g. 280px for a top banner), leaving a large blank space at the top of captured pages. Gate cleanup on ublock_ext.is_some(): remove ins.adsbygoogle, aswift_* iframes, and google_ads_* iframes before SingleFile serialises. Also collapse the parent container if it becomes empty after removal.
This commit is contained in:
parent
e51a99bc77
commit
5a9c65551a
1 changed files with 21 additions and 0 deletions
|
|
@ -292,6 +292,27 @@ fn save_with(
|
|||
).forEach(function(el){el.remove();});",
|
||||
);
|
||||
}
|
||||
if ublock_ext.is_some() {
|
||||
// uBlock blocks ad network requests but first-party ad placeholder
|
||||
// elements (ins.adsbygoogle, iframe hosts) retain their computed
|
||||
// height, leaving blank space. Remove them pre-capture.
|
||||
strip_scripts.push_str(
|
||||
"document.querySelectorAll(\
|
||||
'ins.adsbygoogle,\
|
||||
[id^=\"aswift_\"],\
|
||||
iframe[id^=\"google_ads_\"],\
|
||||
iframe[name^=\"google_ads_frame\"],\
|
||||
iframe[src*=\"googlesyndication\"],\
|
||||
iframe[src*=\"doubleclick\"]'\
|
||||
).forEach(function(el){\
|
||||
var p=el.parentElement;\
|
||||
el.remove();\
|
||||
/* collapse parent if it's now empty and was ad-only */\
|
||||
if(p&&!p.textContent.trim()&&p.children.length===0)\
|
||||
p.style.display='none';\
|
||||
});",
|
||||
);
|
||||
}
|
||||
strip_scripts.push_str("});");
|
||||
std::fs::write(&strip_scripts_path, &strip_scripts)
|
||||
.context("failed to write single-file user script")?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue