Notizie: se possiedi un dispositivo Android, prova Firefox per Android, un browser scattante e dinamico per navigare in ambiente mobile.

Autore Topic: Estensione Safari: cosa fa il codice?  (Letto 729 volte)

0 Utenti e 1 Visitatore stanno visualizzando questo topic.

Offline LolloMazzy

  • Post: 7
Estensione Safari: cosa fa il codice?
« il: 21 Gennaio 2015 18:04:06 »
Ho questo componente aggiuntivo col nome di IPFuck. Mi potete aiutare a studiare il suo codice?

Codice: [Seleziona]
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);
« Ultima modifica: 22 Gennaio 2015 09:15:23 da flod »

Offline flod

  • Amministratore
  • Post: 15057
    • http://www.flod.org
Re: Estensione Safari: cosa fa il codice?
« Risposta #1 il: 22 Gennaio 2015 09:17:17 »
Cosa c'entra Safari con un forum sul software Mozilla? Se effettivamente è un'estensione per Safari, non c'entra nulla con questo forum e devo chiudere.

Avendo già chiuso una discussione in Altro, ho l'impressione che tu abbia bisogno di un forum in cui si discute esclusivamente di programmazione. E questo non è il forum adatto.

0 Utenti e 1 Visitatore stanno visualizzando questo topic.