Hi, I dont know if this chat-script this is any good.
It's the update from the one previously sported here.
If anyone would take a crack at critizizing it, it would be great.
I know it should be possible to make it work for Opera and Mozilla as well, and I once wrote a version for Netscape.
It should be quite easy to do in PHP as well, for those who knows anything about that, which I dont, unfortunatly.
This is the server-part.
<pre>
<% @ LANGUAGE=JScript %>
<% Response.ContentType = "application/x-javascript .js" %>
<%
ForAppending=8;
ForWriting=2;
ForReading=1;
tribuned=new String(Request.Querystring);
tribuned=tribuned.split("<cut>");
if(!tribuned[1])
{
%>
reply="";
num="";
adress="liquid21";
winx=0;
window.str=0;
document.write("<script id='call'><"+"/script>");
window.onload=signOn;
function thePackage()
{
str=document.all.register.template;
if(str=="0"){str="<br/><font style='color:black;border:solid black 2px;width:200;padding:3px;font-face:verdana;font-size:10pt;'><b>[TITLE]</b><br/><b style='cursor:hand;color:black;background-color:silver;border:solid red 1px;padding:2px;height:15;overflow:hidden;width:70;font-size:9px' onclick='callUp()' visitor='[THE_ID]'>Send to..</b><br/><br/>Post: <span id='account'>[POST]</span></font>";}
if(document.all.title){str=str.replace("[TITLE]",document.all.title.value);}
if(document.all.post){str=str.replace("[POST]",document.all.post.value);}
if(document.all.link_to){str=str.replace("[LINK_TO]",document.all.link_to.value);}
if(document.all.mail){str=str.replace("[MAIL_TO]",document.all.mail.value);}
str=str.replace("[THE_ID]",document.body.timestamp);
package=escape(str);
return package
}
function Call()
{
validate(document.all.post.value);
conn="http://www.naltabyte.se/rent_a_chat/files/mail.asp?the_mail_out<cut>";
num++;
thePackage();
act=adress+"<cut>"+package+"<cut> 'the_"+num+"'";
document.all.call.src=conn+act;
document.all.post.value="";
if(reply==""){return false;}
else
{
num++;
reply="";
setTimeout('CallOne(0,1)',2000);
}
}
function CallOne(addon,arg)
{
conn="http://www.naltabyte.se/rent_a_chat/files/mail.asp?the_mail_in<cut>";
num++;
act=addon+"<cut>"+document.body.setTime+"<cut>"+document.all.post.value+"---"+document.all.title.value+"<cut>-<cut> 'the_"+num+"'";
if(!arg){document.all.post.value="";}
call.src=conn+act;
if(reply==""){return false;}
else
{
num++;
reply="";
}
}
function signOn()
{
day=new Date();
day=day.toGMTString();
day=day.replace(/:/g,".");
if(top!=self)
{
if(!document.body.timestamp)
{
document.body.timestamp=parent.setIdentity;
}
}
else if(!document.body.timestamp)
{
document.body.timestamp=day;
}
document.body.setTime="0";
setInterval('CallOne(0,1)',6000);
}
function validate(data)
{
ndata=document.all.post.value;
for(i=0;i < ndata.length;i++)
{
ndata=ndata.replace("<","<");
ndata=ndata.replace(">",">");
ndata=ndata.replace("(","acccc");
ndata=ndata.replace(")","cccca");
ndata=ndata.replace('"','"');
}
document.all.post.value=ndata;
}
function callUp()
{
document.body.setTime=event.srcElement.visitor;
CallOne('send');
}
<%
}
if(tribuned[0]=="the_mail_out"){finish();}
if(tribuned[0]=="the_mail_in"){startup();}
if(tribuned[1]=="send"){sender();}
function finish()
{
strFil="";
indata=" ";
Fsave=" ";
Fstore="";
fso=new ActiveXObject("Scripting.FileSystemObject");
if(fso.FileExists(Server.MapPath("liquid21")))
{
ofil=fso.OpenTextFile(Server.MapPath("liquid21"), ForReading, true);
while(!ofil.AtEndOfStream){strFil+=ofil.ReadLine();}
var x=unescape(strFil);
x=x.split("#");
for(i=0;i < 5;i++){if(!x[i]){break;}indata+=x[i]+"#";}
ofil.Close();
File=fso.OpenTextFile(Server.MapPath("liquid21"), ForWriting, true);
Fsave+=tribuned[2];
Fsave+="<span style='visibility:hidden'>#</span><br>";
File.WriteLine(unescape(Fsave));
File.Write(unescape(indata));
File.Close();
}
if(!fso.FileExists(Server.MapPath("liquid21")))
{
objFile=fso.CreateTextFile(Server.MapPath("liquid21"), true);
objFile.Write(" ")
objFile.Close();
}
%>
<%
}
function startup()
{
strFil="";
indata="";
fso=new ActiveXObject("Scripting.FileSystemObject");
if(fso.FileExists(Server.MapPath("liquid21")))
{
ofil=fso.OpenTextFile(Server.MapPath("liquid21"), ForReading, true);
while(!ofil.AtEndOfStream){strFil+=ofil.ReadLine();}
ofil.Close();
x=unescape(strFil);
x=x.split("#");
for(i=0;i < 6;i++){if(!x[i]){break;}indata+=x[i];}
str="";
fso=new ActiveXObject("Scripting.FileSystemObject");
ofile=fso.OpenTextFile(Server.MapPath("mail.txt"));
while(!ofile.AtEndOfStream) {str += ofile.ReadLine();}
ofile.Close();
%>
printoutdata="<% Response.Write(indata) %>";
printoutdata1=printoutdata.replace(/acccc/g, "(");
printoutdata1=printoutdata1.replace(/cccca/g, ")");
document.all.printOut.innerHTML=printoutdata1;
reply="Success";
recalling();
function recalling()
{
x="<% Response.Write(str) %>";
identity=x.split("<cut>");
if(identity[0]==document.body.timestamp && window.str!=identity[1])
{
window.str=identity[1];
winx=window.open("about:blank","javas","height=120,width=140,resizable=no,scrollbars=no");
winx.document.write("<html><title>Message</title><body oncontextmenu='return false' style='background:butt****ce;border:0'><center><div style='border:inset 1px;height:80px;width:120px;overflow:scroll;background:white;font-family:verdana;font-size:10px;padding:5px'>"+identity[1]+"</div></center></body></html> ");
winx.focus();
}
}
<%
}
}
function sender()
{
objFSO=new ActiveXObject("Scripting.FileSystemObject");
objFile=objFSO.CreateTextFile(Server.MapPath("mail.txt"), true);
objFile.Write(unescape(tribuned[2])+"<cut>"+unescape(tribuned[3]))
objFile.Close();
}
%>
</pre>
This is the client-part.
I use the attribute 'template' in the script-tag to define how I want the posts to be formatted.
It's sent to the server along with the posts.
That way, I can have multiple instances of this chat, with different interfaces and posts, adjusted to the design.
<pre>
<html>
<head>
<title>Naltabyte_chat v.1.0</title>
<script
id="register"
mode="chat"
template="<br><font style='overflow:scroll;color:black;border:solid black 2px;width:200;padding:3px;font-face:verdana;font-size:10pt;background:white'><b>[TITLE]</b><br><span style='text-align:center;margin:1px;font-family:verdana;font-size:9px;cursor:hand;color:black;background-color:buttonhighlight;border:solid black 1px;width:70;font-size:9px;display:block' onclick='callUp()' visitor='[THE_ID]'>Send to..</span><span id='account'><span onclick='parent.viewTheCodeNow(this.parentElement.children(1).innerText)' style='text-align:center;margin:1px;border:black 1px solid;background-color:buttonhighlight;font-family:verdana;font-size:9px;cursor:hand;display:block;width:70'>Codeview</span><span>[POST]</span></span>< ;/font>";
src="http://www.naltabyte.se/rent_a_chat/files/mail.asp">
</script>
</head>
<body oncontextcode="return false" scroll="no" style="background-color:butt****ce;border:0">
<center>
<table style="width:100%;height:100%;border:0;z-index:8;padding:10">
<tr valign="top" style="width:100%;height:100%">
<td align="right" style="width:30%;height:100%">
<input type="text" id="title" style="background-color:white;border:solid gray 1px;width:100%"><b>Name:</b><br />
<textarea id="post" style="background-color:white;border:solid gray 1px;width:100%;height:70%"></textarea>
<br />
<button onclick="Call()" style="background:white;border:gray 1px solid;height:20;width:50;font-size:10">Post</button>
</td>
<td style="width:50%;height:100%">
<div id="printOut" style="position:relative;top:3;left:0;padding:15;background:white;width:100%;height:100%;overflow:scroll">
</div>
</td>
</tr>
<tr>
<td colspan="2" align="right" style="width:100%;height:100%">
</td>
</tr>
</table>
</center>
</body>
</html>
</pre>
(^-^)b