0
我正在尝试使用nsIStyleSheetService
注入样式表文件。有没有办法使用nsIStyleSheetService在特定网站上注入CSS?
当我这样做时,它会在所有页面上注入样式,但我只想定位一些网站。
可能吗?
我的代码:所有的
LoadStyleSheet = function(source) {
var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
.getService(Components.interfaces.nsIStyleSheetService);
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ios.newURI("chrome://addon/content/css/" + source, null, null);
if(!sss.sheetRegistered(uri, sss.AGENT_SHEET))
sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
};
和
if (/^https?:\/\/[^\/]+google.*/i.test(window.location.href))
{
LoadStyleSheet("config.css"); // register the style on all pages
// while my target is just Google
}
也许试试看看[时尚](https://addons.mozilla.org/en-US/firefox/addon/stylish/),因为我认为你想做的事情与它很相似确实。 – MatrixFrog 2011-02-26 21:30:24
我不知道为什么正则表达式测试似乎没有工作。尝试发送'window.location.href'到控制台也许。 – MatrixFrog 2011-02-26 21:33:03
@MatrixFrog,正则表达式测试确实有效。但是,一旦所有网站受到影响,就会引发火灾...... – BrunoLM 2011-02-26 22:22:05