Update index.html
Browse files- index.html +55 -75
index.html
CHANGED
|
@@ -6,47 +6,51 @@
|
|
| 6 |
<title>Chat CVNSS4.0</title>
|
| 7 |
<style>
|
| 8 |
:root{
|
| 9 |
-
/*
|
| 10 |
-
--bg:#f7f9fc; --card:#
|
| 11 |
--primary:#1a73e8; --danger:#d93025; --accent:#ffeb3b;
|
| 12 |
-
/*
|
| 13 |
-
--mask-top:
|
| 14 |
-
--mask-right:clamp(220px,24vw,300px);
|
| 15 |
}
|
| 16 |
*{box-sizing:border-box}
|
| 17 |
-
body{
|
|
|
|
|
|
|
|
|
|
| 18 |
header{padding:14px 16px;text-align:center;font-weight:700;background:#fff;border-bottom:1px solid #e5e7eb}
|
| 19 |
-
.card{
|
|
|
|
|
|
|
|
|
|
| 20 |
h2{margin:0 0 6px} .muted{color:var(--muted)}
|
| 21 |
.row{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
|
| 22 |
input[type=text]{flex:1 1 260px;padding:12px 14px;font-size:16px;border:1px solid #d1d5db;border-radius:10px}
|
| 23 |
input[type=text]:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px rgba(26,115,232,.15)}
|
| 24 |
button{padding:12px 16px;border:0;border-radius:10px;font-weight:700;cursor:pointer}
|
| 25 |
-
.btn-red{background
|
| 26 |
.btn-ghost{background:#eef2ff;color:#1e3a8a}
|
| 27 |
.btn-secondary{background:#374151;color:#fff}
|
| 28 |
.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
| 29 |
|
| 30 |
-
/*
|
| 31 |
.status{display:none;align-items:center;gap:10px;padding:10px 12px;border:1px dashed #d1d5db;border-radius:10px;margin-bottom:10px;background:#f9fafb}
|
| 32 |
.me-pill{display:inline-flex;align-items:center;gap:6px;background:#fff3cd;color:#7a5b00;border:1px solid #ffe8a1;padding:6px 12px;border-radius:999px;font-weight:800}
|
| 33 |
.room-pill{display:inline-block;background:#e8f0fe;color:#174ea6;padding:6px 10px;border-radius:999px}
|
| 34 |
|
| 35 |
-
/* Khung chat
|
| 36 |
-
.chat-wrap{position:relative;border:1px solid #e5e7eb;border-radius:10px;overflow:hidden;background:#fff
|
| 37 |
-
#chatFrame{
|
| 38 |
-
|
| 39 |
-
/* Che cột phải (không chặn click phần chat) */
|
| 40 |
-
.mask-right{position:absolute;top:0;right:0;bottom:0;width:var(--mask-right);background:#fff;pointer-events:none;box-shadow:-8px 0 10px -10px rgba(0,0,0,.12);z-index:2}
|
| 41 |
-
|
| 42 |
-
/* Gợi ý vùng nhập ở đáy – không chặn bấm */
|
| 43 |
-
.hint-bottom{position:absolute;left:0;right:var(--mask-right);bottom:0;height:110px;pointer-events:none;z-index:1;background:radial-gradient(120% 120% at 50% 100%, rgba(26,115,232,.08) 0%, rgba(26,115,232,.03) 40%, rgba(255,255,255,0) 75%)}
|
| 44 |
|
| 45 |
-
/*
|
| 46 |
-
.mask-
|
| 47 |
-
.mask-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
/* Link phòng tự ẩn */
|
| 52 |
.links{display:none;gap:8px;align-items:center;flex-wrap:wrap;margin-top:10px}
|
|
@@ -55,7 +59,6 @@
|
|
| 55 |
/* Fallback khi iframe bị chặn */
|
| 56 |
.error-box{display:none;gap:10px;align-items:center;justify-content:space-between;padding:12px;border:1px solid #fecaca;background:#fef2f2;border-radius:10px;margin-top:10px}
|
| 57 |
.error-text{color:#991b1b}
|
| 58 |
-
|
| 59 |
.toast{position:fixed;left:50%;bottom:22px;transform:translateX(-50%);background:#111827;color:#f9fafb;border:1px solid #374151;padding:10px 14px;border-radius:10px;font-size:14px;opacity:0;pointer-events:none;transition:opacity .2s}
|
| 60 |
.toast.show{opacity:1}
|
| 61 |
footer{margin-top:auto;text-align:center;color:#6b7280;font-size:13px;padding:16px}
|
|
@@ -68,14 +71,17 @@
|
|
| 68 |
<section id="login" class="card">
|
| 69 |
<h2>Tham gia phòng chat</h2>
|
| 70 |
<p class="muted">Nhập tên → <b>Vào Chat</b> → *(tuỳ chọn)* <b>✨ Tạo phòng bí mật</b>.</p>
|
|
|
|
| 71 |
<div class="row" style="margin-top:8px">
|
| 72 |
<input id="nickname" type="text" placeholder="Nhập tên của bạn…" autocomplete="name">
|
| 73 |
<button id="joinBtn" class="btn-red">Vào Chat</button>
|
| 74 |
</div>
|
|
|
|
| 75 |
<div class="row" style="margin-top:10px">
|
| 76 |
<button id="newRoomBtn" class="btn-ghost">✨ Tạo phòng bí mật</button>
|
| 77 |
<span id="roomHint" class="muted"></span>
|
| 78 |
</div>
|
|
|
|
| 79 |
<div id="linkArea" class="links" aria-live="polite">
|
| 80 |
<span>🔗 Link phòng:</span>
|
| 81 |
<span id="roomUrl" class="link-badge mono"></span>
|
|
@@ -90,16 +96,12 @@
|
|
| 90 |
</div>
|
| 91 |
|
| 92 |
<div class="chat-wrap">
|
| 93 |
-
<!--
|
| 94 |
-
<div class="mask-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
<div class="mask-right"></div>
|
| 101 |
-
<div class="hint-bottom"></div>
|
| 102 |
-
<iframe id="chatFrame" title="tlk.io chat" referrerpolicy="no-referrer" allow="clipboard-read; clipboard-write"></iframe>
|
| 103 |
</div>
|
| 104 |
|
| 105 |
<div id="errorBox" class="error-box">
|
|
@@ -119,59 +121,43 @@
|
|
| 119 |
|
| 120 |
const $ = id => document.getElementById(id);
|
| 121 |
const els = {
|
| 122 |
-
login
|
| 123 |
-
name
|
| 124 |
-
linkArea
|
| 125 |
-
hint
|
| 126 |
-
status
|
| 127 |
-
maskVal: $("maskVal"), maskMinus: $("maskMinus"), maskPlus: $("maskPlus")
|
| 128 |
};
|
| 129 |
|
| 130 |
-
const toast = m
|
| 131 |
-
const getName = ()
|
| 132 |
-
const setName = n
|
| 133 |
-
const syncRoomUI = ()
|
| 134 |
-
const tlkUrl = n
|
| 135 |
-
|
| 136 |
-
// --- mask-top: từ URL ?mask=, hoặc localStorage, hoặc mặc định ---
|
| 137 |
-
function getMaskTopInit(){
|
| 138 |
-
const q = parseInt(qs.get("mask"),10);
|
| 139 |
-
if(!isNaN(q)) return q;
|
| 140 |
-
const saved = parseInt(localStorage.getItem("cvnss4_maskTop"),10);
|
| 141 |
-
return !isNaN(saved) ? saved : 220;
|
| 142 |
-
}
|
| 143 |
-
function applyMaskTop(px){
|
| 144 |
-
document.documentElement.style.setProperty('--mask-top', px+'px');
|
| 145 |
-
els.maskVal.textContent = px+'px';
|
| 146 |
-
localStorage.setItem("cvnss4_maskTop", String(px));
|
| 147 |
-
}
|
| 148 |
|
| 149 |
function mountChat(){
|
| 150 |
const name = getName(); setName(name); syncRoomUI();
|
| 151 |
els.status.style.display = "flex";
|
| 152 |
-
|
| 153 |
const url = tlkUrl(name);
|
| 154 |
-
els.frame.src = url; els.openNew.href = url; els.err.style.display
|
| 155 |
-
|
| 156 |
-
const timer = setTimeout(()=>{ els.err.style.display = "flex"; }, 6000);
|
| 157 |
els.frame.addEventListener("load", ()=> clearTimeout(timer), {once:true});
|
| 158 |
}
|
| 159 |
|
| 160 |
function enterChat(){
|
| 161 |
-
els.login.style.display
|
| 162 |
-
els.box.style.display
|
| 163 |
mountChat();
|
| 164 |
}
|
| 165 |
|
| 166 |
-
// Events
|
| 167 |
els.join.addEventListener("click", enterChat);
|
| 168 |
-
els.name.addEventListener("keydown", e
|
| 169 |
|
|
|
|
| 170 |
els.newRoom.addEventListener("click", async ()=>{
|
| 171 |
room = `cvnss4-0-${Math.random().toString(36).slice(2,8)}`;
|
| 172 |
syncRoomUI(); history.replaceState(null,"",`?room=${room}`);
|
| 173 |
const link = `${base}?room=${room}`;
|
| 174 |
-
els.roomUrl.textContent = link; els.linkArea.style.display
|
| 175 |
try{ await navigator.clipboard?.writeText?.(link); toast("✅ Link đã copy!"); }catch(_){}
|
| 176 |
setTimeout(()=>{ if(els.linkArea.style.display!=="none") els.linkArea.style.display="none"; }, 9000);
|
| 177 |
els.copy.onclick = async ()=>{
|
|
@@ -180,17 +166,11 @@
|
|
| 180 |
if(navigator.share){ try{ await navigator.share({title:"Phòng chat CVNSS4.0", url:link}); }catch(_){} }
|
| 181 |
toast("✅ Đã copy link phòng!");
|
| 182 |
}catch(_){ toast("⚠️ Không copy được—hãy copy thủ công"); }
|
| 183 |
-
els.linkArea.style.display
|
| 184 |
};
|
| 185 |
});
|
| 186 |
|
| 187 |
-
//
|
| 188 |
-
let maskTop = getMaskTopInit();
|
| 189 |
-
applyMaskTop(maskTop);
|
| 190 |
-
els.maskMinus.onclick = ()=>{ maskTop = Math.max(100, maskTop-10); applyMaskTop(maskTop); };
|
| 191 |
-
els.maskPlus.onclick = ()=>{ maskTop = Math.min(400, maskTop+10); applyMaskTop(maskTop); };
|
| 192 |
-
|
| 193 |
-
// Prefill + auto-enter
|
| 194 |
const last = localStorage.getItem("cvnss4_name"); if(last) els.name.value = last;
|
| 195 |
syncRoomUI(); els.name.focus({preventScroll:true});
|
| 196 |
if (qs.get("room") && (last || els.name.value.trim() !== "")) enterChat();
|
|
|
|
| 6 |
<title>Chat CVNSS4.0</title>
|
| 7 |
<style>
|
| 8 |
:root{
|
| 9 |
+
/* Giao diện sáng, tối giản */
|
| 10 |
+
--bg:#f7f9fc; --card:#ffffff; --text:#1f2937; --muted:#6b7280;
|
| 11 |
--primary:#1a73e8; --danger:#d93025; --accent:#ffeb3b;
|
| 12 |
+
/* Kích thước mask (che phần đầu + cột phải của tlk.io) */
|
| 13 |
+
--mask-top: 210px; /* ẨN icon mây + thanh xanh tiêu đề */
|
| 14 |
+
--mask-right: clamp(220px, 24vw, 300px); /* ẨN panel phải */
|
| 15 |
}
|
| 16 |
*{box-sizing:border-box}
|
| 17 |
+
body{
|
| 18 |
+
margin:0; font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
|
| 19 |
+
background:var(--bg); color:var(--text); display:flex; flex-direction:column; min-height:100vh;
|
| 20 |
+
}
|
| 21 |
header{padding:14px 16px;text-align:center;font-weight:700;background:#fff;border-bottom:1px solid #e5e7eb}
|
| 22 |
+
.card{
|
| 23 |
+
width:min(980px,94vw); margin:22px auto; background:var(--card);
|
| 24 |
+
border:1px solid #e5e7eb; border-radius:12px; box-shadow:0 6px 18px rgba(0,0,0,.06); padding:18px;
|
| 25 |
+
}
|
| 26 |
h2{margin:0 0 6px} .muted{color:var(--muted)}
|
| 27 |
.row{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
|
| 28 |
input[type=text]{flex:1 1 260px;padding:12px 14px;font-size:16px;border:1px solid #d1d5db;border-radius:10px}
|
| 29 |
input[type=text]:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px rgba(26,115,232,.15)}
|
| 30 |
button{padding:12px 16px;border:0;border-radius:10px;font-weight:700;cursor:pointer}
|
| 31 |
+
.btn-red{background:#d93025;color:#ffeb3b}
|
| 32 |
.btn-ghost{background:#eef2ff;color:#1e3a8a}
|
| 33 |
.btn-secondary{background:#374151;color:#fff}
|
| 34 |
.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
| 35 |
|
| 36 |
+
/* Trạng thái gọn */
|
| 37 |
.status{display:none;align-items:center;gap:10px;padding:10px 12px;border:1px dashed #d1d5db;border-radius:10px;margin-bottom:10px;background:#f9fafb}
|
| 38 |
.me-pill{display:inline-flex;align-items:center;gap:6px;background:#fff3cd;color:#7a5b00;border:1px solid #ffe8a1;padding:6px 12px;border-radius:999px;font-weight:800}
|
| 39 |
.room-pill{display:inline-block;background:#e8f0fe;color:#174ea6;padding:6px 10px;border-radius:999px}
|
| 40 |
|
| 41 |
+
/* Khung chat */
|
| 42 |
+
.chat-wrap{position:relative;border:1px solid #e5e7eb;border-radius:10px;overflow:hidden;background:#fff}
|
| 43 |
+
iframe#chatFrame{width:100%;height:72vh;min-height:640px;border:0;background:#fff}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
/* MASK trắng: chặn mọi click/selection trong vùng che */
|
| 46 |
+
.mask-top,
|
| 47 |
+
.mask-right{
|
| 48 |
+
position:absolute; background:#fff; z-index:5;
|
| 49 |
+
pointer-events:auto; /* chặn click vào phần bị che */
|
| 50 |
+
user-select:none; /* không cho bôi/copy */
|
| 51 |
+
}
|
| 52 |
+
.mask-top{left:0; right:0; top:0; height:var(--mask-top); box-shadow:0 8px 10px -10px rgba(0,0,0,.12)}
|
| 53 |
+
.mask-right{top:0; right:0; bottom:0; width:var(--mask-right); box-shadow:-8px 0 10px -10px rgba(0,0,0,.12)}
|
| 54 |
|
| 55 |
/* Link phòng tự ẩn */
|
| 56 |
.links{display:none;gap:8px;align-items:center;flex-wrap:wrap;margin-top:10px}
|
|
|
|
| 59 |
/* Fallback khi iframe bị chặn */
|
| 60 |
.error-box{display:none;gap:10px;align-items:center;justify-content:space-between;padding:12px;border:1px solid #fecaca;background:#fef2f2;border-radius:10px;margin-top:10px}
|
| 61 |
.error-text{color:#991b1b}
|
|
|
|
| 62 |
.toast{position:fixed;left:50%;bottom:22px;transform:translateX(-50%);background:#111827;color:#f9fafb;border:1px solid #374151;padding:10px 14px;border-radius:10px;font-size:14px;opacity:0;pointer-events:none;transition:opacity .2s}
|
| 63 |
.toast.show{opacity:1}
|
| 64 |
footer{margin-top:auto;text-align:center;color:#6b7280;font-size:13px;padding:16px}
|
|
|
|
| 71 |
<section id="login" class="card">
|
| 72 |
<h2>Tham gia phòng chat</h2>
|
| 73 |
<p class="muted">Nhập tên → <b>Vào Chat</b> → *(tuỳ chọn)* <b>✨ Tạo phòng bí mật</b>.</p>
|
| 74 |
+
|
| 75 |
<div class="row" style="margin-top:8px">
|
| 76 |
<input id="nickname" type="text" placeholder="Nhập tên của bạn…" autocomplete="name">
|
| 77 |
<button id="joinBtn" class="btn-red">Vào Chat</button>
|
| 78 |
</div>
|
| 79 |
+
|
| 80 |
<div class="row" style="margin-top:10px">
|
| 81 |
<button id="newRoomBtn" class="btn-ghost">✨ Tạo phòng bí mật</button>
|
| 82 |
<span id="roomHint" class="muted"></span>
|
| 83 |
</div>
|
| 84 |
+
|
| 85 |
<div id="linkArea" class="links" aria-live="polite">
|
| 86 |
<span>🔗 Link phòng:</span>
|
| 87 |
<span id="roomUrl" class="link-badge mono"></span>
|
|
|
|
| 96 |
</div>
|
| 97 |
|
| 98 |
<div class="chat-wrap">
|
| 99 |
+
<!-- MASK trắng: che gọn icon mây + thanh xanh + panel phải -->
|
| 100 |
+
<div class="mask-top" aria-hidden="true"></div>
|
| 101 |
+
<div class="mask-right" aria-hidden="true"></div>
|
| 102 |
+
|
| 103 |
+
<iframe id="chatFrame" title="tlk.io chat" referrerpolicy="no-referrer"
|
| 104 |
+
allow="clipboard-read; clipboard-write"></iframe>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
</div>
|
| 106 |
|
| 107 |
<div id="errorBox" class="error-box">
|
|
|
|
| 121 |
|
| 122 |
const $ = id => document.getElementById(id);
|
| 123 |
const els = {
|
| 124 |
+
login:$("login"), box:$("chatBox"), frame:$("chatFrame"),
|
| 125 |
+
name:$("nickname"), join:$("joinBtn"), newRoom:$("newRoomBtn"),
|
| 126 |
+
linkArea:$("linkArea"), roomUrl:$("roomUrl"), copy:$("copyBtn"),
|
| 127 |
+
hint:$("roomHint"), me:$("meName"), pill:$("roomPill"),
|
| 128 |
+
status:$("statusBar"), toast:$("toast"), err:$("errorBox"), openNew:$("openNew")
|
|
|
|
| 129 |
};
|
| 130 |
|
| 131 |
+
const toast = m=>{ els.toast.textContent=m; els.toast.classList.add("show"); setTimeout(()=>els.toast.classList.remove("show"),1400); };
|
| 132 |
+
const getName = ()=> (els.name.value || localStorage.getItem("cvnss4_name") || "Guest").trim() || "Guest";
|
| 133 |
+
const setName = n=>{ els.me.textContent=n; localStorage.setItem("cvnss4_name", n); };
|
| 134 |
+
const syncRoomUI = ()=>{ els.pill.textContent=room; els.hint.textContent=`(đang ở phòng ${room})`; };
|
| 135 |
+
const tlkUrl = n=> `https://tlk.io/${encodeURIComponent(room)}?nickname=${encodeURIComponent(n)}#embed`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
function mountChat(){
|
| 138 |
const name = getName(); setName(name); syncRoomUI();
|
| 139 |
els.status.style.display = "flex";
|
|
|
|
| 140 |
const url = tlkUrl(name);
|
| 141 |
+
els.frame.src = url; els.openNew.href = url; els.err.style.display="none";
|
| 142 |
+
const timer = setTimeout(()=>{ els.err.style.display="flex"; }, 6000);
|
|
|
|
| 143 |
els.frame.addEventListener("load", ()=> clearTimeout(timer), {once:true});
|
| 144 |
}
|
| 145 |
|
| 146 |
function enterChat(){
|
| 147 |
+
els.login.style.display="none";
|
| 148 |
+
els.box.style.display="block";
|
| 149 |
mountChat();
|
| 150 |
}
|
| 151 |
|
|
|
|
| 152 |
els.join.addEventListener("click", enterChat);
|
| 153 |
+
els.name.addEventListener("keydown", e=>{ if(e.key==="Enter") enterChat(); });
|
| 154 |
|
| 155 |
+
// Tạo phòng bí mật + copy tự ẩn
|
| 156 |
els.newRoom.addEventListener("click", async ()=>{
|
| 157 |
room = `cvnss4-0-${Math.random().toString(36).slice(2,8)}`;
|
| 158 |
syncRoomUI(); history.replaceState(null,"",`?room=${room}`);
|
| 159 |
const link = `${base}?room=${room}`;
|
| 160 |
+
els.roomUrl.textContent = link; els.linkArea.style.display="flex";
|
| 161 |
try{ await navigator.clipboard?.writeText?.(link); toast("✅ Link đã copy!"); }catch(_){}
|
| 162 |
setTimeout(()=>{ if(els.linkArea.style.display!=="none") els.linkArea.style.display="none"; }, 9000);
|
| 163 |
els.copy.onclick = async ()=>{
|
|
|
|
| 166 |
if(navigator.share){ try{ await navigator.share({title:"Phòng chat CVNSS4.0", url:link}); }catch(_){} }
|
| 167 |
toast("✅ Đã copy link phòng!");
|
| 168 |
}catch(_){ toast("⚠️ Không copy được—hãy copy thủ công"); }
|
| 169 |
+
els.linkArea.style.display="none";
|
| 170 |
};
|
| 171 |
});
|
| 172 |
|
| 173 |
+
// Prefill + auto-enter khi đã có tên
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
const last = localStorage.getItem("cvnss4_name"); if(last) els.name.value = last;
|
| 175 |
syncRoomUI(); els.name.focus({preventScroll:true});
|
| 176 |
if (qs.get("room") && (last || els.name.value.trim() !== "")) enterChat();
|