我在 Firefox Devtools 中扩展 css 规则查看器,发现了一些有趣的东西:这是 chrome://browser/content/devtools/cssruleview.xul 的内容:
<?xml version="1.0"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<?xml-stylesheet href="chrome://global/skin/global.css"?>
<?xml-stylesheet href="chrome://browser/content/devtools/styleinspector.css" type="text/css"?>
<?xml-stylesheet href="chrome://browser/skin/devtools/csshtmltree.css" type="text/css"?>
<?xml-stylesheet href="chrome://browser/skin/devtools/common.css" type="text/css"?>
<!DOCTYPE window [
<!ENTITY % inspectorDTD SYSTEM "chrome://browser/locale/devtools/styleinspector.dtd">
%inspectorDTD;
]>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" title="&ruleViewTitle;">
<script type="application/javascript;version=1.8">
window.setPanel = function(panel, iframe) {
Components.utils.import("resource:///modules/devtools/StyleInspector.jsm");
this.ruleview = new RuleViewTool(panel, window, iframe);
}
window.onunload = function() {
if (this.ruleview) {
this.ruleview.destroy();
}
}
</script>
</window>
但是,DOM 检查器显示了许多不同的元素,带有上下文菜单项的菜单弹出窗口等。我试图用它覆盖文件,但它不起作用.. 可能是因为它是动态生成的。这没有用:
<?xml version="1.0" encoding="utf-8"?>
<overlay id="cssInspectorOverlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<menupopup id="rule-view-context-menu">
<menuitem id="new-rule-devtooltweak"
label="New Rule..."
accesskey="N"
oncommand="alert('yahoo')"/>
</menupopup>
</overlay>
在 Mozilla 中查看 CssRuleView.jsm,我发现元素是使用 createElement 创建的,而不是 xul 文件!我想知道他们为什么这样做——出于性能考虑,还是出于其他原因?