1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/OI-Master-chat

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
main.js 6.1 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
OI-Master Отправлено 21.11.2020 16:29 b2d4f7b
/*
(() => {
return;
var username = "神秘人";
var namecolor = "black";
var socket = io();
window.onload = function() {
var tres = prompt("请输入您的昵称(不想输入可以取消)", "");
var nv = false;
if (tres != null)
for (var i = 0; i < tres.length; ++i)
if (tres[i] != ' ') {
nv = true;
break;
}
if (nv)
username = tres;
var color = prompt("请输入昵称颜色(英文单词)。", "black");
nv = false;
if (color != null)
for (var i = 0; i < color.length; ++i)
if (color[i] != ' ') {
nv = true;
break;
}
if (nv)
namecolor = color;
var wca = confirm("欢迎来到 OI-MasterChat!按下确定跟大家打招呼!");
if (wca)
socket.emit('chat message', { "un": username, "color": namecolor, "message": "大家好!" });
}
var unreadmsg = 0;
$(function() {
$('form').submit(function() {
var s = $('#m').val();
$('#m').val('');
var flag = false;
for (var i = 0; i < s.length; ++i)
if (s[i] != ' ') {
flag = true;
break;
}
if (flag)
socket.emit('chat message', { "un": username, "color": namecolor, "message": s });
else
alert("消息不能为空");
return false;
});
socket.on('chat message', function(msg) {
$('#messages').append('<li><span style="font-weight:bold;color:' + msg.color + ';font-size:30px;">' + msg.un + '</span> ' + msg.message + '</li>');
if (document.visibilityState == "hidden") {
++unreadmsg;
alert("您有" + unreadmsg + "条未读消息。");
} else
unreadmsg = 0;
});
socket.on('system message', function(msg) {
$('#messages').append('<li><center><span class="system">&nbsp;' + msg + '&nbsp;</span></center></li>');
if (document.visibilityState == "hidden") {
++unreadmsg;
alert("您有" + unreadmsg + "条未读消息。");
} else
unreadmsg = 0;
});
});
})();
*/
function isnull(s){
for(var i=0;i<s.length;++i)
if(s[i]!=' ')
return false;
return true;
}
$(() => {
window.app = new Vue({
el: '#app',
data: {
text: '',
username: '匿名',
color: '#000000',
namecolor: '#000000',
socket: io(),
msgs: ["欢迎来到 OI-MasterChat。"],
drawer: false
},
methods: {
send() {
if (isnull(this.text)) {
this.$message.error('消息不能为空');
} else if(this.text.substr(0,6)=="music:"){
var mid=parseInt(this.text.substr(6));
if(!mid){
this.socket.emit('chat message', { "un": this.username, "color": this.color, "message": this.text ,"namecolor": this.namecolor});
this.text = '';
}
else{
this.socket.emit('chat message', { "un": this.username, "music": mid, "namecolor": this.namecolor});
this.text = '';
}
} else if(this.text.substr(0,6)=="video:"){
var vid=this.text.substr(6);
if(!vid){
this.socket.emit('chat message', { "un": this.username, "color": this.color, "message": this.text ,"namecolor": this.namecolor});
this.text = '';
}
else{
this.socket.emit('chat message', { "un": this.username, "video": vid, "namecolor": this.namecolor});
this.text = '';
}
} else {
this.socket.emit('chat message', { "un": this.username, "color": this.color, "message": this.text ,"namecolor": this.namecolor});
this.text = '';
}
},
handleClose(done) {
if(isnull(this.username))
this.username='匿名';
window.localStorage.username = this.username;
window.localStorage.color = this.color;
window.localStorage.namecolor = this.namecolor;
done();
},
cls(){
window.localStorage.msgs = [];
this.msgs = [];
},
clearall(){
window.localStorage.clear();
this.username="匿名";
this.color="#000000";
this.namecolor="#000000";
localStorage.msgs=this.msgs;
}
},
mounted() {
this.$message.warning('本网站会用到cookies,请勿禁用。');
let that = this;
try {
this.msgs = JSON.parse(window.localStorage.msgs);
this.username = window.localStorage.username;
if(!this.username)
this.usrename="匿名";
this.color = window.localStorage.color;
if(!this.color)
this.color="#000000";
this.namecolor=window.localStorage.namecolor;
if(!this.namecolor)
this.namecolor="#000000";
} catch (e) {}
this.socket.on('chat message', function(msg) {
that.msgs.push(msg);
window.localStorage.msgs = JSON.stringify(that.msgs);
});
this.socket.on('system message', function(msg) {
that.msgs.push(msg);
window.localStorage.msgs = JSON.stringify(that.msgs);
});
setTimeout(() => { $(".el-main")[0].scrollTop = $(".el-main")[0].scrollHeight; }, 10);
}
});
});

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/OI-Master-chat.git
git@api.gitlife.ru:oschina-mirror/OI-Master-chat.git
oschina-mirror
OI-Master-chat
OI-Master-chat
master