ふたりのチャット 作業版

■ソース
[diary:174380]
[beforeExec]
getChat = function(){
chatCh = 0;
Fx.e(ch0_uri, "cn0");
};
Lo.cn0 = function(msg){
if(!isLoop) return;
msg = Fx.dec(msg.replace(/^.+name="text">(.+)\x3c\/textarea>.+$/, "$1"));
if(u0msg != msg){
echo("logo_0", msg == "done." ? '<input type="button" value="入室" onclick="login(0)" />' : "入室中");
}
if(msg == "done.") chatCh++;
u0msg = msg;
setTimeout('Fx.e("' + ch1_uri + '", "cn1")', 0);
};
Lo.cn1 = function(msg){
if(!isLoop) return;
msg = Fx.dec(msg.replace(/^.+name="text">(.+)\x3c\/textarea>.+$/, "$1"));
if(u1msg != msg){
echo("logo_1", msg == "done." ? '<input type="button" value="入室" onclick="login(1)" />' : "入室中");
}
if(msg == "done.") chatCh += 2;
u1msg = msg;
if(chatCh != isChatCh){
echo("formInfo", chatCh == 3 ? "ホストで入室になります" :
chatCh == 0 ? "満室です" : "相方が入室してお待ちしています"
);
}
isChatCh = chatCh;
chatHost = chatCh == 3 ? true : false;
if(isLoop) setTimeout("getChat()", 3000);
};

ac1_a = function(){ Fx.e(ch_uri + chatBoxNo2, "ac1_b"); };
Lo.ac1_b = function(s){
var msg = Fx.dec(s.replace(/^.+name="text">(.+)\x3c\/textarea>.+$/, "$1"));
Fid("ac2").style.color = msg == "done." ? "#ccf" : "#339";
if(msg != "done." && msg != user2Msg){
echo("formInfo", "");
echo("chatBuff", msg);
Fid("ac3").style.color="orange";
}
if(msg == "done."){
if(chatHost) echo("formInfo", "※ゲスト(" + chatUser2 + ")待ちです");
else {
echo("formInfo", "※ホストが退室しましたのでホストになります");
chatHost = true;
form_host_guest();
}
}
user2Msg = msg;
Fid("ac1").style.color = "#fcc";
};

isLogin = function(){
Fid("logoAct").style.color = timeCnt % 2 ? "#0f0" : "#cfc";
if(timeCnt % 5 == 0){
Fid("ac1").style.color="tomato";
ac1_a();
}
echo("u_time", userTimes());
/* if(chatHost && timeCnt % 31 == 0 && msgStack != 0) updateBody(); */
timeCnt++;
};
uc = function(){ updateBody(); };
updateBody = function(){
msgStack = 0;
Fid("uc1").style.color = "magenta";
var str = '\x3cdiv class="chat_info">' + chatDefaultInfo + '\x3c/div>\n' +
'\x3cdiv class="chat_body">' + chatDefaultBody + '\x3c/div>';
str = str.replace(/\t/g, "\n");
Fx.e("diary_form",diaryForm(chatArticle, chatTitle, str,0, 949), "uE2");
};
Lo.uE2 = function(){
Fid("uc1").style.color = "#339";
};
getArticle = function(){
var str = Fx.e(["/cgi-bin/diary_form.cgi?mode=edit;oid=",Vis.oid,";article_id=",chatArticle], false);
str = str.replace(/\r?\n/g, "\t");
return Fx.dec(str);
};
userTimes = function(){
var a = chatTime(0).split(":");
return a[0] + '\x3cspan style="color:' + (timeCnt % 2 ? "#000" : "#ccc") + '">:\x3c/span>' + a[1];
};
form_host_guest = function(){
echo("formHostDisp",
chatUser + "(" + (chatHost ? "ホスト" : "ゲスト") + ")"
).className = "form_" + (chatHost ? "host" : "guest");
};

login = function(n){
isLoop = false;
chatBox = n;
chatBox2 = n ? 0 : 1;
chatName = ["なんちゃん","葉月"];
chatUser = chatName[n];
chatUser2 = chatName[chatBox2];
chatBoxNo = ch[n];
chatBoxNo2 = ch[chatBox2];
Fid("loginButton").disabled = false;
chatLogin = true;
form_host_guest();
echo("formInfo", chatHost ? "※ゲスト待ちです" : "");
echo("logo_" + chatBox, '\x3cspan id="u_time">' + userTimes() + '\x3c/span> \x3cspan id="uc1">■\x3c/span>\x3cspan id="uc2" onclick="uc()">■\x3c/span>').className = "logo_a";
echo("logo_" + chatBox2, '\x3cspan id="logoAct">■\x3c/span>\x3cspan id="ac1">■\x3c/span>\x3cspan id="ac2">■\x3c/span>\x3cspan id="ac3">■\x3c/span>').className = "logo_b";
user2Msg = "";
chatDispMsg = "";
chatBuffMsg = "";
var s = chatTime(1) + " ";
echo("txt1", s).focus();
chat(s);
chatTimer1 = setInterval("isLogin()", 1000);
};

