在Firefox中,当您右键单击图像以查看其“属性”对话框时,几乎每次位置URL都会延伸到小对话框中看不见的地方。当我的图像属性检查同事问我是否有办法永久扩大该对话框时,我被难住了,多个MozillaZine搜索失败了。...
在Firefox中,当您右键单击图像以查看其“属性”对话框时,几乎每次位置URL都会延伸到小对话框中看不见的地方。当我的图像属性检查同事问我是否有办法永久扩大该对话框时,我被难住了,多个MozillaZine搜索失败了。
幸运的是,我的Firefox好友Mark Pilgrim找到了答案:
使用style定义XUL样式:
@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);window#metadata { width: 60em !important; }
太好了,它工作了!本着教女人钓鱼的精神,马克详细介绍了他是如何通过浏览器的源代码找到答案的。跳转之后,他透露了搜索Firefox内部的秘密。
马克描述了查找他可以改变什么样式来扩大对话框的过程,并说这是一种常见的模式,更多的Firefox调整者应该知道。警告:这些说明是为那些愿意卷起袖子,把手伸进Firefox内脏弄脏的人准备的。你已经被警告了。
以下是马克为找到这条线索所做的:
- Mozilla Cross-Reference lets you search the Firefox source code
- Search for "alternate text" (no quotes), because this is a phrase that appears in the dialog that probably doesn't appear in very many places in the source code
- The search for "alternate text" shows that, as predicted, the phrase only appears in a few places.
- Ignore anything that is just a source code comment (// or /* */ or #).
- Ignore anything in /editor (that's Composer) or /suite (that's Seamonkey).
- In this case that only leaves a few hits in /browser, specifically /browser/locales/en-US, and both of them are .dtd files. That's a good sign — all end-user-visible text in Firefox is localized in .dtd files, so this means we've found a place where the phrase "alternate text" is used in the UI somewhere.
- There are two matches within /browser/locales/en-US: metaData.dtd and pageInfo.dtd. Generally each .dtd file is specific to a particular window or dialog. On a hunch, I guessed (correctly) that pageInfo.dtd was used in the Tools/Page Info dialog, and metaData.dtd was used in the properties dialog that we're looking for.
- The metaData.dtd search result shows that the phrase "Alternate text" is defined as the entity &image-alt.label;. So I did a new lxr search for "image-alt.label".
- A search for image-alt.label shows exactly 4 results. 2 are in /suite, which we ignore. 1 is the .dtd file that we just came from, and the other is a .xul file. That's the one we want.
- metaData.xul has a grid with rows like "image-url", "image-type", "image-size", "image-filesize", "image-alt", and "image-desc". Sound familiar? You don't need to know a lot about XUL to guess (correctly) that you've found the dialog you want to hack.
- OK, now look at the top of the file. The root element is <window>, and we're in luck: it has a unique ID "metadata". It also defines its initial dimensi*** in the style attribute: width: 40em, height: 10em.
- Now we whip out Stylish and write a new style. Insert the XUL namespace (from the "Insert" dropdown button), and try window#metadata { width: 60em }. Save the style. Stylish styles take effect immediately, so test it by right-clicking an image and selecting "Properties". Lo and behold, we've done it! You can adjust the final width to taste, of course — now that you know the window ID, you can apply any CSS styles you like.
现在,我的朋友们,这就是公开源码的美丽和魔力。谢谢你,马克!