Hacker News new | ask | show | jobs
by ericlewis 852 days ago
We can bring that down to 16 since query selector can handle undefined. 12% reduction.

setTimeout(()=>document.querySelector(contentWindow.location.hash)?.replaceWith(...contentDocument.body.childNodes))

1 comments

Yeah, querySelector(undefined) works

Although location.hash defaults to the empty string '' when there is no hash, which gives a SyntaxError, so we still need the fallback selector to select none.