Greasemonkey脚本使固定位置元素静态 [英] Greasemonkey script to make Fixed Positioned Elements Static

查看:155
本文介绍了Greasemonkey脚本使固定位置元素静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现网页上的元素已经被固定在我的方式经常。我想找到一种方法来禁用位置:固定 CSS规则在我访问的任何网站。



我写了一个用户脚本(Firefox,Greasemonkey)来扫描文档中的每个节点,并计算出是否有一个固定的计算样式位置,然后覆盖它是静态的。

有没有更好的方法来实现我的目标?



这是我写的脚本,我已经缩小到现在的div了。
$ b $ p $ Array.forEach(
document.querySelectorAll(div)
,function(el){
if( window.getComputedStyle(el).position ==='fixed'){
el.style.position ='static';
}
}
);


解决方案

如果您的Greasemonkey脚本可以运行,

一些替代方案需要付出更多的努力,但每个页面使用的CPU /内存更少:


  1. 撰写


    1. 删除CSS样式规则加载。 (由于跨域问题,Greasemonkey不能总是这样做。)

    2. 使用拦截JavaScript尝试设置 position:fixed 。 li>



  2. 分配并编译您自己的Firefox版本忽略 position:fixed 。你可能想要这个由黑名单和白名单控制。



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

解决方案

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

这篇关于Greasemonkey脚本使固定位置元素静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