Greasemonkey脚本使固定位置元素静态 [英] Greasemonkey script to make Fixed Positioned Elements Static
问题描述
位置:固定
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 /内存更少:
-
撰写 :
- 删除CSS样式规则加载。 (由于跨域问题,Greasemonkey不能总是这样做。)
- 使用拦截JavaScript尝试设置
position:fixed
。 li>
-
分配并编译您自己的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:
Write an Add-on that:
- Deletes CSS style rules as they are loaded. (Greasemonkey cannot always do this because of cross-domain issues.)
- Uses Mutation Observers to intercept javascript attempts to set
position: fixed
.
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屋!