I am trying to inject a stylesheet file using nsIStyleSheetService
.
When I do that it injects the style on all pages, but I want to target jus开发者_如何学运维t some websites.
Is it possible?
My code:
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);
};
and
if (/^https?:\/\/[^\/]+google.*/i.test(window.location.href))
{
LoadStyleSheet("config.css"); // register the style on all pages
// while my target is just Google
}
First of all, you likely want to specify USER_SHEET
instead of AGENT_SHEET
. Secondly, you have to specify what is applied in your stylesheet like this code. More information can be found here.
精彩评论