Lurker News

Comments (242) 68 threads

Show all comments

Showing thread 6 of 68

err4nt2 replies#
Further size reduction, you don't need the `this.` on the inline event listener, so it can be: `contentWindow.location.hash` and `contentDocument.body.childNodes` instead of `this.contentWindow.location.hash` or `this.contentDocument.body.childNodes`.

This will shave another 10 bytes off the snippet :D

ericlewis1 reply#
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))

Kalabasa#
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.

niutech#
If you write `document.querySelector(contentWindow.location.hash||null)?.outerHTML=contentDocument.body.innerHTML`, you'll make it even shorter.