样式表的一切 [英] Stylesheet for everything

查看:120
本文介绍了样式表的一切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加载CSS文件的一切。
对于元素:选项卡,侧边栏,标记,窗口,选项,开发人员工具等
我需要这个来改变滚动条。

如何在Firefox中使用addons-sdk?

解决方案

通过evrything,您实际上是指浏览器区域。所以你要做的就是在 @ - moz-document url(chrome://browser/content/browser.xul){} 。否则,CSS将会影响网页内容。



有两种方法可以加载CSS表单,一种是使用 nsIStyleSheetService 一个是
window.loadSheet



window.loadSheet 是推荐的方法。你可以这样做:
$ b $ pre $ code> function registerWindows(){
var _uri = Services.io.newURI( chrome://aus-view/skin/toolbar.css,null,null);
aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).loadSheet(_uri,1);



函数unregisterWindows(){
var _uri = Services.io.newURI(chrome://aus-view/skin/toolbar.css ,null,null);
aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).removeSheet(_uri,1);

$ / code>

您必须确保将您的工作表加载到新打开的窗口中。



使用nsIStyleSheetService,您只需 loadAndRegisterSheet ,然后就不必担心窗口的打开和关闭。但是我听到的表现很难。虽然我不知道这个性能的来源。

  Cu.import('resource:// gre / modules / Services .jsm'); 
var sss = Cc ['@ mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService);
var cssUri = Services.io.newURI('chrome://content/path/to/your/file.css',null,null);
sss.loadAndRegisterSheet(cssUri,sss.USER_SHEET);

然后当你想删除它时,你只需要:

  sss.unregisterSheet(cssUri,sss.USER_SHEET); 

现在这两个文件都被使用了。你可以创建一个没有任何文件的URI:

  var css =''; 
css + ='* {background-color:red; };
css + ='* .hover {background-color:blue; };
var cssEncoded = encodeURIComponent(css);
var cssEncodedWithDataURL ='data:text / css,'+ cssEncoded

我们的URI以同样的方式: var cssUri = Services.io.newURI(cssEncodedWithDataURL,null,null); 然后你只需要以同样的方式加载stylehseet。 (使用第二种方法的例子: sss.unregisterSheet(cssUri,sss.USER_SHEET)


I want to load the CSS file for everything. For elements: tabs, sidebars, tags , windows, options, developer tools, etc. I need this to change the scroll bars.

How to do it in Firefox addons-sdk?

解决方案

By evrything you actually mean the browser area. So what you want to do is write CSS within the brackets of @-moz-document url("chrome://browser/content/browser.xul") { and }. Otherwise the CSS will affect things within webpages.

There are two ways to load in a CSS sheet, one is with the nsIStyleSheetService and one is with window.loadSheet.

The window.loadSheet is the recommended way. You would do it something like this:

function registerWindows() {
    var _uri = Services.io.newURI("chrome://aus-view/skin/toolbar.css", null, null);
    aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).loadSheet(_uri, 1);
}


function unregisterWindows() {
    var _uri = Services.io.newURI("chrome://aus-view/skin/toolbar.css", null, null);
    aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).removeSheet(_uri, 1);
}

You would have to make sure to load your sheet into newly opened windows.

With the nsIStyleSheetService, you just loadAndRegisterSheet and then you don't have to worry about window opening and closing. But it's harder on performance I heard. I don't know the source on this performance though.

Cu.import('resource://gre/modules/Services.jsm');
var sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService);
var cssUri = Services.io.newURI('chrome://content/path/to/your/file.css', null, null);
sss.loadAndRegisterSheet(cssUri, sss.USER_SHEET);

Then when you want to remove it you just do:

sss.unregisterSheet(cssUri, sss.USER_SHEET);

Now those both used files. You can make a URI without any files like this:

var css = '';
css += '* { background-color: red; }';
css += '*.hover { background-color: blue; }';
var cssEncoded = encodeURIComponent(css);
var cssEncodedWithDataURL = 'data:text/css,' + cssEncoded 

Then we just make our URI the same way: var cssUri = Services.io.newURI(cssEncodedWithDataURL, null, null); Then you just load the stylehseet the same way. (Example using 2nd method: sss.unregisterSheet(cssUri, sss.USER_SHEET))

这篇关于样式表的一切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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