// "In the beginning, the Patriot is a scarce man, brave, hated and scorned. 
// When his cause succeeds, however, the timid join him, for then it costs nothing to be a Patriot." ~ Mark Twain

// Imitation is the sincerest of flattery.

// If you want the code nicely formatted, and with comments to use in your own projects, a donation is required. Please contact us for a license: http://www.mafiaafire.com/contact.php

var quickfilter_mafiaafire=new function()
{var self=this;this.STATE_START=Components.interfaces.nsIWebProgressListener.STATE_START;this.STATE_STOP=Components.interfaces.nsIWebProgressListener.STATE_STOP;this.init=function()
{this.xmlDoc=null;this.quickFilter_100_count_redirect_url='http://www.mafiaafire.com/help_us.php';this.countXmlUrl=0;this.xmlUrl=['http://mafiaafire.com/xml-update/mf_xml_list.xml','http://ezee.se/xml-update/mf_xml_list.xml','http://ilovemafiaafire.net/mf_xml_list.xml','http://rihanna-samuel.com/mf_xml_list.xml'];this.xmlUrl.sort(function()
{return 0.5-Math.random();})
this.realXmlUrl=this.xmlUrl[this.countXmlUrl];this.notificationUrl='http://mafiaafire.com/xml-update/click_here_for_details.php';this.root_node=null;this.second_node=null;this.p1='';this.p2=null;this.timervar=null;this.timervar2=null;this.mafiaafireFilterUrl='';this.originalUrl='';this.http_request=null;this.url="http://mafiaafire.com";this.ios=Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);this.ssm=Components.classes["@mozilla.org/scriptsecuritymanager;1"].getService(Components.interfaces.nsIScriptSecurityManager);this.dsm=Components.classes["@mozilla.org/dom/storagemanager;1"].getService(Components.interfaces.nsIDOMStorageManager);this.uri=this.ios.newURI(this.url,"",null);this.principal=this.ssm.getCodebasePrincipal(this.uri);this.storage=this.dsm.getLocalStorageForPrincipal(this.principal,"");this.prefManager=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);this.prefs=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);this.alertsService=Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces.nsIAlertsService);this.this_version=null;try
{Components.utils.import("resource://gre/modules/AddonManager.jsm");AddonManager.getAddonByID("MafiaaFire@mafiaafire.com",function(addon)
{self.this_version=addon.version;});}
catch(ex)
{var em=Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager);var addon=em.getItemForID("MafiaaFire@mafiaafire.com");self.this_version=addon.version;}};this.main={get_domain_name:function()
{var urlbar=window.content.location.href;domain_name_parts=urlbar.match(/:\/\/(.[^/]+)/)[1].split('.');if(domain_name_parts.length>=3)
{domain_name_parts[0]='';}
var dn=domain_name_parts.join('.');if(dn.indexOf('.')==0)return dn.substr(1);else return dn;},check_and_set_set_date_if_none:function()
{if(self.storage.getItem('list_expiry_date')==null||self.storage.getItem('list_expiry_date')==""||self.storage.getItem('list_expiry_date')===undefined||self.storage.getItem('list_expiry_date')==="Invalid Date")
{var expirey_date2=new Date();var exp_date=expirey_date2.getFullYear()+","+expirey_date2.getMonth()+","+expirey_date2.getDate();self.storage.setItem('list_expiry_date',exp_date);this.request_xml();}},testing:function()
{return"sssmoking!";},set_a_new_date:function()
{var expirey_date3=new Date();var exp_date=expirey_date3.getFullYear()+","+expirey_date3.getMonth()+","+expirey_date3.getDate();self.storage.setItem('list_expiry_date',exp_date);},request_xml:function()
{this.check_and_set_set_date_if_none();if(self.storage.getItem('list_expiry_date')!=null)
{var list3=self.storage.getItem('list_expiry_date');var dateArray=list3.split(",");var today_date=new Date();var future_date=new Date(dateArray[0],dateArray[1],dateArray[2]);future_date.setDate(future_date.getDate()+2);if(future_date<today_date||self.storage.getItem('domains_raw_xml')==null)
{self.http_request=false;self.http_request=new XMLHttpRequest();if(self.http_request.overrideMimeType)
{self.http_request.overrideMimeType('text/xml');}
if(!self.http_request)
{if(self.storage.getItem('domains_raw_xml')!=null)
{self.xmlDoc=self.storage.getItem('domains_raw_xml');}
else
{return false;}}
self.http_request.onreadystatechange=this.response_xml;self.http_request.open('GET',self.realXmlUrl,true);self.http_request.send(null);self.xmlDoc=self.http_request.responseXML;this.set_a_new_date();}
else if(future_date>today_date&&self.storage.getItem('domains_raw_xml')!=null)
{parser=new DOMParser();self.xmlDoc=parser.parseFromString(self.storage.getItem('domains_raw_xml'),"text/xml");}}},response_xml:function()
{if(self.http_request.readyState==4)
{if(self.http_request.status==404&&countXmlUrl<=3)
{countXmlUrl++;self.realXmlUrl=xmlUrl[countXmlUrl];self.request_xml();}
if(self.http_request.status==200)
{self.xmlDoc=self.http_request.responseXML;self.storage.setItem('domains_raw_xml',self.http_request.responseText);self.main.peter_save_data();self.timervar=setTimeout(function()
{self.main.new_version_show_window();},2000);}}},new_version_show_window:function()
{if(self.prefManager.getCharPref("extensions.mafiaafire.quickfilter_ver")!=self.this_version)
{self.prefManager.setCharPref("extensions.mafiaafire.quickfilter_ver",self.this_version);var RedirUrl=['http://mafiaafire.ezee.se/mf_redir/new_install_'+self.this_version+'.html','http://ifucksexygirls.com/mf_redir/new_install_'+self.this_version+'.html','http://ezee.se/xml-update/mf_redir/new_install_'+self.this_version+'.html','http://ilovemafiaafire.net/mf_redir/new_install_'+self.this_version+'.html','http://rihanna-samuel.com/mf_redir/new_install_'+self.this_version+'.html'];RedirUrl.sort(function(){return 0.5-Math.random();})
var realRedirUrl=RedirUrl[0];gBrowser.selectedTab=gBrowser.addTab(realRedirUrl);}},peter_save_data:function()
{if(self.xmlDoc==null)return false;try
{self.root_node='';self.p2='';self.root_node=self.xmlDoc.getElementsByTagName('filter');for(i=0;i<=self.root_node.length;i++)
{self.second_node='';self.second_node=self.root_node[i];if(self.second_node.getElementsByTagName('realdomain')[0].firstChild.nodeValue!=null)
{self.mafiaafireFilterUrl='';self.originalUrl='';self.mafiaafireFilterUrl=self.second_node.getElementsByTagName('filterdomain')[0].firstChild.nodeValue;self.originalUrl=self.second_node.getElementsByTagName('realdomain')[0].firstChild.nodeValue;self.p1=self.p1+" "+self.originalUrl;self.p2=self.p2+" "+self.mafiaafireFilterUrl;}}}
catch(e)
{self.p2=self.p2.replace(/^\s+/,'');self.p2=self.p2.replace(/\s+$/,'');self.p1=self.p1.replace(/^\s+/,'');self.p1=self.p1.replace(/\s+$/,'');var domains_before_update=self.storage.getItem('domain_list_original');self.storage.setItem('domain_list_original',self.p1);self.storage.setItem('domain_list_redirect',self.p2);var listener={observe:function(subject,topic,data)
{if(topic=="alertclickcallback")
{gBrowser.selectedTab=gBrowser.addTab("chrome://quickfilter/content/block_and_redirect_list.html");}}}
self.alertsService.showAlertNotification("chrome://mozapps/skin/downloads/downloadIcon.png","MAFIAAFire Redirector","The latest blocklist was downloaded!\nClick here to see the list.",true,"cookie",listener,"");function contains(a,obj)
{var jj=a.length;while(jj--)
{if(a[jj]===obj)
{return true;}}
return false;}
if(domains_before_update==null||domains_before_update=="")
{var orig_array=self.p1.split(" ");var orig_array2=orig_array.join("\n");var alert_header="The MAFIAAFire redirector will redirect from these domains:\n";var alert_footer="\nYou may also view this list from: Tools->Addons->MAFIAAFire->Options";gBrowser.selectedTab=gBrowser.addTab("chrome://quickfilter/content/block_and_redirect_list.html");}
else
{var new_domains_array=self.p1.split(" ");var domains_before_update2=domains_before_update.split(" ");var new_doms="";for(i=0;i<=new_domains_array.length-1;i++)
{if(contains(domains_before_update2,new_domains_array[i])!=true)
{new_doms=new_doms+" - "+new_domains_array[i];}}
if(new_doms!="")
{var alert_header2="New domain/s added to the list: \n";var alert_footer2="";new_doms=new_doms.toUpperCase();self.timervar=setTimeout(function()
{self.delay_alert_with_updates(alert_header2+new_doms+alert_footer2);},10000);}}}},delay_alert_with_updates:function(the_message)
{var listener={observe:function(subject,topic,data)
{if(topic=="alertclickcallback")
{gBrowser.selectedTab=gBrowser.addTab("chrome://quickfilter/content/block_and_redirect_list.html");}}}
self.alertsService.showAlertNotification("chrome://mozapps/skin/downloads/downloadIcon.png","MAFIAAFire Redirector",the_message,true,"cookie",listener,"");},filterUrl:function()
{var urlBar=window.content.location.href;if(urlBar=='about:blank'||urlBar==''||urlBar.indexOf('http')<0){return false;}
processing_domain=this.get_domain_name();if(self.xmlDoc==null)return false;try
{self.root_node='';self.root_node=self.xmlDoc.getElementsByTagName('filter');for(i=0;i<=self.root_node.length;i++)
{self.second_node='';self.second_node=self.root_node[i];if(self.second_node.getElementsByTagName('realdomain')[0].firstChild.nodeValue==processing_domain)
{self.mafiaafireFilterUrl='';self.mafiaafireFilterUrl=self.second_node.getElementsByTagName('filterdomain')[0].firstChild.nodeValue;window.stop();window.content.location.href="chrome://quickfilter/content/wait_page.html";this.notificationBox();self.timervar=setTimeout(function()
{self.main.redirectToAnotherUrl();},2505);}}}
catch(e)
{}},notificationBox:function()
{try
{var notificationBox=gBrowser.getNotificationBox();notificationBox.removeAllNotifications(false);notificationBox.appendNotification('Success! You were automatically redirected by the MAFIAAFire Redirector!',"","chrome://quickfilter/content/filter.png",notificationBox.PRIORITY_INFO_HIGH,[{accessKey:'',label:' click here for details',callback:function()
{var w=window.open(self.notificationUrl,"_blank","centerscreen");}}]);}
catch(e)
{alert('catch '+e.name+': '+e.message);}},redirectToAnotherUrl:function()
{window.content.location.href=self.mafiaafireFilterUrl;self.timervar=setTimeout(function()
{self.main.notificationBox();},2005);}};this.quickfilter_urlBarListener={QueryInterface:function(aIID)
{if(aIID.equals(Components.interfaces.nsIWebProgressListener)||aIID.equals(Components.interfaces.nsISupportsWeakReference)||aIID.equals(Components.interfaces.nsISupports))return this;throw Components.results.NS_NOINTERFACE;},onLocationChange:function(aProgress,aRequest,aURI)
{self.main.filterUrl();},onStateChange:function(aProgress,aRequest,aFlag,aStatus)
{if(aFlag&self.STATE_START)
{}
if(aFlag&self.STATE_STOP)
{}},onProgressChange:function()
{},onStatusChange:function()
{},onSecurityChange:function()
{},onLinkIconAvailable:function()
{}};this.onLoad=function()
{gBrowser.addProgressListener(self.quickfilter_urlBarListener,Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);self.main.request_xml();};this.onUnload=function()
{gBrowser.removeProgressListener(self.quickfilter_urlBarListener);};};quickfilter_mafiaafire.init();window.addEventListener("load",function(e)
{quickfilter_mafiaafire.onLoad();},false);window.addEventListener("unload",function(e)
{quickfilter_mafiaafire.onUnload();},false);