Re:A bookmarklet to kill sticky headers
by evgpbfhnr on Sunday February 02, 2025 @02:04AM
(#42906694)
Interestingly running this in the console works but from a bookmarklet changes all the page content to false,false,false,.... (on firefox)
Any idea?
Re:A bookmarklet to kill sticky headers
by Robin_Message on Sunday February 02, 2025 @03:32AM
(#42907141)
Change map to forEach?
Re:A bookmarklet to kill sticky headers
by silvestrov on Sunday February 02, 2025 @03:56AM
(#42907284)
document.querySelectorAll('body *').forEach(e=>{if (["fixed","sticky"].includes(getComputedStyle(e).position)) e.remove()});
Firefox expects your script to return undefined, so you can add one at the end (or even shorter: void 0).
Re:A bookmarklet to kill sticky headers
by evgpbfhnr on Sunday February 02, 2025 @07:11AM
(#42908173)
Thank you (and neighbors), I didn't know this.
Re:A bookmarklet to kill sticky headers
by handsclean on Sunday February 02, 2025 @08:18AM
(#42908446)
To clarify slightly, bookmarklet behavior across browsers is to call `document.write` with the result of the bookmarklet’s last expression unless that result is `undefined`, and calling `document.write` after page load completes replaces the page’s DOM with the content written. It’s a weird bookmarklet thing, I don’t think there’s anywhere else in JS that accepts a list of statements, not expressions, but cares about the result of the last expression.
People often disable this by making the last expression `void 0`, which evaluates to `undefined`. This is really an anachronism, though, the original point wasn’t actually brevity (it’s only one character shorter after URL encoding, not worth funky syntax) but that just writing `undefined` was broken and sometimes didn’t evaluate to the special value undefined. That’s fixed now, so I would just append `undefined` instead.
Though, really what you should do is always wrap bookmarklets in IIFEs, which avoids stomping around the page’s global variables, lets you write code with early exits, lets you opt back in with an explicit return rather than editing boilerplate, and also solves this issue as a bonus.
Re:A bookmarklet to kill sticky headers
by gabrielsroka on Sunday February 02, 2025 @12:46PM
(#42910237)
even more minified. forEach doesn't return anything, so you don't need the IIFE.
javascript:document.querySelectorAll('body *').forEach(el=>['fixed','sticky'].includes(getComputedStyle(el).position)&&el.remove())
or javascript:document.querySelectorAll('body *').forEach(el=>/^(fixed|sticky)$/.test(getComputedStyle(el).position)&&el.remove())
Here's a minified version with "sticky" added:
javascript:(()=>[...document.querySelectorAll('body *')].map(el=>["fixed","sticky"].includes(getComputedStyle(el).position)&&el.remove()))();