Extensions
: K-Meleon Forum
All about K-Meleon extensions.
Goto:
Forum List
•
Message List
•
Search
•
Log In
Your Name:
Subject:
Help information
BBcode help
Smileys help
[quote=adodupan] 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. [b]User interface requires more lines and more time. Of course, you're all invited to complete the interface.[/b] 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) [size=10px]/** 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() { [list]//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);[/list] } nsUserAgent.prototype = { classDescription: 'Create a rule for UserAgent', contractID: '@adodupan/nsUserAgent;1', classID: Components.ID('{18823150-88e5-11e2-9e96-0800200c9a66}'), Load: function(aSubject) { [list] var nsIHttpChannel = aSubject.QueryInterface(Ci.nsIHttpChannel), nsIChannel = aSubject.QueryInterface(Ci.nsIChannel); for(var a=0,b=this.prefs.getChildList('', {});a<b.length;a++) { [list] if(this.prefs.getCharPref(b[a]).indexOf(nsIChannel.URI.host)>-1) { [list] nsIHttpChannel.setRequestHeader('User-Agent', this.prefs.getCharPref(b[a]).split('@')[0], false); return; break;[/list] }[/list] }[/list] }, observe: function(aSubject, aTopic, aData) { [list] try{ [list] switch(aTopic) { [list] case 'app-startup' : this.AppStartup(); break; case 'http-on-modify-request' : this.Load(aSubject); break; case 'xpcom-shutdown' : this.Shutdown(); break;[/list] }[/list] }catch(err){}[/list] }, get Shutdown() { [list] this.observer.removeObserver(this, 'http-on-modify-request'); this.observer.removeObserver(this, 'xpcom-shutdown');[/list] }, get AppStartup() { [list] this.observer.addObserver(this, 'xpcom-shutdown', false); this.observer.addObserver(this, 'http-on-modify-request', false);[/list] }, QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), _xpcom_categories: [{ category: 'app-startup', service: true }] }; function NSGetModule(compMgr, fileSpec) { [list] return XPCOMUtils.generateModule([nsUserAgent]);[/list] }[/size] Regards[/quote]
[Please Enable JavaScript]
K-Meleon forum is powered by
Phorum
.
Home/News
Screenshots
Download
Documentation
Resources
Get Involved
Forum
Bugs
Development