Skip to content

Instantly share code, notes, and snippets.

@forivall
Created September 30, 2021 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forivall/57a5d60c99dee1b1ac6184f629592849 to your computer and use it in GitHub Desktop.
Save forivall/57a5d60c99dee1b1ac6184f629592849 to your computer and use it in GitHub Desktop.
bookmarklet for improved printing
document.querySelectorAll('h1,h2,h3,h4,h5,h6').forEach((h) => {
var e = h.nextElementSibling, a = [h], d
e && a.push(e)
while (e && /H[0-6]/.test(e.tagName)) (e = e.nextElementSibling) && a.push(e)
if (a.length === 1) return
d = document.createElement('div')
d.style.display = 'inline-block'
h.replaceWith(d)
d.append(...a)
})
javascript:document.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach((h=>{var e=h.nextElementSibling,a=[h],d;for(e&&a.push(e);e&&/H[0-6]/.test(e.tagName);)(e=e.nextElementSibling)&&a.push(e);1!==a.length&&((d=document.createElement("div")).style.display="inline-block",h.replaceWith(d),d.append(...a))}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment