an0ny / Easy Moderation

// ==UserScript==
// @name         Easy Moderation
// @namespace    http://nextgenupdate.com
// @version      0.1
// @description  Thanks to Cammy!
// @author       An0ny
// @match        http://www.nextgenupdate.com/forums/infernoshout.php
// @match        http://www.nextgenupdate.com/forums/infernoshout.php?do=detach
// @grant        none
// ==/UserScript==
var _shoutbox = function(){
 var cam = this;
 cam.head = document.getElementsByTagName("HEAD")[0];
 cam.window = document.getElementById("shoutbox_window");
 cam.frame = document.getElementById("shoutbox_frame");
 cam.old = [];
 cam.selectID = [];
 cam.dis = false;
 
 cam.start = function(){
  if(typeof InfernoShoutboxControl == "object") InfernoShoutboxControl.idletimelimit = -1;
  cam.appendStyles();
  cam.addStyle("html","background:#2A333C !important;","",false);
  cam.addStyle("body","width:100%;overflow:hidden;font-family:Tahoma;font-size:12px;background:rgba(0,0,0,0) !important;","",false);
  cam.IDselect();
 }
 
 cam.appendStyles = function(){
  var link = document.createElement("LINK");
  link.setAttribute("rel","stylesheet");
  link.setAttribute("type","text/css");
  link.setAttribute("href","http://f.cl.ly/items/0g3F0h0E0M281T422Z3I/bootstrap.css");
  cam.head.appendChild(link);
 }
 
 cam.addStyle = function(selector,css,title,box){
  var style = document.createElement("STYLE");
  style.innerHTML = selector+'{'+css+'}';
  style.setAttribute("title",title);
  cam.head.appendChild(style);
  if(box) cam.getStyles();
 }
 
 cam.IDselect = function(){
  cam.window.onmouseover = cam.idOver;
  cam.window.onmouseout = cam.idOut;
  cam.window.onclick = cam.idClick;
 }
 
 cam.IDstop = function(){
  cam.window.onmouseover = '';
  cam.window.onmouseout = '';
  cam.window.onclick = '';
 }
 
 cam.idOver = function(e){
  var canEdit = e.target.ondblclick;
  if(canEdit!==null) canEdit = canEdit.toString();
  if(typeof canEdit=="string" && e.target.innerHTML.indexOf('pm_tab(')!==-1){
   if(cam.old[0]!=="undefined") cam.old = [];
   cam.old.push(e.target.style.boxShadow);
   cam.old.push(e.target.style.background);
   cam.old.push(e.target.style.opacity);
   e.target.style.boxShadow='0 0 5px #15F';
   e.target.style.backgroundColor='rgba(17,85,255,.1)';
   e.target.style.opacity='0.85';
  }
 }
 
 cam.idOut = function(e){
  e.target.style.boxShadow = cam.old[0];
  e.target.style.background = cam.old[1];
  e.target.style.opacity = cam.old[2];
  old = [];
 }
 
 cam.idClick = function(e){
  var ID = e.target.ondblclick;
  if(ID!==null) ID = ID.toString();
  if(typeof ID=="string"){
   e.target.style.boxShadow = cam.old[0];
   e.target.style.background = cam.old[1];
   e.target.style.opacity = cam.old[2];
   old = [];
   ID = ID.split('edit_shout(')[1].split(')')[0];
   cam.openBox(e.target.innerHTML,ID);
   cam.IDstop();
  }
 }
  
 cam.openBox = function(html,sID){
  var light = document.createElement("DIV");
  light.setAttribute("style","background-color:#000;height:100%;width:100%;position:absolute;top:0;left:0;opacity:0.75;");
  light.setAttribute("id","SBlightout");
  light.setAttribute("onclick","shout.closeBox();");
  var temp = document.createElement("DIV");
  temp.innerHTML = html;
  var user = temp.getElementsByTagName("A")[0].innerHTML;
  var uID = 0;
  if(temp.innerHTML.indexOf('pm_tab(')!==-1) uID = temp.innerHTML.split('pm_tab(\'pm_')[1].split('\'')[0];
  cam.getShout(sID);
  var box = document.createElement("DIV");
  box.setAttribute("style","position:absolute;top:15%;left:10%;height:55%;width:75%;font-weight:bold;overflow:auto;");
  box.setAttribute("id","SBbox");
  box.setAttribute("class","well");
  box.setAttribute("onclick","");
  box.innerHTML='<a href="#" class="close" onclick="shout.closeBox();return false">&times;</a><div class="input-append input-prepend"><span class="add-on" id="SBeditShoutID">0</span><input style="width:80%" id="SBeditShout" type="text" value="Loading..." onkeydown="shout.updateCount();if(event.keyCode==13) shout.editShout('+sID+',false)" onkeyup="shout.updateCount()"><button class="btn" type="button" onclick="shout.editShout('+sID+',false)">Edit</button></div><hr>\
<ul class="thumbnails" style="text-align:center;">\
<li class="span3">\
<div class="thumbnail">\
  <h5><a href="member.php?u='+uID+'" target="_blank">'+user+'</a></h5>\
  <p><div class="btn-group"><input type="button" class="btn btn-small" value="Edit Shout" onclick="shout.editShout('+sID+',false)" disabled="disabled">\
	<input type="button" class="btn btn-small" value="Delete Shout" onclick="shout.editShout('+sID+',true)"></div><br>\
	<div class="btn-group"><input type="button" class="btn btn-small" onclick="shout.pruneUser('+uID+')" value="Prune User">\
	<input type="button" value="Temp Ban User" class="btn btn-small" onclick="shout.tbanUser('+uID+')"></div></p>\
</div>\
</li>\
<li class="span3">\
<div class="thumbnail">\
  <h5><a href="member.php?u='+uID+'" target="_blank">'+user+'</a></h5>\
  <p><div class="btn-group"><input type="button" value="Ban User" class="btn btn-small" onclick="shout.banUser('+uID+',false)">\
	<input type="button" class="btn btn-small" value="Unban User" onclick="shout.banUser('+uID+',true)"></div><br>\
	<div class="btn-group"><input type="button" value="Silence User" class="btn btn-small" onclick="shout.silenceUser('+uID+',false)">\
	<input type="button" class="btn btn-small" value="Unsilence User" onclick="shout.silenceUser('+uID+',true)"></div></p>\
</div>\
</li>\
<li class="span5 pull-right" style="text-align:left;">\
<div class="thumbnail" style="height:134px;">\
  <img src="http://www.nextgenupdate.com/forums/avatars/'+uID+'.gif" style="border:2px solid #bbbbbb;margin-right:4px;height:130px;max-width:130px;" align="left">\
  <a href="member.php?u='+uID+'" target="_blank">'+user+'</a> \
  <p class="pull-right"><a rel="nofollow" href="http://www.nextgenupdate.com/forums/moderator.php?do=useroptions&u='+uID+'"><img src="http://www.nextgenupdate.com/forums/images/buttons/edit_40b.png" alt="Edit Profile" title="Edit Profile"></a>\
  <a href="search.php?q='+uID+'&showposts=0&s=&securitytoken='+SECURITYTOKEN+'&do=process&contenttype=vBForum_Post&forumchoice%5B%5D=52&childforums=1&exactname=1"><img src="http://f.cl.ly/items/3S1q0Y2K3o3t0j402d0U/custom.png"></a>\
  <a href="http://www.nextgenupdate.com/forums/search.php?do=finduser&userid='+uID+'&contenttype=vBForum_Post&showposts=1" alt="Seach AE for user"><img src="http://www.nextgenupdate.com/forums/images/site_icons/forum.png"></a></p>\
  <div id="uInfo"><p>'+(cam.dis?'<ul><li>User Info Disabled.</li><li>User ID: '+uID+'</li><li>Shout ID: '+sID+'</li></ul>':'<ul><li>User ID: '+uID+'</li><li>Shout ID: '+sID+'</li></ul>')+'</p></div>\
</div>\
</li>\
</ul>';
  if(uID!==0){
   document.body.appendChild(light);
   document.body.appendChild(box);
  }
 }
 
 cam.updateCount = function(){
  document.getElementById("SBeditShoutID").innerHTML = document.getElementById("SBeditShout").innerHTML.split("").length;
 }
 
 cam.getShout = function(sID){
  var get = new XMLHttpRequest();
  get.onreadystatechange = function(){
   if(get.readyState==4 && get.status==200){
    var data = get.responseXML.documentElement;
	data = data.getElementsByTagName("data")[0].firstChild.data;
	data = data.split("<<~~PARSE_^_BREAKER~~>>")[0];
	document.getElementById("SBeditShout").value = data;
	document.getElementById("SBeditShoutID").innerHTML = data.split("").length;
   }
  }
  get.open("POST","infernoshout.php",true);
  get.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  get.send("do=editshout&shoutid="+sID+"&s=&securitytoken="+SECURITYTOKEN);
 }
 
 cam.closeBox = function(){
  document.body.removeChild(document.getElementById("SBlightout"));
  document.body.removeChild(document.getElementById("SBbox"));
  cam.IDselect();
 }
 
 cam.numberWithCommas = function(rp){
  return rp.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
 }
 
 cam.editShout = function(id,del){
  var edit = new XMLHttpRequest();
  var message = document.getElementById("SBeditShout").value;
  if(message!==null || del){
   edit.open("POST","infernoshout.php",true);
   edit.setRequestHeader("Content-type","application/x-www-form-urlencoded");
   edit.send("do=doeditshout&shoutid="+id+"&shout="+message+"&delete="+(del?"1":"0")+"&s=&securitytoken="+SECURITYTOKEN);
  }
  cam.closeBox();
 }
 
 cam.pruneUser = function(id){
  var post = new XMLHttpRequest();
  post.onreadystatechange = function(){
   if(post.readyState==4 && post.status==200) cam.closeBox();
  }
  post.open("POST","infernoshout.php",true);
  post.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  post.send("do=shout&message=/prune "+id+"&s=&securitytoken="+SECURITYTOKEN);
 }
 
 cam.tbanUser = function(id){
  var time = prompt("For how long?","24");
  var post = new XMLHttpRequest();
  post.onreadystatechange = function(){
   if(post.readyState==4 && post.status==200) cam.closeBox();
  }
  post.open("POST","infernoshout.php",true);
  post.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  post.send("do=shout&message=/tban "+id+";"+time+"&s=&securitytoken="+SECURITYTOKEN);
 }
 
 cam.banUser = function(id,un){
  var post = new XMLHttpRequest();
  post.onreadystatechange = function(){
   if(post.readyState==4 && post.status==200) cam.closeBox();
  }
  post.open("POST","infernoshout.php",true);
  post.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  post.send("do=shout&message=/"+(un?"unban":"ban")+" "+id+"&s=&securitytoken="+SECURITYTOKEN);
 }
 
 cam.silenceUser = function(id,un){
  var post = new XMLHttpRequest();
  post.onreadystatechange = function(){
   if(post.readyState==4 && post.status==200) cam.closeBox();
  }
  post.open("POST","infernoshout.php",true);
  post.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  post.send("do=shout&message=/"+(un?"unsilence":"silence")+" "+id+"&s=&securitytoken="+SECURITYTOKEN);
 }
}

var shout = new _shoutbox;
shout.start();