如何阻止通过Firefox扩展下载和应用CSS的Firefox? [英] How to stop firefox from downloading and applying CSS via a firefox extension?

查看:174
本文介绍了如何阻止通过Firefox扩展下载和应用CSS的Firefox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢大家提前 -

所以我在这个问题上已经有很长的一段时间了,并且烧毁了我所有的选择。我目前取消css请求的方法是在nsIWebProgressListener.onStateChange中使用nsIRequest.cancel。这在大多数情况下都是有效的,除非事情有点迟缓,否则有几个人会溜走,跳出负荷组,然后才能找到他们。这显然是个肮脏的解决方案。



我已经阅读了以下链接,尝试了解如何在创建nsIRequest之前禁用css ...没有骰子。 b
$ b'p> https://developer.mozilla.org/en/ Document_Loading _-_ From_Load_Start_to_Finding_a_Handler
https://developer.mozilla.org/en/The_life_of_an_HTML_HTTP_request
https://developer.mozilla.org/zh/Bird's_Eye_View_of_the_Mozilla_Framework



如何通过表示对象/接口禁用css?这可能吗?里面nsIDocShell的有那种暗示你可以通过浏览器禁用CSS docshell一些属性 - ?allowPlugins,allowJavascript,allowMetaRedirects,allowSubframes,allowImages



任何建议



谢谢,

Sam

解决方案

禁用样式表的菜单选项使用一个函数

$ $ c $ set $ c $ setStyleDisabled

所以,只要创建了新的浏览器标签,你可能就可以调用这个函数。样式表仍然从服务器请求,但不适用。这个函数不是很复杂,不会和nsIRequest混淆,来源:

 函数setStyleDisabled(disabled){
getMarkupDocumentViewer()。authorStyleDisabled = disabled;

$ / code>

在Web Developer Toolbar源代码中挖掘我注意到他们的禁用样式表函数循环遍历所有 document.styleSheets 并将 disabled 属性设置为 true

  / *如果加载了DOM内容* / 
var sheets = document.styleSheets;
for(var i in sheets){sheets [i] .disabled = true; }

因此,如果关键是不将CSS应用于页面,上述解决方案之一应该工作。但是如果你真的需要停止从服务器上下载样式表,我很担心 nsIRequest 拦截是你唯一的选择。


Thanks to everyone in advance -

So I have been banging on this issue for quite a while now and have burned through all my options. My current approach to canceling css requests is with nsIRequest.cancel inside of nsIWebProgressListener.onStateChange. This works most of the time, except when things are a little laggy a few will slip through and jump out of the loadgroup before I can get to them. This is obviously a dirty solution.

I have read through the following links to try and get a better idea of how to disable css before a nsIRequest is created...no dice.

https://developer.mozilla.org/en/Document_Loading_-_From_Load_Start_to_Finding_a_Handler https://developer.mozilla.org/en/The_life_of_an_HTML_HTTP_request https://developer.mozilla.org/en/Bird's_Eye_View_of_the_Mozilla_Framework

How do I disable css via presentation objects/interfaces? Is this possible? Inside of nsIDocShell there are a few attributes that kind of imply you can disable css via the browsers docshell - allowPlugins, allowJavascript, allowMetaRedirects, allowSubframes, allowImages.

Any suggestions?

Thanks,

Sam

解决方案

The menu option that disables style sheets uses a function

setStyleDisabled(true)

so you probably can just call this function whenever new browser tab is created. Style sheets are still requested from server, but not applied. This function is not very sophisticated and doesn't mess with nsIRequest, source:

function setStyleDisabled(disabled) {
  getMarkupDocumentViewer().authorStyleDisabled = disabled;
}

Digging in Web Developer Toolbar source code I have noticed that their "disable stylesheets" function loops trough all document.styleSheets and sets the disabled property to true, like:

/* if DOM content is loaded */
var sheets = document.styleSheets;
for(var i in sheets){ sheets[i].disabled = true; }

So if the key is to not apply CSS to pages, one of the above solutions should work. But if you really need to stop style sheets from being downloaded from servers, I'm affraid nsIRequest interception is your only option.

这篇关于如何阻止通过Firefox扩展下载和应用CSS的Firefox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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