entry = function(){
ch = [46370,46369];
chatArticle = Fx.loc.match(/page=(\d+)/) ? RegExp.$1 : 174381;
var doc = getArticle();
chatTitle = doc.replace(/^.+ value="(ふたりのチャット \(\d+\))".+$/, "$1");
chatDefaultBody = doc.replace(/^.+\x3cdiv class="chat_body">(.+?)\x3c\/div>.+$/, "$1");
chatDefaultInfo = doc.replace(/^.+\x3cdiv class="chat_info">(.+?)\x3c\/div>.+$/, "$1");
echo("chatDisp", chatDefaultBody.replace(/\t/g, "\x3cbr />"));
ch_uri = "/cgi-bin/diary_editor.cgi?oid=" + Vis.oid + "&type=comments;id=";
ch0_uri = ch_uri + ch[0];
ch1_uri = ch_uri + ch[1];
ini();
getChat();
};
ini = function(){
msgStack = 0;
chatLogin = false;
timeCnt = 0;
u0msg = "";
u1msg = "";
isLoop = true;
isChatCh = -1;
};

chatTime = function(n){
var d = new Date();
var mm = ("0" + (d.getMonth() + 1)).slice(-2);
var dd = ("0" + d.getDate()).slice(-2);
var h = ("0" + d.getHours()).slice(-2);
var m = ("0" + d.getMinutes()).slice(-2);
return (n ? mm + "/" + dd + " " : "") + h + ":" + m;
};

chat = function(msg){
Fid("ac3").style.color = "red";
var str = "/cgi-bin/diary_editor.cgi?mode=update&oid=" + Vis.oid + "&type=comments&id=" +
chatBoxNo + "&text=" + enc(msg);
Fx.e(str, "chatReq");
};
Lo.chatReq = function(s){
Fid("ac3").style.color = "yellow";
};

showChatDisp = function(str){
return;
var o = Fid("chatDisp");
echo(o.insertBefore(Fce("div"), o.firstChild), str);
chatDefaultBody = str + "\n" + chatDefaultBody;
msgStack++;
/* if(chatHost && msgStack > 10) updateBody(); */
};

chatSubmit = function(){
var str = echo("txt1");
chat(str);
};
counter = function(){
var s = echo("txt1");
echo("counterDisp", s.length + "/200(max)");
if(s.slice(-1) == "\n") chatSubmit();
};

window.onunload = function(){
if(chatLogin) chat("done.");
};
[/beforeExec]
[cssText]
#mainDisp { margin-left:2em; }
#chatDisp {
min-height:30em; margin-bottom:3em;
margin-top:.5em;
}
#chatBuff {
font-size:105%; width:100%;
background-color:#afeeee; border:1px solid #ccc;
}
.top_form {
padding-top:95px; width:350px; text-align:center; float:left;
background:url(MIHO/futari/nancyan_hazuki_kotobanohako_123.jpg) no-repeat center top;
}
#txt1 {
font-size:105%; width:100%; background-color:ivory;
border:1px solid #ccc;
}
#logo_w0 { display:inline-block; width:49%; text-align:right; }
#logo_w1 { display:inline-block; width:49%; text-align:left; }
#logo_0 { margin-right:60px;}
#logo_1 { margin-left:65px; }
.logo_a { color:#339;}
.logo_b { color:darkgreen; }

#uc2 { cursor:default; }

.logo { margin-left:360px; padding-top:1em; }
.logo span { font-size:80%; }
.logo a { text-decoration:none; font:130%/1.3 serif; }

.clear { clear:left; }
#submitForm {
margin:.5em 0em; font-size:90%; width:500px;
}
#u_time { color:#808080; font-family:Verdana; }
#_u_time span { font-weight:bold; }
.form_host { color:#9932cc; font-family:"MS UI Gothic"; }
.form_guest { color:#808080; font-family:"MS UI Gothic"; }
#newButton { float:right; }
[/cssText]
[body]
<form onsubmit="return false;" class="top_form">
<$$span id="logo_w0"><$$span id="logo_0">チェック中<$$/span><$$/span>
<$$span id="logo_w1"><$$span id="logo_1">チェック中<$$/span><$$/span>
</form>
<$$div class="logo">
<$$a href="main.html?diary=174380">ふたりのチャット <$$span>2.0<$$/span><$$/a>
<$$/div>
<$$div class="clear"><$$/div>
<form id="submitForm">
<$$textarea id="txt1" cols="40" rows="3" wrap="soft" onkeyup="counter()"><$$/textarea>
<$$div >
<input id="loginButton" type="button" value="送信" disabled="disabled" onclick="chatSubmit()" />
<$$span id="formHostDisp"><$$/span>
<$$span id="counterDisp">23/200(max)<$$/span>
<$$span id="formInfo">done.<$$/span>
<input type="button" value="新規" id="newButton" disabled="disabled" />
<$$/div>
<$$textarea id="chatBuff" cols="40" rows="3" wrap="soft"><$$/textarea>
</form>
<$$div id="chatDisp" class="chat_body"><$$/div>
[/body]
[exec]
document.title = "ふたりのチャット 作業版";
entry();
[/exec]
[/diary:174380]

■仕様書 2010 09/04 07:30 Wrote