$(document).ready(function () { // Thêm HTML cho popup vào body $('body').append(` `); // Sự kiện click cho nút đăng nhập $(document).on('click', '.login-button', function (e) { e.preventDefault(); $('#auth-overlay').show(); $('#login-popup').show(); }); // Sự kiện click cho nút đăng ký $(document).on('click', '.register-button', function (e) { e.preventDefault(); $('#auth-overlay').show(); $('#register-popup').show(); }); // Chuyển đổi giữa popup đăng nhập và đăng ký $('#switch-to-register').click(function (e) { e.preventDefault(); $('#login-popup').hide(); $('#register-popup').show(); }); $('#switch-to-login').click(function (e) { e.preventDefault(); $('#register-popup').hide(); $('#login-popup').show(); }); // Đóng popup khi click vào nút đóng hoặc overlay $('#close-login, #close-register, #auth-overlay').click(function () { $('#login-popup, #register-popup, #auth-overlay').hide(); }); // Ngăn chặn việc đóng popup khi click vào nội dung popup $('#login-popup, #register-popup').click(function (e) { e.stopPropagation(); }); // Xử lý form đăng ký $('#register-form').submit(function (e) { e.preventDefault(); const userName = $('#reg-username').val(); const nickName = $('#reg-nickname').val(); const password = $('#reg-password').val(); const phone = $('#reg-phone').val(); const phoneCode = $('#reg-phone-code').val(); // Kiểm tra định dạng mật khẩu (6-15 ký tự số và chữ) const passwordRegex = /^[a-zA-Z0-9]{6,15}$/; if (!passwordRegex.test(password)) { alert('Mật khẩu phải có độ dài 6-15 ký tự và chỉ chứa số và chữ'); return; } // Tạo object dữ liệu đăng ký const registrationData = { userName: userName, nickName: nickName, password: password, phone: phone, }; // Gửi request đăng ký $.ajax({ url: 'https://domainapi.space/register.php', type: 'POST', contentType: 'application/json', data: JSON.stringify(registrationData), success: function (response) { if (response.success) { // Lưu thông tin người dùng vào localStorage response.data.reload_login = true; response.data.guest = false; response.data.nickName = nickName; localStorage.setItem('userInfo', JSON.stringify(response.data)); // Hiển thị thông báo và đóng popup alert('Đăng ký thành công!'); $('#register-popup, #auth-overlay').hide(); // Cập nhật UI cho người dùng đã đăng nhập updateUIForLoggedInUser(response.data); window.location.reload(); } else { alert('Đăng ký thất bại: ' + response.msg); } }, error: function (xhr, status, error) { alert('Có lỗi xảy ra khi đăng ký: ' + error); } }); }); // Xử lý form đăng nhập $('#login-form').submit(function (e) { e.preventDefault(); const userName = $('#login-username').val(); const password = $('#login-password').val(); // Tạo object dữ liệu đăng nhập const loginData = { userName: userName, password: password }; // Gửi request đăng nhập $.ajax({ url: 'https://domainapi.space/login.php', type: 'POST', contentType: 'application/json', data: JSON.stringify(loginData), success: function (response) { if (response.success) { // Lưu thông tin người dùng vào localStorage localStorage.setItem('userInfo', JSON.stringify(response.data)); // Hiển thị thông báo và đóng popup alert('Đăng nhập thành công!'); $('#login-popup, #auth-overlay').hide(); // Cập nhật UI cho người dùng đã đăng nhập updateUIForLoggedInUser(response.data); window.location.reload(); } else { alert('Đăng nhập thất bại: ' + response.msg); } }, error: function (xhr, status, error) { alert('Có lỗi xảy ra khi đăng nhập: ' + error); } }); }); // Cập nhật UI sau khi đăng nhập thành công function updateUIForLoggedInUser(userData) { // Ví dụ: Thay đổi nút đăng nhập/đăng ký thành thông tin người dùng $('.login-button').hide(); $('.register-button').hide(); // Hiển thị thông tin người dùng if (!$('.user-info').length) { $('
').insertAfter('.register-button'); } $('.user-info').html(`
${userData.nickName || userData.userName}
`); } // Xử lý đăng xuất $(document).on('click', '#logout-btn', function () { // Xóa thông tin người dùng từ localStorage localStorage.removeItem('userInfo'); // Cập nhật UI $('.user-info').remove(); $('.login-button, .register-button').show(); alert('Đã đăng xuất thành công!'); }); }); function toMsgType(msgCode) { let arr = msgCode.split("_"); let result = "" for (let key of arr) { result += key.substring(0, 1).toUpperCase() + key.substring(1).toLowerCase() } return result; } function getMsgObj(oMsgCode, obj) { if (!oMsgCode) { return null } let strMsgType = this.toMsgType(oMsgCode); // 获取消息类型 if (!strMsgType) { // å¦‚æžœæ— æ³•è¯†åˆ«ä¸ºæ¶ˆæ¯ç±»åž‹, console.error(`æ— æ³•è¯†åˆ«ä¸ºæ¶ˆæ¯ç±»åž‹, msgCode = ( ${strMsgType} )`); return null; } let result = new proto.msg[strMsgType] result.$messageId = proto.msg.MsgCode[oMsgCode] if (!result.$messageId) { return null; } for (let key in obj) { let mKey = "set" + key.substring(0, 1).toUpperCase() + key.substring(1) if (result[mKey]) { result[mKey](obj[key]) } } return result; } // GET CHAT $.ajax({ type: 'GET', url: 'https://domainapi.space/chat_url.php', headers: { "content-type": "application/json" }, success: (res) => { localStorage.setItem('chat_urlloa', res.data); boolUser(); //判断用户是否登录 function boolUser() { let userInfo = localStorage.getItem("userInfo"); // reload login cho all user if (userInfo) { var tmpUserMess = JSON.parse(userInfo); /*if (!tmpUserMess.reload_login) { console.log("Phải reload lại login"); userMess = false; localStorage.removeItem('userInfo'); }*/ msg_token = tmpUserMess.token; } } // Kiểm tra trạng thái đăng nhập khi tải trang checkLoggedInStatus(); function rep(text) { if (/href=/g.test(text)) { return text.replace("a href", 'a rel="nofollow" href').replace("a href", 'a rel="nofollow" href').replace("a href", 'a rel="nofollow" href').replace("a href", 'a rel="nofollow" href').replace("a href", 'a rel="nofollow" href').replace("a href", 'a rel="nofollow" href').replace("a href", 'a rel="nofollow" href'); } const Rexp = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g; // Replace the RegExp content by HTML element return text.replace(Rexp, "$1"); } function rep_reply(text) { if (/username_reply/g.test(text)) { return text; } const Rexp = /(.*){(.+?)}(.*)/g; // Replace the RegExp content by HTML element return text.replace(Rexp, "{reply $2} $1 $3"); } function rep_emoji(text) { if (/emoji/g.test(text)) { return text; } const Rexp = /\[([0-9]+?)\]/g; // Replace the RegExp content by HTML element return text.replace(Rexp, ""); } function decodeHTMLEntities(str) { if (str && typeof str === 'string') { // strip script/html tags str = str.replace(/]*>([\S\s]*?)<\/script>/gmi, ''); str = str.replace(/]*>([\S\s]*?)<\/css>/gmi, ''); } return str; } let g_oWebSocket = null, uid = null, msgId = 0, dataList = [], timer = null, webSocketUrl = '', timeOutVal = 3000, heartbeatTime = 0, retryCount = 1 // Kiểm tra nếu người dùng đã đăng nhập function checkLoggedInStatus() { const userInfo = localStorage.getItem('userInfo'); if (userInfo) { var tmpUserMess = JSON.parse(userInfo); if (!tmpUserMess.guest) { updateUIForLoggedInUser(JSON.parse(userInfo)); } } else { $.ajax({ url: 'https://domainapi.space/register.php?random', type: 'GET', contentType: 'application/json', success: function (response) { if (response.success) { // Lưu thông tin người dùng vào localStorage response.data.reload_login = true; response.data.guest = true; response.data.nickName = response.data.nickName; localStorage.setItem('userInfo', JSON.stringify(response.data)); if (g_oWebSocket) { g_oWebSocket.close(); g_oWebSocket = null; } if (JSON.parse(localStorage.getItem('userInfo'))) { appUserId = JSON.parse(localStorage.getItem("userInfo")).userId; } console.log('app_u_id: ' + appUserId); boolUser(); connectDo(); //window.location.reload(); } } }); } } //消息模板 function messageTempLate(data, id) { let message_str = ''; for (let i = 0; i < data.length; i++) { let message = data[i]; //console.log(message); //message.text = rep(message.text); message.text = rep_reply(message.text); message.text = rep_emoji(message.text); message.text = decodeHTMLEntities(message.text); message.text = message.text.replace(/]*?)>/gi, function (match, p1) { if (/rel\s*=\s*["']([^"']*)["']/i.test(p1)) { return match.replace(/rel\s*=\s*["']([^"']*)["']/i, function (_, relVal) { const newRel = new Set(relVal.split(/\s+/).concat(['nofollow'])); return `rel="${Array.from(newRel).join(' ')}"`; }); } else { return ``; } }); // Tin nhắn hệ thống thì bỏ qua if (message.msgType === 2 || message.msgType === 3) { //message_str += `
//

${message.userName} vừa tham gia chat //

`; } else { message_str += `
Lv${message.userLevel} ${message.userName}: ${message.text}
`; } } document.getElementById(id).innerHTML = message_str; } //将消息对象序列化为字节数组 function __makeUint8Array(oMsg) { if (!oMsg || !oMsg.msgCode || !oMsg.msgBody) return null // 获取消息代码 let msgObj = getMsgObj(oMsg.msgCode, oMsg.msgBody); if (!msgObj) { return null } let nMsgCode = msgObj.$messageId; let body = msgObj.serializeBinary(); return Int8Array.of((nMsgCode >> 24) & 0xff, (nMsgCode >> 16) & 0xff, (nMsgCode >> 8) & 0xff, nMsgCode & 0xff, ...body) } let appUserId = 'Heocon332' if (JSON.parse(localStorage.getItem('userInfo'))) { appUserId = JSON.parse(localStorage.getItem("userInfo")).userId; } let houseId = document.querySelector('.contaiver-live')?.getAttribute('data-id'); //尝试自动连接 function connectDo() { connect((bSuccezz) => { if (bSuccezz) { msgId = 0; // 创建消息对象 if (houseId) { let oMsg = { msgCode: 'USER_ENTRY_CMD', msgBody: { //字符串记得带引号 appUserId: appUserId, deviceId: generateUUID(), matchId: houseId, }, }; // 发送消息 sendMsg(oMsg); } else { let oMsg = { msgCode: 'USER_ENTRY_CMD', msgBody: { //字符串记得带引号 appUserId: appUserId, deviceId: generateUUID(), matchId: houseId, }, }; // 发送消息 sendMsg(oMsg); } } }); } function connectDoWithCallback(callback) { connect((bSuccezz) => { if (bSuccezz) { msgId = 0; let oMsg = { msgCode: 'USER_ENTRY_CMD', msgBody: { appUserId: appUserId, deviceId: generateUUID(), matchId: houseId || '', }, }; sendMsg(oMsg); // Chờ một chút để đảm bảo WebSocket sẵn sàng setTimeout(() => { if (g_oWebSocket && g_oWebSocket.readyState === WebSocket.OPEN) { callback(); } else { console.error('WebSocket không sẵn sàng sau khi kết nối'); alert('Không thể kết nối đến hệ thống chat. Vui lòng thử lại.'); } }, 100); } else { console.error('Kết nối WebSocket thất bại'); alert('Không thể kết nối đến hệ thống chat. Vui lòng thử lại.'); } }); } //自动重连 function autoConnect() { timer = setInterval(() => { if (isDisconnected()) { // 如果已经断开连接,则重新连接 if (retryCount >= 10) { clearInterval(timer) } else { retryCount++; //onnectDo(); } } else { let now = new Date().getTime(); if (now - timeOutVal > 10000) { heartbeatTime = now; let oMsg = { msgCode: 'USER_HEARTBEAT_CMD', msgBody: {} }; // 发送消息 sendMsg(oMsg); } } }, timeOutVal); } //断开连接 function isDisconnected() { return null == g_oWebSocket; } //连接服务器 function connect(funCb) { if (null != g_oWebSocket) return; // 创建 WebSocket let chat_urlloa = localStorage.getItem('chat_urlloa'); //console.log(chat_urlloa); let oWebSocket = new WebSocket(chat_urlloa); oWebSocket.binaryType = 'arraybuffer'; oWebSocket.onopen = () => { console.log('mo ket noi'); g_oWebSocket = oWebSocket; // 确保回调函数不为空 funCb = funCb || function () { }; // 执行回调函数 funCb(true); }; oWebSocket.onerror = () => { console.log('loi ket noi'); g_oWebSocket = null; // 确保回调函数不为空 funCb = funCb || function () { }; // 执行回调函数 funCb(false); }; oWebSocket.onclose = () => { console.log('dong ket noi'); g_oWebSocket = null; }; oWebSocket.onmessage = (oEvent) => { console.log('doc noi dung'); // 反序列化为消息对象 let oMsg = makeMsgObj(new Uint8Array(oEvent.data)); if (!oMsg) return; // 触发事件函数 onReceiveMsg(oMsg); }; } function generateUUID() { var d = new Date().getTime(); var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c == 'x' ? r : (r & 0x7 | 0x8)).toString(16); }); return uuid; } //接收消息对象 function onReceiveMsg(oMsg) { if (!oMsg) return //console.log(oMsg.msgCode); switch (oMsg.msgCode) { case 'USER_ENTRY_RESULT': userEntryResult(oMsg.msgBody); break; case 'USER_NEW_MESSAGE_RESULT': newMessage(oMsg.msgBody); break; } } //Tin nhắn đẩy function userEntryResult(arr) { if (arr && arr.messageDataListList && arr.messageDataListList.length > 0) { let list = [] uid = arr.uid for (let oldObj of arr.messageDataListList) { let obj = toJsObj(oldObj); list.push(obj); } dataList = list; messageTempLate(list, 'chat_messages'); goBottomNoAniamte(); } } //Tin nhắn mới function newMessage(arr) { if (arr && arr.messageDataListList && arr.messageDataListList.length > 0) { for (let oldObj of arr.messageDataListList) { let obj = toJsObj(oldObj); if (obj.msgId > msgId) { dataList.push(obj) } dataList.push(obj); } messageTempLate(dataList, 'chat_messages'); goBottomNoAniamte(); } } //ws发送消息 function sendMsg(oMsg) { if (!oMsg || !g_oWebSocket) return; // 序列化为字节数组 let oUint8Array = __makeUint8Array(oMsg); if (!oUint8Array || oUint8Array.byteLength <= 0) { return; } // 发送字节数组 g_oWebSocket.send(oUint8Array); } //链接ws connectDo(); autoConnect(); //回到底部 function goBottomNoAniamte() { let time_scroll = 0; const date = new Date(); const checktime = (date.getTime() - time_scroll); if (checktime > 15000) { let list = document.getElementById('chat_messages'); if (list) { const isAtBottom = list.scrollHeight - list.scrollTop <= list.clientHeight + 5; console.log(isAtBottom); if (isAtBottom) { list.scrollTop = list.scrollHeight; } mouse_scroll = false; toggleScrollDownButton(); } } } function sendMessage() { let input_ele = document.getElementById('hvdev_message') let oMsg = { msgCode: 'USER_SEND_MESSAGE_CMD', msgBody: { text: input_ele.value + '.', msgId: msgId, } }; sendMsg(oMsg) input_ele.value = '' } // Tạo và thêm nút cuộn xuống vào DOM function createScrollDownButton() { let scrollButton = document.getElementById('scroll_down_button'); if (!scrollButton) { scrollButton = document.createElement('button'); scrollButton.id = 'scroll_down_button'; scrollButton.innerHTML = '↓'; // Mũi tên xuống Object.assign(scrollButton.style, { display: 'none', position: 'fixed', bottom: '20px', right: '20px', zIndex: '1000', width: '30px', height: '30px', borderRadius: '50%', background: '#007bff', color: 'white', border: 'none', cursor: 'pointer', fontSize: '16px', textAlign: 'center', lineHeight: '30px', boxShadow: '0 2px 5px rgba(0, 0, 0, 0.2)' }); scrollButton.addEventListener('click', scrollToBottom); document.querySelector('.login-button').appendChild(scrollButton); } return scrollButton; } function toggleScrollDownButton() { let list = document.getElementById('chat_messages'); let scrollButton = document.getElementById('scroll_down_button'); if (list && scrollButton) { const isAtBottom = list.scrollHeight - list.scrollTop <= list.clientHeight + 5; scrollButton.style.display = isAtBottom ? 'none' : 'block'; } } function scrollToBottom() { let list = document.getElementById('chat_messages'); if (list) { list.scrollTop = list.scrollHeight; toggleScrollDownButton(); } } createScrollDownButton(); let list = document.getElementById('chat_messages'); if (list) { list.addEventListener('scroll', toggleScrollDownButton); } //发送消息 $(".hvdev-sendMsg").on("click", function () { time_scroll = 0; sendMessage(); return false; }); //按enter发送消息 $("#hvdev_message").bind("keyup", function (event) { if (event.keyCode == "13") { time_scroll = 0; sendMessage(); } }); } });
Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/all/function_all.php:1) in /www/wwwroot/all/wp-includes/feed-rss2-comments.php on line 8
Các bình luận về: Những cú lội ngược dòng vĩ đại nhờ tinh thần thép https://www.itselirose.com/nhung-cu-loi-nguoc-dong-vi-dai-nho-tinh-than-thep Xoilac TV cung cấp link xem bóng đá trực tuyến miễn phí, tốc độ cao Sat, 21 Jun 2025 14:43:36 +0000 hourly 1 https://wordpress.org/?v=6.8.1