Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Greasemonkey script to make Fixed Positioned Elements Static

I find elements on a web page that have been positioned fixed to be in my way frequently. I'd like to find a way to disable position: fixed CSS rules in any web site that I visit.

I wrote a userscript (Firefox, Greasemonkey) that scans every node in the document and figures out if it has a computed style position fixed, then overrides that to be static.

Is there a better way to accomplish my goal?

This is the script I wrote, I've narrowed it to just divs for now:

Array.forEach(
    document.querySelectorAll("div")
    ,function(el) {
        if (window.getComputedStyle(el).position === 'fixed') {
            el.style.position = 'static';
        }
    }
);
like image 643
Rob Avatar asked Jul 15 '26 01:07

Rob


1 Answers

If your Greasemonkey script works, it is probably the most cost effective way to eliminate fixed-positioned styling.

Some alternatives that require much more effort but will use less CPU/memory per page:

  1. Write an Add-on that:

    1. Deletes CSS style rules as they are loaded. (Greasemonkey cannot always do this because of cross-domain issues.)
    2. Uses Mutation Observers to intercept javascript attempts to set position: fixed.


  2. Fork and compile your own version of Firefox that ignores position: fixed. You'd probably want this controlled by both a "blacklist" and a "whitelist".

like image 67
Brock Adams Avatar answered Jul 16 '26 14:07

Brock Adams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!