Ho questo componente aggiuntivo col nome di IPFuck. Mi potete aiutare a studiare il suo codice?
var ipfuck = {
inited: false,
init: function() {
if (!this.inited) {
if (this.get_pref('ipfuck_enabled') == true)
this.register();
this.inited = true;
}
},
observe: function(subject, topic, data) {
if (topic == "http-on-modify-request") {
var channel = subject.QueryInterface(Components.interfaces.nsIChannel);
if (!this.in_array(channel.originalURI.asciiHost, this.get_pref('white_list').split(','))) {
var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
var ip = this.get_ip();
if (this.get_pref('synchronize')) {
var ip2 = ip;
var ip3 = ip;
} else {
var ip2 = this.get_ip();
var ip3 = this.get_ip();
}
if (this.get_pref('xforwarded'))
httpChannel.setRequestHeader("X-FORWARDED-FOR", ip, false);
if (this.get_pref('via'))
httpChannel.setRequestHeader("VIA", ip2, false);
if (this.get_pref('clientip'))
httpChannel.setRequestHeader("CLIENT-IP", ip3, false);
}
}
},
get observerService() {
return Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
},
register: function() {
this.set_pref('ipfuck_enabled', true);
document.getElementById('ipfuck-toolbar-button').className = 'toolbarpanel-menu-iconic ipfuck_enabled';
this.observerService.addObserver(this, "http-on-modify-request", false);
},
unregister: function() {
this.set_pref('ipfuck_enabled', false);
document.getElementById('ipfuck-toolbar-button').className = 'toolbarpanel-menu-iconic ipfuck_disabled';
this.observerService.removeObserver(this, "http-on-modify-request");
},
toggle_state:function() {
if (this.get_pref('ipfuck_enabled')) {
this.unregister();
} else {
this.register();
}
},
get_ip: function() {
if (this.get_pref('mode') == 'list') {
var ips = this.get_pref('ip_list').split(',');
return ips[Math.round(Math.random() * (ips.length - 1))];
} else {
var ip = parseInt(Math.round(Math.random() * parseInt(this.get_pref('ip_high_0') - this.get_pref('ip_low_0'))) + this.get_pref('ip_low_0')) + ".";
ip += parseInt(Math.round(Math.random() * parseInt(this.get_pref('ip_high_1') - this.get_pref('ip_low_1'))) + this.get_pref('ip_low_1')) + ".";
ip += parseInt(Math.round(Math.random() * parseInt(this.get_pref('ip_high_2') - this.get_pref('ip_low_2'))) + this.get_pref('ip_low_2')) + ".";
ip += parseInt(Math.round(Math.random() * parseInt(this.get_pref('ip_high_3') - this.get_pref('ip_low_3'))) + this.get_pref('ip_low_3'));
return ip;
}
},
in_array:function(needle, haystack) {
for (var i = 0; i < haystack.length; i++) {
if (haystack[i] == needle)
return true;
}
return false;
},
get_pref: function(pref_name) {
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
prefs = prefs.getBranch("extensions.ipfuck.");
var type = prefs.getPrefType(pref_name);
if (type == 128)
return prefs.getBoolPref(pref_name);
else if (type == 32)
return prefs.getCharPref(pref_name);
else //type == 64
return prefs.getIntPref(pref_name);
},
set_pref: function(pref_name, value) {
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
prefs = prefs.getBranch("extensions.ipfuck.");
var type = prefs.getPrefType(pref_name);
if (type == 128)
return prefs.setBoolPref(pref_name, value);
else if (type == 32)
return prefs.setCharPref(pref_name, value);
else //type == 64
return prefs.setIntPref(pref_name, value);
},
addbutton: function() {
var toolbar = document.getElementById("ipfuck-toolbar-button");
var browserel = document.getElementById("nav-bar");
if (browserel && !toolbar) {
browserel.insertItem("ipfuck-toolbar-button");
browserel.setAttribute("currentset", browserel.currentSet);
document.persist("nav-bar", "currentset");
}
}
};
window.addEventListener("load", ipfuck.addbutton, false);