4,456
edits
No edit summary |
No edit summary |
||
Line 1,370: | Line 1,370: | ||
// Remove “empty” optional sections so they don’t leave gaps in print. | // Remove “empty” optional sections so they don’t leave gaps in print. | ||
// --- | // --- Compact vertical spacing & report gaps in the print iframe --- | ||
(function | (function compactAndReport(doc) { | ||
// | // 1) Trim margins everywhere in #article-content. Rely on your hairline padding instead. | ||
var | var css = doc.createElement("style"); | ||
css.textContent = | |||
"@media print{" + | |||
"#article-content>*{margin-top:0!important;margin-bottom:0!important}" + | |||
// keep your hairline look but ensure it’s not huge | |||
".article-entry-number," + | |||
".link-pdf," + | |||
".article-type," + | |||
".article-metadata," + | |||
".article-images," + | |||
".article-description," + | |||
".article-reflection," + | |||
".article-external-reference," + | |||
".article-quote," + | |||
".article-mod-line{padding-bottom:6px!important}" + | |||
// remove hairline on the very last child to avoid a trailing gap | |||
"#article-content>:last-child{padding-bottom:0!important}" + | |||
"#article-content>:last-child::after{content:none!important}" + | |||
// kill any accidental block that’s truly empty (divs/spans) | |||
"#article-content div:empty,#article-content p:empty{display:none!important;height:0!important;padding:0!important;border:0!important}" + | |||
"}"; | |||
doc.head.appendChild(css); | |||
// | // 2) Extra cleanup: remove empty DIV shells that still contain only whitespace | ||
(function removeEmptyDivs() { | |||
var nodes = doc.querySelectorAll("#article-content div"); | |||
for (var i = 0; i < nodes.length; i++) { | |||
var el = nodes[i]; | |||
var | if (!el.firstElementChild) { | ||
var t = (el.textContent || "") | |||
.replace(/\u00A0/g, " ") | |||
.replace(/\u200B/g, "") | |||
.trim(); | |||
if (!t && el.parentNode) el.parentNode.removeChild(el); | |||
} | } | ||
} | } | ||
})(); | })(); | ||
// | // 3) GAP reporter — logs where any unexpected space (>8px) occurs between siblings | ||
(function reportGaps() { | |||
var container = doc.getElementById("article-content"); | |||
if (!container) return; | |||
var kids = []; | |||
for ( | |||
var n = container.firstElementChild; | |||
n; | |||
n = n.nextElementSibling | |||
) { | |||
(function () { | // skip nodes that are display:none (offsetParent null) or zero-height | ||
var | if (!n.offsetParent || n.offsetHeight === 0) continue; | ||
if (! | kids.push(n); | ||
var | |||
var | |||
if (! | |||
} | } | ||
for (var i = 0; i < kids.length - 1; i++) { | |||
var a = kids[i], | |||
b = kids[i + 1]; | |||
var gap = | |||
b.getBoundingClientRect().top - | |||
(a.getBoundingClientRect().top + | |||
a.getBoundingClientRect().height); | |||
if (gap > 8) { | |||
console.log( | |||
"[print] GAP", | |||
Math.round(gap) + "px", | |||
"between", | |||
a.className || a.tagName, | |||
"→", | |||
b.className || b.tagName | |||
); | |||
} | } | ||
} | } | ||
})(); | })(); | ||
})(doc); | })(doc); |