Advertisement
Guest User

js

a guest
Nov 8th, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.25 KB | None | 0 0
  1. /***
  2. * Application: Staff's ChatBox.
  3. * Description: Exclusive chat room for your forum staff.
  4. * Version: 2.02112015-jq1.9.1 - (wizard) Nesu, neb Tot.
  5. * Made and Optimizations by JScript - 2015/02/11
  6. * Copyright (c) 2015 JScript <jscriptbrasil at live dot com>
  7. * This work is free. You can redistribute it and/or modify it
  8. * under the terms of the WTFPL, Version 2
  9. */
  10.  
  11. (function (){(function($){jQuery.assyncFor=function(arr,callback){for(var i=0,len=arr.length;i<len;++i){var boundCallback=callback.bind(null,i,arr[i]);setTimeout(boundCallback,i)}return this}}(jQuery));chatStaff={autor:"JScript",version:"2.02112015-jq1.9.1",codename:"(wizard) Nesu, neb Tot.",readLoop:0,readInterval:6000,startingMsg:"Starting, wait...",restartMsg:"Mensagens Reiniciadas!",mentionMsg:"Insert name into Shout",editChatMsg:"Edit",delChatMsg:"Remove",sendError:"Attention!\n\n An error occurred while sending the message, wait 10 seconds and try again!",removeError:"Attention!\n\n An error occurred while removing or editing the message, wait 10 seconds and try again!",uninstallMsg:"Staff's ChatBox - 2.02112015-jq1.9.1, by JScript!\n\nWelcome to the uninstaller for Staff's Chatbox, do you want to continue with the uninstall?",uninstallMsg:"Staff's ChatBox - 2.02112015-jq1.9.1, by JScript!\n\nWelcome to the uninstaller for Staff's Chatbox, do you want to continue with the uninstall?",stopRead:0,postSize:0,founder:undefined,oPost:{user:[],msgs:[]},oBBCode:{patt:[/\[b](.*?)\[\/b]/gi,/\[i](.*?)\[\/i]/gi,/\[u](.*?)\[\/u]/gi,/\[s](.*?)\[\/s]/gi,/\[center](.*?)\[\/center]/gi,/\[size=(.*?)](.*?)\[\/size]/gi,/\[url](.*?)\[\/url]/gi,/\[url=(.*?)](.*?)\[\/url]/gi,/\[color=(.*?)](.*?)\[\/color]/gi,/\[img](.*?)\[\/img]/gi,/\[spoiler](.*?)\[\/spoiler]/gi,/\[spoiler](.*?)\[\/spoiler]/gi,/\[code](.*?)\[\/code]/gi,/\[quote](.*?)\[\/quote]/gi,/\[quote=(.*?)](.*?)\[\/quote]/gi],html:["<strong>$1</strong>","<i>$1</i>","<span style='text-decoration:underline;'>$1</span>","<span style='text-decoration:line-through'>$1</span>","<div style='margin:auto;text-align:center;width:100%'>$1</div>","<span style='font-size: $1;'>$2</span>","<a rel='nofollow' target='_blank' href='$1'>$1</a>","<a rel='nofollow' target='_blank' href='$1'>$2</a>","<span style='color: $1'>$2</span>","<img src='$1' style='max-width:120px;max-height:120px;'/>","<dl class='codebox spoiler'><dt style='cursor: pointer;'>Spoiler:</dt><dd><div class='spoiler_content'>$1</div></dd></dl>","<dl class='codebox spoiler'><dt style='cursor: pointer;'>$1</dt><dd><div class='spoiler_content'>$2</div></dd></dl>","<dl class='codebox'><dt>Código:</dt><dd class='cont_code'><code>$1</code></dd></dl>","<blockquote><div>$1</div></blockquote>","<blockquote><div>$2</div></blockquote>"]},initialize:function(){jQuery(function(){if(_userdata.user_level>0){if(!String.prototype.repeat){String.prototype.repeat=function(count){return(count<1)?"":Array(count+1).join(this.valueOf())}};chatStaff.setupChatbox()}})},setupChatbox:function(){jQuery("head").append("<style type='text/css'>"+".jschatbox_container.row1 {"+" border: 1px solid #dbe4ef;"+"}"+".message.block_wrap {"+" background: none repeat scroll 0 0 #ebfcdf;"+" border: 1px solid #a4cfa4;"+" color: #0e440e;"+" font-size: 12px;"+" line-height: 1.6;"+" padding: 10px;"+"}"+".jschatbox_container .content {"+" border-bottom: 1px solid #f3f3f3 !important;"+" overflow: visible !important;"+" padding: 4px;"+"}"+"#staff-chatbox-shouts {"+" border: 1px solid #d5dde5;"+"}"+"#staff-chatbox-shouts > div {"+" border-bottom: 1px solid #d5dde5;"+" padding: 4px;"+" font-size: 12px;"+" line-height: 135%;"+" min-height: 35px;"+" margin: 0;"+"}"+".altrow_avatar {"+" float: left;"+" padding-right: 4px;"+"}"+".jschat_avatar {"+" background: none repeat scroll 0 0 #fff;"+" border: 1px solid #d5d5d5 !important;"+" box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);"+" height: 30px;"+" padding: 1px;"+" vertical-align: middle;"+" width: 30px;"+"}"+".right.desc {"+" color: #777;"+" float: right;"+" font-size: 12px;"+"}"+".altrow_text .right.desc > img {"+" cursor: pointer;"+"}"+".shout_text {"+" display: block;"+" padding-top: 3px;"+" word-wrap: break-word;"+"}"+".shout_text > img {"+" margin-bottom: 0 !important;"+" vertical-align: middle;"+"}"+"#rt_input {"+" font-family: inherit;"+" font-size: inherit;"+" vertical-align: middle;"+"}"+"#staff-shouts-resizer {"+" background-color: #dbe2ec;"+" cursor: n-resize;"+" height: 6px;"+"}"+".message.error.block_wrap {"+" background-color: #f3e3e6;"+" border-color: #e599aa;"+" color: #80001c;"+" font-size: 12px;"+" line-height: 1.6;"+" padding: 10px;"+"}"+".jschatbox_container .input_text, .jschatbox_container .input_submit {"+" padding: 4px;"+" vertical-align: middle;"+"}"+".jschatbox_container .button2 {"+" cursor: pointer;"+" margin-left: 4px;"+"}"+"#staff-smiles-show {"+" background: none no-repeat scroll center center rgb(255, 255, 255);"+" border: 2px solid #d2d2d2;"+" height: 250px;"+" overflow: auto;"+" padding-top: 6px;"+" position: absolute;"+" width: 225px;"+" z-index: 99999;"+"}"+"#staff-smiles-show > p {"+" margin: 0;"+"}"+"#staff-smiles-show p a {"+" margin-bottom: 14px;"+"}"+"#staff-smiles-show a {"+" display: inline-block;"+" font-size: 18px;"+" margin-bottom: 5px;"+" margin-left: 10px;"+" text-decoration: none;"+"}"+"</style>");jQuery("#f42, a[href^='/f42']").closest("#f42, .main-content, .topiclist.forums, .forumline tr").html("<div class='jschatbox_container row1'>"+" <div class='content row2' id='staff-announcement-row' style='display: none;'>"+" <div class='message block_wrap' id='staff-announcement-text'></div>"+" </div>"+" <div class='content top row1'>"+" <div id='staff-chatbox-shouts' style='top: 0px; height: 225px; min-height: 155px; left: 0px; overflow: auto;'>"+" <p id='shout-row-0' class='row2' style='padding: 8px;'>"+" <span class='altrow_text'>"+" <span class='shout_text' style='font-size: 18px;'><strong>"+chatStaff.startingMsg+"</strong></span>"+" </span>"+" </p>"+" </div>"+" <div id='staff-shouts-resizer' title='Click to resize' oncontextmenu='localStorage.removeItem(&quot;shout_height&quot;);return false;' onmousedown='chatStaff.resize();'></div>"+" <div style='display: none;' class='message error block_wrap' id='staff-shoutbox-error'></div>"+" </div>"+" <div class='content bottom row1'>"+" <div valign='top' class='footer altrow' colspan='2'>"+" <input type='text' id='staff-shout-input' size='75' class='input_text'>"+" <input type='button' onclick='chatStaff.submitShout();' id='staff-submit-button' value='Enviar' class='button2 input_submit'>"+" <input type='button' onclick='document.getElementById(&quot;staff-shout-input&quot;).value = &quot;&quot;;' id='staff-clear-button' value='Limpar' class='button2 input_submit'>"+" <input type='button' onclick='chatStaff.refresh(true);' id='staff-refresh-button' value='Atualizar' class='button2 input_submit'>"+" <input type='button' onclick='chatStaff.showSmile(event);' id='staff-smiles-button' value='smiles' class='button2 input_submit'>"+" <div id='staff-smiles-show' style='display: none;'></div>"+" </div>"+" </div>"+"</div>").closest(".forabg, .table, tbody").find(".topics, .posts, .lastpost, th:not(:first)").remove();if(localStorage.getItem("shout_height")){jQuery("#staff-chatbox-shouts").css("height",localStorage.getItem("shout_height"))}jQuery("#staff-shout-input").keydown(function(e){if(e.keyCode==13&&jQuery("#staff-shout-input").val()!==""){chatStaff.submitShout()}});chatStaff.refresh(true);chatStaff.readLoop=setInterval("chatStaff.refresh()",chatStaff.readInterval);chatStaff.loadSmile()},dataRead:function(callback){jQuery.ajax({url:'/t705-chat_staff_db',cache:false,type:"get",dataType:"text",success:callback})},dataSave:function(failMsg){failMsg=failMsg||"";jQuery.post('/post?p=2645&mode=editpost',{subject:"chat_staff_db",message:JSON.stringify(chatStaff.oPost),edit_reason:"",attach_sig:0,notify:0,post:1}).done(function(){chatStaff.stopRead=0}).fail(function(){if(failMsg.length){alert(failMsg)}chatStaff.stopRead=0})},parseDB:function(response,refresh){refresh=refresh||false;response=/{"user":.+}]}/i.exec(jQuery(response).text());if(response!==null){response=response[0];if(refresh&&chatStaff.postSize==response.length){return false}chatStaff.postSize=response.length;chatStaff.oPost=JSON.parse(response);if(refresh){chatStaff.getMsgs(function(){document.getElementById("staff-chatbox-shouts").scrollTop=999999})}}return true},refresh:function(force){force=force||false;if(!force&&chatStaff.stopRead){return false}chatStaff.dataRead(function(response,status,xhr){if(xhr.status==200){chatStaff.parseDB(response,true)}})},resize:function(){var element=jQuery("#staff-chatbox-shouts");jQuery(document).mousemove(function(event){element.css("height",event.pageY-element.offset().top);document.getElementById("staff-chatbox-shouts").scrollTop=999999}).mouseup(function(){jQuery(document).unbind("mouseup").unbind("mousemove");localStorage.setItem("shout_height",element.css("height"))})},getUser:function(id){var user=chatStaff.oPost.user;for(var i=0,len=user.length;i<len;i++){if(user[i].id===id){return user[i]}}return null},addMsg:function(id,msg,idx){idx=idx||chatStaff.oPost.msgs.length;if(!chatStaff.getUser(id)){chatStaff.oPost.user.push({id:_userdata.user_id,name:_userdata.username,pname:encodeURIComponent(jQuery('a[href="/u'+_userdata.user_id+'"]').slice(-1)[0].innerHTML),avatar:jQuery(_userdata.avatar).attr("src")})}return(msg.length)?chatStaff.oPost.msgs[idx]={id:_userdata.user_id,msg:encodeURIComponent(msg).replace(/%20/g," "),date:Math.round(new Date().getTime()/1000)}:chatStaff.oPost.msgs[idx]=null},delMsg:function(index){return chatStaff.oPost.msgs.splice(index,1)},editMsg:function(index,value){return chatStaff.oPost.msgs[index].msg=encodeURIComponent(value).replace(/%20/g," ")},getMsgs:function(callback){var aMsgLen=chatStaff.oPost.msgs.length-1,user=0,epoch="",posts="";$.assyncFor(chatStaff.oPost.msgs,function(i,value){user=chatStaff.getUser(value.id);epoch=new Date(value.date*1000);posts+='<div id="shout-row-'+i+'" class="row2">'+' <span class="altrow_avatar">'+' <img width="30" height="30" class="jschat_avatar" src="'+user.avatar+'" alt="avatar">'+' </span>'+' <span class="altrow_name">'+' <a title="'+chatStaff.mentionMsg+'" data-store="'+user.name+' " class="at_member" onclick="chatStaff.insertMember(this);return false;" href="#">@</a>&nbsp;'+' <a title="" rel="nofollow" target="_blank" href="/u'+user.id+'" class="hover_url">'+user.pname+'</a>&nbsp;:'+' </span>'+' <span class="altrow_text">'+' <span title="" class="right desc">('+epoch.toLocaleString()+" )&nbsp;";if((user.id==_userdata.user_id)&&(i>0)){posts+=' <img alt="'+chatStaff.editChatMsg+'" onclick="chatStaff.editShout('+i+', 0, this)" src="http://i59.servimg.com/u/f59/18/17/62/92/commen10.png">&nbsp;'+' <img alt="'+chatStaff.delChatMsg+'" onclick="chatStaff.editShout('+i+', 1, this)" src="http://i59.servimg.com/u/f59/18/17/62/92/delete10.png">'}posts+=' </span>'+' <span class="shout_text">'+value.msg+'</span>'+' </span>'+'</div>';if(i==aMsgLen){posts=posts.replace(/%0A|%5Cn/gi,"<br>");posts=decodeURIComponent(posts);var pattLen=chatStaff.oBBCode.patt.length-1,html=chatStaff.oBBCode.html;$.assyncFor(chatStaff.oBBCode.patt,function(i,value){posts=posts.replace(value,html[i]);if(i==pattLen){jQuery("#staff-chatbox-shouts").html(posts);callback()}})}})},submitShout:function(){var user_msg=jQuery("#staff-shout-input").val();if(user_msg==""){return false}chatStaff.stopRead=1;jQuery("#staff-shout-input").val("");switch(user_msg){case"/cls":chatStaff.oPost.user=[];chatStaff.oPost.msgs=[];user_msg=chatStaff.restartMsg;jQuery("#staff-chatbox-shouts").html("");break;case"/stop":jQuery("#staff-chatbox-shouts").css({"opacity":"0.4","-moz-opacity":"0.4","filter":"alpha(opacity=40)"});return false;break;case"/start":chatStaff.stopRead=0;jQuery("#staff-chatbox-shouts").css({"opacity":"1","-moz-opacity":"1","filter":"alpha(opacity=100)"});return false;break;case'/info':return alert(chatStaff.info.Title+'\n\nVersion: '+chatStaff.info.Version+'\nReselase date: '+chatStaff.info.Release+'\nCodeName: '+chatStaff.info.codeName+'\nAuthor: '+chatStaff.info.Author+'\nCopyright: '+chatStaff.info.copyRight);break;case"/uninstall":if(chatStaff.confirm(chatStaff.uninstallMsg)){jQuery("#staff-shoutbox-error").show();return chatStaff.uninstall()}return false;break}chatStaff.dataRead(function(response,status,xhr){if(xhr.status==200){if(chatStaff.oPost.msgs.length){chatStaff.parseDB(response)}if(chatStaff.postSize>14000){chatStaff.oPost.msgs.splice(0,1);chatStaff.oPost.msgs.splice(1,1)}chatStaff.addMsg(_userdata.user_id,user_msg);chatStaff.getMsgs(function(){document.getElementById("staff-chatbox-shouts").scrollTop=999999;chatStaff.dataSave(chatStaff.sendError)})}})},editShout:function(index,mode,vData){chatStaff.stopRead=1;if(mode==0){var td=jQuery(vData).closest(".altrow_text"),width=td.width()-td.find(".right.desc").width(),height=td.height(),sHtml="<span class='shout_text' id='staff-shout-edit'>"+" <textarea id='rt_input' style='width: "+width+"px; height: "+height+"px;'>"+decodeURIComponent(chatStaff.oPost.msgs[index].msg)+"</textarea>"+" <input type='submit' id='rt_submit' class='button2' value='Save' onclick='chatStaff.editShout("+index+", 2, jQuery(\"#rt_input\").val());return false;' style='margin-right: 4px;'>"+" <a title='Cancel' href='javascript:void(0);' onclick='var oEdit = jQuery(\"#staff-shout-edit\");oEdit.next().show();oEdit.prev().show();oEdit.remove();chatStaff.stopRead = 0;return false;'>Cancel</a>"+"</span>";td.find(".right.desc").hide();td.find(".shout_text").hide().before(sHtml);return false}chatStaff.dataRead(function(response,status,xhr){if(xhr.status==200){chatStaff.parseDB(response);(mode==2)?chatStaff.editMsg(index,vData):chatStaff.delMsg(index);chatStaff.getMsgs(function(){chatStaff.dataSave(chatStaff.removeError)})}})},loadSmile:function(){jQuery.ajax({url:"/post?mode=smilies",cache:true,type:"get",dataType:"text",success:function(response,status,xhr){if(xhr.status==200){var htmlSmile=jQuery("<div>"+response+"</div>");htmlSmile.find("#smilies_categ, p, span").remove();htmlSmile.html(htmlSmile.html().replace(/insert_chatboxsmilie/g,"chatStaff.insertSmile"));var oTarget=htmlSmile.find("a"),alen=oTarget.length-1,oThis,patt,regex,pHtml=chatStaff.oBBCode.patt,bHtml=chatStaff.oBBCode.html;$.assyncFor(oTarget,function(i,value){oThis=jQuery(value);patt=/\('(.*?)'\)/i.exec(oThis.attr("href"))[1];regex=new RegExp("(?:^|\\s)"+patt.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\^\$\|]/g,"\\$&")+"(?:\\s|$)","gi");pHtml.push(regex);bHtml.push(oThis.html());if(i==alen){var aSmiles=["&phone;","&starf;","&hearts;","&sung;","&check;","&boxbox;","&copy;","&Jscr;&Sscr;","&block;","&blk34;","&xcirc;","&star;","&clubs;","&cross;","&Fscr;&Mscr;"],sSmiles="<p>";for(var i=0,len=aSmiles.length;i<len;i++){sSmiles+="<a href='#' onclick='chatStaff.insertSmile(\""+aSmiles[i]+"\");return false;'>"+aSmiles[i]+"</a>"}sSmiles+="</p>";jQuery("#staff-smiles-show").html(sSmiles+htmlSmile.find("#simple-wrap, tbody:last").html())}})}}})},showSmile:function(event){var elenPos=jQuery("#staff-smiles-button"),target=jQuery("#staff-smiles-show");target.css({"left":(elenPos.offset().left+elenPos.outerWidth())-target.outerWidth(),"top":elenPos.offset().top-target.outerHeight()});return(target[0].style.display=="none")?target.fadeIn("fast"):target.fadeOut("fast")},insertSmile:function(smile){var id=document.getElementById("rt_input")||document.getElementById("staff-shout-input");id.focus();id.value+=" "+smile+" ";document.getElementById("staff-smiles-show").style.display="none"},insertMember:function(oThis){var id=document.getElementById("staff-shout-input");id.focus();id.value+="@"+oThis.getAttribute("data-store")+" -> "},confirm:function(text){return(confirm(text)==true)?true:false},info:{Title:"Staff's ChatBox.",Version:"2.02112015-jq1.9.1",Release:"2015-05-31",codeName:"sosrio",Author:"JScript - 2015-02-11",copyRight:"(c) 2015 JScript <jscriptbrasil at live dot com>\nThis work is free. You can redistribute it and/or modify it under the terms of the WTFPL, Version 2"},uninstall:function(){var TID=jQuery('a[href*="tid="]').attr("href").split("tid=")[1].split("&")[0],prgBar=parseInt((jQuery("#staff-shoutbox-error").width()/4)/9);document.getElementById("staff-shoutbox-error").innerHTML+="&blk34;".repeat(prgBar);jQuery.ajax({url:"/admin/index.forum?part=general&sub=general&mode=edit&fid=f42&extended_admin=1&tid="+TID,type:"post",data:{fid:"f42",mode:"delete",move:-2,selected_id:"Root",update:"Delete"},dataType:"html",success:function(response,status,xhr){document.getElementById("staff-shoutbox-error").innerHTML+="&blk34;".repeat(prgBar);if(xhr.status==200){var response=jQuery(response);if(response.find(".successbox")!==null){jQuery.ajax({url:"/admin/index.forum?mode=js&part=modules&sub=html&tid="+TID,type:"get",dataType:"html",success:function(response,status,xhr){document.getElementById("staff-shoutbox-error").innerHTML+="&blk34;".repeat(prgBar);if(xhr.status==200){var response=jQuery(response);var JS=response.find("#listJs td:contains('Module: chat_staff_db')").closest("tr").find("td:last input").val();jQuery.ajax({url:"/admin/index.forum?part=modules&sub=html&mode=js&extended_admin=1&tid="+TID,type:"post",data:{conf:[JS],confirm:1,mode:"js_delete"},dataType:"html",success:function(response,status,xhr){document.getElementById("staff-shoutbox-error").innerHTML+="&blk34;".repeat(prgBar);if(xhr.status==200){alert("The staff's chat box has been uninstalled from your forum!");window.location.reload(true)}}})}}})}}}})}};chatStaff.initialize()})();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement