Greasemonkey script to make Fixed Positioned Elements Static

孤者浪人 提交于 2019-12-23 19:40:54

问题


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';
        }
    }
);

回答1:


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".



来源:https://stackoverflow.com/questions/13696100/greasemonkey-script-to-make-fixed-positioned-elements-static

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!