Here you often discuss about User-Agent. I don't know why it takes 10-15 different UA strings, but it does not matter. Now it's possible even more, here is possibility that you create UA rules (or exceptions) for the site. This file transmits UA header of your choice, and you can create rules.
User interface requires more lines and more time. Of course, you're all invited to complete the interface.
Important:
nsUserAgent.js file reads preferences 'network.httpheaders.User-Agent.'
If you want to create a rule, for example for site
http://kmeleon.sourceforge.net, and you want to send UA header Firefox 14.0.1, you need to create a pref STRING 'network.httpheaders.User-Agent.firefox' and set value:
Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1@kmeleon.sourceforge.net
So, in the first place is ua string, then @, then hostname. Here you can put more than one page, but it is necessary to separate each, use a empty character, for example:
Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1@kmeleon.sourceforge.net en.wikipedia.org developer.mozilla.org
Now you create a new pref, for example STRING 'network.httpheaders.User-Agent.iexplorer' etc...
nsUserAgent.js (put this file in the folder components)
/** K-meleon HTTP Headers (User-Agent) © 2013 adodupan **/
Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
const Cc = Components.classes;
const Ci = Components.interfaces;
const UA_RULES = 'network.httpheaders.User-Agent.';
function nsUserAgent() {
//this.wrappedJSObject = this;
this.observer = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
this.prefs = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefService)
.getBranch(UA_RULES);
}
nsUserAgent.prototype = {
classDescription: 'Create a rule for UserAgent',
contractID: '@adodupan/nsUserAgent;1',
classID: Components.ID('{18823150-88e5-11e2-9e96-0800200c9a66}'),
Load: function(aSubject) {
var nsIHttpChannel = aSubject.QueryInterface(Ci.nsIHttpChannel),
nsIChannel = aSubject.QueryInterface(Ci.nsIChannel);
for(var a=0,b=this.prefs.getChildList('', {});a<b.length;a++) {
if(this.prefs.getCharPref(b[a]).indexOf(nsIChannel.URI.host)>-1) {
nsIHttpChannel.setRequestHeader('User-Agent', this.prefs.getCharPref(b[a]).split('@')[0], false);
return;
break;
}
}
},
observe: function(aSubject, aTopic, aData) {
try{
switch(aTopic) {
case 'app-startup' : this.AppStartup(); break;
case 'http-on-modify-request' : this.Load(aSubject); break;
case 'xpcom-shutdown' : this.Shutdown(); break;
}
}catch(err){}
},
get Shutdown() {
this.observer.removeObserver(this, 'http-on-modify-request');
this.observer.removeObserver(this, 'xpcom-shutdown');
},
get AppStartup() {
this.observer.addObserver(this, 'xpcom-shutdown', false);
this.observer.addObserver(this, 'http-on-modify-request', false);
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
_xpcom_categories: [{ category: 'app-startup', service: true }]
};
function NSGetModule(compMgr, fileSpec) {
return XPCOMUtils.generateModule([nsUserAgent]);
}
Regards