I shall go first:
"// ==Userscript==
// @name dAmnWelcome
// @namespace bentomlin
// @description Custom script for setting up welcomes for chatrooms
// @include
http://chat.deviantart.com/chat/*// ==/Userscript==
setTimeout(function() {
with(unsafeWindow) {
var script_NAME = "dAmnWelcome";
var script_VERSION = "0.2";
//change this if you already have a /welcome command for some reason, or you just want it called something else
commandname="welcome";
//Step 1. type /welcome on
//Step 2. type /welcome on User
//Step 3. type /welcome on Priv
//Step 4. write some welcomes...
//@channel will insert the channel, @user will input the users name and @privclass will add their privclass in, @gpc will insert their gpc. obvious really.
//To Welcome ALL Privclasses.. where it says pc: you'd put pc:"All"
//you have no need to edit below this line... -------------------------------------------------------------------------------------------------
//you have no need to edit below this line... -------------------------------------------------------------------------------------------------
function set(name,value){GM_setValue(name,value);}
function get(name,def){return GM_getValue(name,def);}
function pwelcome(chan,pc,msg){this.chan=chan;this.pc=pc;this.msg=msg;}
function uwelcome(chan,pc,msg){this.chan=chan;this.name=name;this.msg=msg;}
privwelcomes=new Array();
userwelcomes=new Array();
function say(msg,channel){dAmnChats["chat:"+channel].Send('msg','main',msg);}
function log(msg){dAmn_addTimedDiv( dAmnChats[dAmnChatTab_active].channels.main.info_el, "dAmnWelcome", msg );}
function gname(name){string="chat:"+name;return string;}
function dname(name){string=name.substring(5);return string;}
function makeResultBox(icon,iconWidth,result){
var channel = dAmnChats[dAmnChatTab_active].channels.main;
var o = dAmn_MakeDiv( "userinfo-outer" )
var i = dAmn_AddDiv( o, "userinfo-inner" );
var u = dAmn_AddDiv( i, "userinfo alt0 damncri-member" );
var t = this;
dAmnChat_AddImgBox( u, "damncr-close", 'close', 'close', function(el){ dAmn_DeleteSelf(el); t.scroll_once = true; dAmn_InvalidateLayout(); }, o );
var m = dAmn_AddDiv( u, "damncri-member" );
if(parseInt(iconWidth)!=0)
dAmn_AddDiv( m, 'aside-left avatar alt1', icon );
var r = dAmn_AddDiv( m, 'bodyarea alt1-left-border' );
r.style.borderWidth="0 0 0 "+iconWidth;
var b = dAmn_AddDiv( r, 'b read' );
dAmn_AddNewEl( b, 'SPAN', null, result );
channel.addDiv( o, null, 0 );
}
var dAx=false;
if(dAmn_Client_Agent.match(/dAx/)){dAx=true;}
block=new Array("devart","mnadmin","help","h3lp","iRPG","photographers","trivia");
function sayprivate(results){makeResultBox('
', "24px", '
deviantART Welcome System:Developed by =
bentomlin'+results);}
function dname(name){return name.substring(5);}
function inArray(x,array){for(var i = 0; i < array.length; i++){if(array[i]==x)return true;} return false;}
function arg(str){ msg=str.split(" "); return msg;}
function argE(str,num){
find=arg(str);
num=num-1;
pos=str.indexOf(find[num]);
last=str.substring(pos);
array=new Array();
for(i=0;i
array.push(last);
delete find, num, pos, last, num;
return array;
}
var boollist = new Array("Priv","User","Welcome");var strlist=new Array("PrivOnes","UserOnes");
for(i in boollist){ window[boollist[i]]=get(boollist[i]); if(typeof window[boollist[i]]=="undefined"){set(boollist[i],false);}}
for(i in strlist){ window[strlist[i]]=get(strlist[i]); if(typeof window[strlist[i]]=="undefined"){window[strlist[i]]=set(strlist[i],"");}}
if(UserOnes!=""){UserArray=UserOnes.split("#2409");} else {var UserArray = new Array();}
if(PrivOnes!=""){PrivArray=PrivOnes.split("#2409");} else {var PrivArray = new Array();}
privwelcomes=new Array();
userwelcomes=new Array();
for(var i=0; i
for(var i=0; i
function addmybutton(target){
bool=window.confirm("Do you want to create a Privclass welcome (OK) or a specific User welcome (cancel)?");
if(bool){type="priv";}
else{type="user";}
switch(type){
case 'user':
chan=window.prompt("Next, Enter the channel name eg: Botdom");
if(chan==null){log("dAmnWelcome: You have cancelled welcome creation"); return;}
name=window.prompt("Now enter the username that the welcome is for");
if(name==null){log("dAmnWelcome: You have cancelled welcome creation"); return;}
msg=window.prompt("Finally, enter the welcome message that you would like to send them");
if(msg==null){log("dAmnWelcome: You have cancelled welcome creation"); return;}
t="/welcome create type:"+type+" chan:"+chan+" name:"+name+" msg:{"+msg+"}";
break;
case 'priv':
chan=window.prompt("Next, Enter the channel name eg: Botdom");
if(chan==null){log("dAmnWelcome: You have cancelled welcome creation"); return;}
privclass=window.prompt("Now enter the privclass name that the welcome is for, or All for all privclasses");
if(privclass==null){log("dAmnWelcome: You have cancelled welcome creation"); return;}
msg=window.prompt("Finally, enter the welcome message that you would like to send them");
if(msg==null){log("dAmnWelcome: You have cancelled welcome creation"); return;}
t="/welcome create type:"+type+" chan:"+chan+" pc:"+privclass+" msg:{"+msg+"}";
break;
}
target.value=t
}
temporary = function(){addmybutton(dAmnChats[dAmnChatTab_active].channels.main.input.chatinput_el);}
var t=document.getElementById('chatroomsettingslink');
var buttonwelcome=document.createElement('a');
buttonwelcome.onclick=temporary;
buttonwelcome.innerHTML='New Welcome';
buttonwelcome.style.cursor='pointer';
var buttonSpacer=document.createElement('span');buttonSpacer.appendChild(document.createTextNode(' | '));buttonSpacer.setAttribute("id","welcomespacer");t.parentNode.insertBefore(buttonSpacer,t);t.parentNode.insertBefore(buttonwelcome,buttonSpacer);
function use(v,s){
if(v.toLowerCase()=="user"){v="User";}
if(v.toLowerCase()=="priv"||v.toLowerCase()=="privclass"){v="Priv";}
if(v!="Priv" && v!="User" && v!="Welcome"){ log("Error in command"); return;}
else if(s!="on"&&s!="off"){log("Error in command");return;}
else{
switch(s){
case "on":
window[v]=true;
set(v, true);
break;
case "off":
window[v]=false;
set(v, false);
break;
}
if(v!="Welcome"){log("dAmnWelcome: "+v+" welcomes are "+s);}
else{log("dAmnWelcome: Welcomes are switched "+s);}
}
}
function add(text){
args=text.substring(0,text.indexOf("msg")).split(" ");
msg=text.match(/msg:{(.*?)}/);
msg=msg[1];
for(i in args){ args[i]=args[i].split(":"); if(args[i][0]!="msg"){window[args[i][0]]=args[i][1];} }
if(!type){log("Specify all of the following: type,chan,name/pc,msg");}
switch(type){
case 'user':
if(!name||!chan){log("Specify all of the following: type,chan,name/pc,msg");}
userwelcomes.push(new uwelcome(chan,name,msg));
UserArray.push("new uwelcome(\""+chan+"\",\""+name+"\",\""+msg+"\")");
set("UserOnes",UserArray.join("#2409"));
log("User Welcome has been added");
break;
case 'priv':
case 'privclass':
if(!pc||!chan||!msg){log("Specify all of the following: type,chan,name/pc,msg");}
privwelcomes.push(new pwelcome(chan,pc,msg));
PrivArray.push("new pwelcome(\""+chan+"\",\""+pc+"\",\""+msg+"\")");
set("PrivOnes",PrivArray.join("#2409"));
log("Privclass Welcome has been added");
break;
}
}
function remove(text){
args=arg(text);
if(!args[1]||!args[0]){ log("Usage: /"+commandname+" remove [user, privclass] [number of welcome to remove]"); return; }
switch(args[0]){
case 'user':
userwelcomes.splice(args[1]-1,1);
UserArray.splice(args[1]-1,1);
set("UserOnes",UserArray.join("#2409"));
log("User welcome "+args[1]+" has been deleted");
break;
case 'priv':
case 'privclass':
privwelcomes.splice(args[1]-1,1);
PrivArray.splice(args[1]-1,1);
set("PrivOnes",PrivArray.join("#2409"));
log("Privclass welcome "+args[1]+" has been deleted");
break;
}
}
function list(){
text = "
";
text += "User Welcomes:\n"
if(userwelcomes.length==0){ text+="No user welcomes set";}
else{
for(var list in userwelcomes){
Chan = userwelcomes[list].chan;
Name = userwelcomes[list].name;
Msg = userwelcomes[list].msg;
text += "- #"+Chan+": - "+Name+" => "+Msg+"
";
}
}
text += "
\nPrivclass Welcomes:\n"
if(privwelcomes.length==0){ text+="No privclass welcomes set";}
else{
for(var list in privwelcomes){
Chan = privwelcomes[list].chan;
PC = privwelcomes[list].pc;
Msg = privwelcomes[list].msg;
text += "- #"+Chan+": - "+PC+" => "+Msg+"
";
}
}
text +="
";
sayprivate(text);
}
function stats(){
text="Welcomes are "+Welcome+"
User Welcomes are "+User+"
Priv Welcomes are "+Priv;
while(text.match("true")||text.match("false")){
text=text.replace("true","on").replace("false","off");}
sayprivate(text);
}
function help(){
text="Help:
";
text+="- To enable user and privclass welcomes, type /welcome on, /welcome on User and then /welcome on Privclass
";
text+="- To disable user and privclass welcomes, type /welcome off, /welcome off User and then /welcome off Privclass
";
text+="- To check what is enabled, type /welcome status
";
text+="- To create new welcomes, click the new welcome button and follow instructions
";
text+="- To list welcomes, type /welcome list
";
text+="- To delete welcomes, type /welcome delete followed by either User or Privclass and then the welcome's number, as specified on /welcome list
";
text+="
";
text+="
";
text+="Commands:
";
text+="- /welcome Add / Create - don't use this manually, use the button
";
text+="- /welcome List
";
text+="- /welcome Status
";
text+="- /welcome on [user, privclass] / off [user, privclass]
";
text+="- /welcome Del / Delete / Remove [user, privclass] [number of welcome]
";
text+="- /welcome Help
";
text+="
";
sayprivate(text);
}
function processcommand(command){
argsE=argE(command,2);
args=arg(command);
switch(args[0].toLowerCase()){
case 'list':
list();
break;
case 'status':
stats();
break;
case 'help':
help();
break;
case 'add':
case 'create':
add(argsE[1]);
break;
case 'remove':
case 'del':
case 'delete':
remove(argsE[1]);
break;
case 'on':
case 'off':
if(args[1]){use(args[1],args[0]);}
else{use("Welcome",args[0]);}
break;
default:
log("dAmnWelcome: That's not a valid command, type /welcome help");
break;
}
}
dAmnChanChat.prototype.dAmnWelcome_Init = dAmnChanChat.prototype.Init;
dAmnChanChat.prototype.Init = function( cr, name, parent_el )
{
this.dAmnWelcome_Init( cr, name, parent_el );
var cie=this.input;
cie.cmds[commandname]=[0,''];
}
dAmnChatInput_onKey_damnwelcome=dAmnChatInput_onKey;
dAmnChatInput_onKey = function (e,kc,force){
var el = this.chatinput_el;
if( kc == 13 && ( force || !this.multiline || e.shiftKey || e.ctrlKey ) ){
var input = el.value;var args = /^\/(\S*)\s*(.*)$/i.exec(input);
if(args){
var cmd=args[1];
var param=args[2];
var did=false;
if(cmd){
switch(cmd){
case commandname:
did=true;
if(args&&args!=' '&&args!=' '){ processcommand(args[2]); }
else this.cr.channels.main.onErrorEvent( 'syntax', "Usage: /"+commandname+" [on [User, Priv], off [User, Priv], delete [User, Priv] [number], help, list, status]" );
break;
}
if(did){
if(el.value){
el.value='';
el.focus();
}
}
}
}
}
if(!did){return this.onKey_damnwelcome(e,kc,force)?true:false;}
else return false;
}
dAmnChatInput.prototype.onKey = dAmnChatInput_onKey;
dAmnChatInput.prototype.onKey_damnwelcome = dAmnChatInput_onKey_damnwelcome;
dAmnChat_onData_damnwelcome = dAmnChat_onData;
dAmnChat_onData = function ( pkt ){
this.onData_damnwelcome(pkt);
roomname=dname(this.ns);
if( pkt.param == this.ns ){
switch( pkt.cmd ){
case 'recv':
var rp = dAmn_ParsePacket(pkt.body);
var pc = pkt.body.split('\n');
switch (rp.cmd) {
case "join":
check=dname(this.ns);
if(!Welcome||inArray(check,block)){ return; }
if(User){
for(var set in userwelcomes){
Chan = userwelcomes[set].chan; Chan=gname(Chan);
Name = userwelcomes[set].name;
Msg = userwelcomes[set].msg;
if(this.ns==Chan && rp.param.toLowerCase()==Name.toLowerCase()){
privclass = pc[3].substring(3);
gpc = pc[8].substring(4);
while(Msg.match("@user")||Msg.match("@privclass")||Msg.match("@channel")||Msg.match("@gpc")){
Msg = Msg.replace(/@user/,rp.param);
Msg = Msg.replace(/@channel/,"#"+dname(this.ns));
Msg = Msg.replace(/@privclass/,privclass);
Msg = Msg.replace(/@gpc/,gpc);}
say(Msg,dname(Chan));
return;
}
}
}
if(Priv){
for(var list in privwelcomes){
Chan = privwelcomes[list].chan; Chan=gname(Chan);
PC = privwelcomes[list].pc;
Msg = privwelcomes[list].msg;
privclass = pc[3].substring(3);
gpc = pc[8].substring(4);
if(this.ns == Chan && rp.param!=dAmn_Client_Username && (privclass.toLowerCase()==PC.toLowerCase() || PC.toLowerCase()=="all")){
while(Msg.match("@user")||Msg.match("@privclass")||Msg.match("@channel")||Msg.match("@gpc")){
Msg = Msg.replace(/@user/,rp.param);
Msg = Msg.replace(/@channel/,"#"+dname(this.ns));
Msg = Msg.replace(/@privclass/,privclass);
Msg = Msg.replace(/@gpc/,gpc);}
say(Msg,dname(Chan));
}
}
}
break;
}
break;
}
}
}
dAmnChat.prototype.onData=dAmnChat_onData;
dAmnChat.prototype.onData_damnwelcome=dAmnChat_onData_damnwelcome;
dAmn_objForEach(dAmnChats,function(chan){
main=chan.channels.main;
main.input.cmds[commandname]=[0,''];
main.input.onKey=dAmnChatInput_onKey;
main.input.onKey_damnwelcome=dAmnChatInput_onKey_damnwelcome;
dAmnChatTabs_activate_active();
});
}
},2000);
"
Whoa, Major Javascript overload. 0.o