// ==UserScript==
// @name          SoftPedia Ban Cimpoaca
// @author        Ciuly  
// @namespace     http://www.ciuly.com
// @description   Bans any user as being the clone of Cimpoaca and posts the message in the dedicated area 
// @include       http://forum.softpedia.com/index.php?showtopic=*
// ==/UserScript==

var forms, form, uid, uname;

  window.ciuly_post = function(url, data) {
	var request = new XMLHttpRequest();
	request.open("POST", url, false);
	request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	request.send(encodeURI(data));
	alert("Done.");
  };

  window.ciuly_post_bless = function (username, forum, postContent){
	ciuly_post( "http://forum.softpedia.com/index.php?", 
		"st=0"+
		"&act=Post"+
		"&s="+
		"&f="+forum+
		"&auth_key="+ciuly_authKey+
		"&removeattachid=0"+
		"&MAX_FILE_SIZE=0"+
		"&CODE=01"+
		"&attach_post_key="+
		"&TopicTitle="+username+
		"&TopicDesc="+
		"&poll_question="+
		"&ed-0_wysiwyg_used=0"+
		"&editor_ids=ed-0"+
		"&Post="+postContent+
		"&enableem=yes"+
		"&enablesig=yes"+
		"&enabletrack=0"+
		"&iconid=0"+
		"&dosubmit=Bless"
	);
  };

  window.ciuly_BanUser = function(username, userid){
    var reason = "clona cimpoaca";

    // commit the ban
    var req = new XMLHttpRequest();
    var url = "http://forum.softpedia.com/index.php?&act=warn&CODE=dowarn&mid="+userid+"&t=0&st=0&type=add";
    req.open("POST", url, false);
    req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    var data =  "key="+ciuly_authKey+
		"&level=add"+
		"&mod_indef=1"+
		"&mod_value=0"+
		"&mod_unit=d"+
		"&post_indef=1"+
		"&post_value=0"+
		"&post_unit=d"+
		"&susp_value=2147483647"+
		"&susp_unit=d"+
		"&reason="+reason+
		"&subject="+
		"&contactmethod=pm"+
		"&ed-0_wysiwyg_used=0"+
		"&editor_ids[]=ed-0"+
		"&contact=";
        ;
    req.send(encodeURI(data));

    // post in dedicated area
    ciuly_post_bless(username, "267", reason);

    return true;
  }

forms = document.body.all.tags("form");
for (var j=0; j<forms.length; j++){
  form = forms.item(j);
  if ( form.name == "REPLIER" ){
    for (var l=0; l<form.elements.length; l++){
      if (form.elements[l].name == "auth_key"){
        window.ciuly_authKey = form.elements[l].value;
        break;
      }
    }
    break;
  }
}

if (window.ciuly_authKey){
  tables = document.body.all.tags("table");
  for (var i = 0; i<tables.length; i++){
    table = tables.item(i);
    if (table.className == "ipbtable" & table.getAttribute("cellspacing") == "1"){
      var aaa = table.all.tags("a").item(1);
      text = aaa.getAttribute("href");
      var j = text.indexOf("showuser=");
      if (j>-1){
        uid = text.substr(j+9, text.length);
        uname = aaa.innerHTML;

        var t = table.getElementsByTagName("tr").item(0);
        t = t.nextSibling.nextSibling;
        div = t.getElementsByTagName("td").item(1).getElementsByTagName("div").item(0);

        div.insertAdjacentHTML("beforeEnd", 
           "&nbsp;<button class=\"button\" name=\"ban_cimpoaca\" title=\"Ban Cimpoaca\" onclick=\"return ciuly_BanUser('"+uname+"', '"+uid+"')\">Ban Cimpoaca</button>&nbsp;"
  			);
      }
    }
  }
}
