Update index.html
Browse files- index.html +77 -115
index.html
CHANGED
|
@@ -6,76 +6,52 @@
|
|
| 6 |
<title>Chat CVNSS4.0</title>
|
| 7 |
<style>
|
| 8 |
:root{
|
| 9 |
-
|
|
|
|
| 10 |
--primary:#1a73e8; --danger:#d93025; --accent:#ffeb3b;
|
| 11 |
-
/*
|
| 12 |
-
--ov-top:
|
| 13 |
-
--ov-right:
|
| 14 |
}
|
| 15 |
*{box-sizing:border-box}
|
| 16 |
-
body{
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
.
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
.
|
| 28 |
-
.
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
.
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
.
|
| 43 |
-
|
| 44 |
-
.
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
.
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
.ov-top{
|
| 55 |
-
position:absolute; left:0; right:0; top:0; height:var(--ov-top);
|
| 56 |
-
background:var(--card); z-index:3; pointer-events:none;
|
| 57 |
-
box-shadow:0 10px 12px -10px rgba(0,0,0,.6);
|
| 58 |
-
}
|
| 59 |
-
.ov-right{
|
| 60 |
-
position:absolute; top:0; right:0; bottom:0; width:var(--ov-right);
|
| 61 |
-
background:var(--card); z-index:2; pointer-events:none;
|
| 62 |
-
box-shadow:-10px 0 12px -10px rgba(0,0,0,.6);
|
| 63 |
-
}
|
| 64 |
-
/* Glow nhẹ ở đáy để “gợi ý” chỗ gõ — không che click */
|
| 65 |
-
.focus-bottom{
|
| 66 |
-
position:absolute; left:0; right:var(--ov-right); bottom:0; height:128px; pointer-events:none; z-index:1;
|
| 67 |
-
background:radial-gradient(120% 120% at 50% 100%, rgba(255,235,59,.16) 0%, rgba(255,235,59,.08) 40%, rgba(0,0,0,0) 72%);
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
.links{ display:none; gap:8px; align-items:center; flex-wrap:wrap; margin-top:10px }
|
| 71 |
-
.link-badge{ background:#0b1220; border:1px solid #223047; color:#b6c2d2; padding:6px 8px; border-radius:8px }
|
| 72 |
-
.toast{ position:fixed; left:50%; bottom:22px; transform:translateX(-50%); background:#111827; color:#e5e7eb;
|
| 73 |
-
border:1px solid #374151; padding:10px 14px; border-radius:10px; font-size:14px; opacity:0; pointer-events:none; transition:opacity .2s }
|
| 74 |
-
.toast.show{ opacity:1 }
|
| 75 |
-
|
| 76 |
-
footer{ margin-top:auto; text-align:center; color:#8b9bb1; font-size:13px; padding:16px }
|
| 77 |
-
ol.guide{ margin:0; padding-left:20px } ol.guide li{ margin:6px 0 }
|
| 78 |
-
@media (max-width:820px){ :root{ --ov-right:0px } } /* mobile: tlk.io thường không có panel phải */
|
| 79 |
</style>
|
| 80 |
</head>
|
| 81 |
<body>
|
|
@@ -83,11 +59,12 @@
|
|
| 83 |
|
| 84 |
<section id="login" class="card">
|
| 85 |
<h2>Tham gia phòng chat</h2>
|
| 86 |
-
<p class="muted">
|
|
|
|
| 87 |
<ol class="guide">
|
| 88 |
-
<li
|
| 89 |
-
<li>Nhấn <b>Vào Chat</b> (nút đỏ).
|
| 90 |
-
<li><b>✨ Tạo phòng bí mật</b> nếu cần (ID ngẫu nhiên + Copy
|
| 91 |
</ol>
|
| 92 |
|
| 93 |
<div class="row" style="margin-top:12px">
|
|
@@ -112,10 +89,10 @@
|
|
| 112 |
<span class="me-pill">👤 <span id="meName">Guest</span></span>
|
| 113 |
<span class="room-pill">Phòng: <span id="roomPill" class="mono"></span></span>
|
| 114 |
</div>
|
| 115 |
-
<div class="chat-wrap">
|
| 116 |
-
<!--
|
| 117 |
-
<div class="ov-top"
|
| 118 |
-
<div class="ov-right"
|
| 119 |
<div class="focus-bottom"></div>
|
| 120 |
<!-- mount cho embed hoặc iframe -->
|
| 121 |
<div id="chatMount"></div>
|
|
@@ -127,15 +104,15 @@
|
|
| 127 |
|
| 128 |
<script>
|
| 129 |
(() => {
|
| 130 |
-
//
|
| 131 |
const qs = new URLSearchParams(location.search);
|
| 132 |
let room = (qs.get("room") || "cvnss4-0").trim().toLowerCase();
|
| 133 |
const base = `${location.origin}${location.pathname}`;
|
| 134 |
-
const debug = qs.get("debug")==="1"; // ?debug=1 để tắt overlay khi test
|
| 135 |
|
| 136 |
const els = {
|
| 137 |
login: document.getElementById("login"),
|
| 138 |
chatBox: document.getElementById("chatBox"),
|
|
|
|
| 139 |
mount: document.getElementById("chatMount"),
|
| 140 |
name: document.getElementById("nickname"),
|
| 141 |
join: document.getElementById("joinBtn"),
|
|
@@ -148,68 +125,54 @@
|
|
| 148 |
roomPill: document.getElementById("roomPill"),
|
| 149 |
status: document.getElementById("statusBar"),
|
| 150 |
toast: document.getElementById("toast"),
|
| 151 |
-
ovTop: document.getElementById("ovTop"),
|
| 152 |
-
ovRight: document.getElementById("ovRight"),
|
| 153 |
};
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
| 160 |
|
| 161 |
-
//
|
| 162 |
-
if (debug){ els.ovTop.style.display="none"; els.ovRight.style.display="none"; }
|
| 163 |
-
|
| 164 |
-
// ======== Renderer A: embed.js (ưu tiên) ========
|
| 165 |
function renderEmbed(name){
|
| 166 |
clearMount();
|
|
|
|
| 167 |
const holder = document.createElement("div");
|
| 168 |
holder.id = "tlkio";
|
| 169 |
holder.dataset.channel = room;
|
| 170 |
holder.dataset.nickname = name;
|
| 171 |
-
holder.dataset.theme = "theme--day";
|
| 172 |
-
holder.style.minHeight = "
|
| 173 |
els.mount.appendChild(holder);
|
| 174 |
|
| 175 |
const s = document.createElement("script");
|
| 176 |
-
s.async = true;
|
| 177 |
-
|
| 178 |
-
let
|
| 179 |
-
s.onload = ()
|
| 180 |
-
s.onerror = ()
|
| 181 |
els.mount.appendChild(s);
|
| 182 |
}
|
| 183 |
|
| 184 |
-
// ======== Renderer B: iframe (fallback) ========
|
| 185 |
function renderIframe(name){
|
| 186 |
clearMount();
|
|
|
|
| 187 |
const url = `https://tlk.io/${encodeURIComponent(room)}?nickname=${encodeURIComponent(name)}#embed`;
|
| 188 |
const ifr = document.createElement("iframe");
|
| 189 |
-
ifr.title = "tlk.io chat";
|
| 190 |
-
ifr.src = url;
|
| 191 |
-
ifr.referrerPolicy = "no-referrer";
|
| 192 |
-
// Nếu iframe không tải được trong 6s → nhắc kiểm tra mạng/CSP
|
| 193 |
-
let watch = setTimeout(() => {
|
| 194 |
-
const warn = document.createElement("div");
|
| 195 |
-
warn.style.padding = "16px"; warn.style.color = "#ffd166";
|
| 196 |
-
warn.textContent = "⚠️ Không tải được khung chat. Thử mở trang này trong cửa sổ mới hoặc bật cho phép nội dung bên thứ ba.";
|
| 197 |
-
els.mount.appendChild(warn);
|
| 198 |
-
}, 6000);
|
| 199 |
-
ifr.addEventListener("load", ()=> clearTimeout(watch));
|
| 200 |
els.mount.appendChild(ifr);
|
| 201 |
}
|
| 202 |
|
| 203 |
function renderChat(){
|
| 204 |
const name = getName();
|
| 205 |
-
setName(name);
|
| 206 |
-
syncRoomUI();
|
| 207 |
els.status.style.display = "flex";
|
| 208 |
-
renderEmbed(name);
|
| 209 |
-
setTimeout(()=> els.chatBox.scrollIntoView({behavior:"smooth"
|
| 210 |
}
|
| 211 |
|
| 212 |
-
//
|
| 213 |
function enterChat(){
|
| 214 |
els.login.style.display = "none";
|
| 215 |
els.chatBox.style.display = "block";
|
|
@@ -219,7 +182,6 @@
|
|
| 219 |
els.join.addEventListener("click", enterChat);
|
| 220 |
els.name.addEventListener("keydown", e => { if(e.key === "Enter") enterChat(); });
|
| 221 |
|
| 222 |
-
// Tạo phòng bí mật
|
| 223 |
els.newRoom.addEventListener("click", async ()=>{
|
| 224 |
room = `cvnss4-0-${Math.random().toString(36).slice(2,8)}`;
|
| 225 |
syncRoomUI();
|
|
@@ -230,7 +192,7 @@
|
|
| 230 |
els.linkArea.style.display = "flex";
|
| 231 |
|
| 232 |
try{ await navigator.clipboard?.writeText?.(link); toast("✅ Link đã copy!"); }catch(_){}
|
| 233 |
-
setTimeout(()=>{ if(els.linkArea.style.display!=="none") els.linkArea.style.display="none"; },
|
| 234 |
|
| 235 |
els.copy.onclick = async ()=>{
|
| 236 |
try{
|
|
@@ -242,7 +204,7 @@
|
|
| 242 |
};
|
| 243 |
});
|
| 244 |
|
| 245 |
-
// Prefill
|
| 246 |
const last = localStorage.getItem("cvnss4_name"); if(last) els.name.value = last;
|
| 247 |
syncRoomUI(); els.name.focus({preventScroll:true});
|
| 248 |
})();
|
|
|
|
| 6 |
<title>Chat CVNSS4.0</title>
|
| 7 |
<style>
|
| 8 |
:root{
|
| 9 |
+
/* Light theme */
|
| 10 |
+
--bg:#f7f9fc; --card:#ffffff; --text:#1f2937; --muted:#6b7280;
|
| 11 |
--primary:#1a73e8; --danger:#d93025; --accent:#ffeb3b;
|
| 12 |
+
/* Overlays (chỉ dùng cho iframe) */
|
| 13 |
+
--ov-top:140px; /* che header/#channel; tăng nếu còn hở */
|
| 14 |
+
--ov-right:clamp(220px,24vw,300px); /* che panel phải */
|
| 15 |
}
|
| 16 |
*{box-sizing:border-box}
|
| 17 |
+
body{margin:0;font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
|
| 18 |
+
background:var(--bg);color:var(--text);display:flex;flex-direction:column;min-height:100vh}
|
| 19 |
+
header{padding:14px 16px;text-align:center;font-weight:700;background:#ffffff;border-bottom:1px solid #e5e7eb}
|
| 20 |
+
.card{width:min(980px,94vw);margin:22px auto;background:var(--card);border:1px solid #e5e7eb;border-radius:12px;box-shadow:0 6px 18px rgba(0,0,0,.06);padding:18px}
|
| 21 |
+
h2{margin:0 0 6px}
|
| 22 |
+
.muted{color:var(--muted)}
|
| 23 |
+
.row{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
|
| 24 |
+
input[type=text]{flex:1 1 260px;padding:12px 14px;font-size:16px;border:1px solid #d1d5db;border-radius:10px}
|
| 25 |
+
input[type=text]:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px rgba(26,115,232,.15)}
|
| 26 |
+
button{padding:12px 16px;border:0;border-radius:10px;font-weight:700;cursor:pointer}
|
| 27 |
+
.btn-red{background:var(--danger);color:var(--accent)}
|
| 28 |
+
.btn-ghost{background:#eef2ff;color:#1e3a8a}
|
| 29 |
+
.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
| 30 |
+
|
| 31 |
+
/* Trạng thái: tên + phòng (gọn) */
|
| 32 |
+
.status{display:none;align-items:center;gap:10px;padding:10px 12px;border:1px dashed #d1d5db;border-radius:10px;margin-bottom:10px;background:#f9fafb}
|
| 33 |
+
.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}
|
| 34 |
+
.room-pill{display:inline-block;background:#e8f0fe;color:#174ea6;padding:6px 10px;border-radius:999px}
|
| 35 |
+
|
| 36 |
+
/* Khung chat */
|
| 37 |
+
.chat-wrap{position:relative;border:1px solid #e5e7eb;border-radius:10px;overflow:hidden;background:#fff}
|
| 38 |
+
#chatMount{min-height:560px}
|
| 39 |
+
iframe{width:100%;height:72vh;min-height:560px;border:0;background:#fff}
|
| 40 |
+
|
| 41 |
+
/* Overlays – chỉ thêm khi ở chế độ iframe */
|
| 42 |
+
.ov-top,.ov-right,.focus-bottom{display:none} /* mặc định ẩn (embed không cần) */
|
| 43 |
+
.iframe-mode .ov-top{display:block;position:absolute;left:0;right:0;top:0;height:var(--ov-top);background:#fff;z-index:3;pointer-events:none;box-shadow:0 8px 10px -10px rgba(0,0,0,.12)}
|
| 44 |
+
.iframe-mode .ov-right{display:block;position:absolute;top:0;right:0;bottom:0;width:var(--ov-right);background:#fff;z-index:2;pointer-events:none;box-shadow:-8px 0 10px -10px rgba(0,0,0,.12)}
|
| 45 |
+
.iframe-mode .focus-bottom{display:block;position:absolute;left:0;right:var(--ov-right);bottom:0;height:110px;pointer-events:none;z-index:1;
|
| 46 |
+
background:radial-gradient(120% 120% at 50% 100%, rgba(26,115,232,.12) 0%, rgba(26,115,232,.05) 40%, rgba(255,255,255,0) 75%)}
|
| 47 |
+
|
| 48 |
+
.links{display:none;gap:8px;align-items:center;flex-wrap:wrap;margin-top:10px}
|
| 49 |
+
.link-badge{background:#f3f4f6;border:1px solid #e5e7eb;color:#111827;padding:6px 8px;border-radius:8px}
|
| 50 |
+
.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}
|
| 51 |
+
.toast.show{opacity:1}
|
| 52 |
+
footer{margin-top:auto;text-align:center;color:#6b7280;font-size:13px;padding:16px}
|
| 53 |
+
ol.guide{margin:0;padding-left:20px} ol.guide li{margin:6px 0}
|
| 54 |
+
@media (max-width:820px){ :root{ --ov-right:0px } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
</style>
|
| 56 |
</head>
|
| 57 |
<body>
|
|
|
|
| 59 |
|
| 60 |
<section id="login" class="card">
|
| 61 |
<h2>Tham gia phòng chat</h2>
|
| 62 |
+
<p class="muted">Nhập tên → <b>Vào Chat</b> → *(tuỳ chọn)* <b>✨ Tạo phòng bí mật</b> để mời người khác.</p>
|
| 63 |
+
|
| 64 |
<ol class="guide">
|
| 65 |
+
<li>Nhập tên ở ô dưới.</li>
|
| 66 |
+
<li>Nhấn <b>Vào Chat</b> (nút đỏ). Form Join bên trong tlk.io luôn bị ẩn.</li>
|
| 67 |
+
<li><b>✨ Tạo phòng bí mật</b> nếu cần (ID ngẫu nhiên + Copy tự ẩn). <span class="muted">Không cần thì bỏ qua.</span></li>
|
| 68 |
</ol>
|
| 69 |
|
| 70 |
<div class="row" style="margin-top:12px">
|
|
|
|
| 89 |
<span class="me-pill">👤 <span id="meName">Guest</span></span>
|
| 90 |
<span class="room-pill">Phòng: <span id="roomPill" class="mono"></span></span>
|
| 91 |
</div>
|
| 92 |
+
<div id="chatWrap" class="chat-wrap">
|
| 93 |
+
<!-- Overlays chỉ bật khi dùng iframe -->
|
| 94 |
+
<div class="ov-top"></div>
|
| 95 |
+
<div class="ov-right"></div>
|
| 96 |
<div class="focus-bottom"></div>
|
| 97 |
<!-- mount cho embed hoặc iframe -->
|
| 98 |
<div id="chatMount"></div>
|
|
|
|
| 104 |
|
| 105 |
<script>
|
| 106 |
(() => {
|
| 107 |
+
// ====== State ======
|
| 108 |
const qs = new URLSearchParams(location.search);
|
| 109 |
let room = (qs.get("room") || "cvnss4-0").trim().toLowerCase();
|
| 110 |
const base = `${location.origin}${location.pathname}`;
|
|
|
|
| 111 |
|
| 112 |
const els = {
|
| 113 |
login: document.getElementById("login"),
|
| 114 |
chatBox: document.getElementById("chatBox"),
|
| 115 |
+
wrap: document.getElementById("chatWrap"),
|
| 116 |
mount: document.getElementById("chatMount"),
|
| 117 |
name: document.getElementById("nickname"),
|
| 118 |
join: document.getElementById("joinBtn"),
|
|
|
|
| 125 |
roomPill: document.getElementById("roomPill"),
|
| 126 |
status: document.getElementById("statusBar"),
|
| 127 |
toast: document.getElementById("toast"),
|
|
|
|
|
|
|
| 128 |
};
|
| 129 |
|
| 130 |
+
// ====== Helpers ======
|
| 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.meName.textContent=n; localStorage.setItem("cvnss4_name", n); };
|
| 134 |
+
const syncRoomUI = ()=>{ els.roomPill.textContent=room; els.hint.textContent=`(đang ở phòng ${room})`; };
|
| 135 |
+
const clearMount = ()=> els.mount.replaceChildren();
|
| 136 |
|
| 137 |
+
// ====== Renderers ======
|
|
|
|
|
|
|
|
|
|
| 138 |
function renderEmbed(name){
|
| 139 |
clearMount();
|
| 140 |
+
els.wrap.classList.remove("iframe-mode"); // không cần overlay
|
| 141 |
const holder = document.createElement("div");
|
| 142 |
holder.id = "tlkio";
|
| 143 |
holder.dataset.channel = room;
|
| 144 |
holder.dataset.nickname = name;
|
| 145 |
+
holder.dataset.theme = "theme--day"; // sáng
|
| 146 |
+
holder.style.minHeight = "560px";
|
| 147 |
els.mount.appendChild(holder);
|
| 148 |
|
| 149 |
const s = document.createElement("script");
|
| 150 |
+
s.async = true; s.src = "https://tlk.io/embed.js";
|
| 151 |
+
// fallback nếu bị chặn
|
| 152 |
+
let t = setTimeout(()=>{ renderIframe(name); }, 3500);
|
| 153 |
+
s.onload = ()=> clearTimeout(t);
|
| 154 |
+
s.onerror = ()=> { clearTimeout(t); renderIframe(name); };
|
| 155 |
els.mount.appendChild(s);
|
| 156 |
}
|
| 157 |
|
|
|
|
| 158 |
function renderIframe(name){
|
| 159 |
clearMount();
|
| 160 |
+
els.wrap.classList.add("iframe-mode"); // bật overlay để ẩn header + cột phải
|
| 161 |
const url = `https://tlk.io/${encodeURIComponent(room)}?nickname=${encodeURIComponent(name)}#embed`;
|
| 162 |
const ifr = document.createElement("iframe");
|
| 163 |
+
ifr.title = "tlk.io chat"; ifr.src = url; ifr.referrerPolicy = "no-referrer";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
els.mount.appendChild(ifr);
|
| 165 |
}
|
| 166 |
|
| 167 |
function renderChat(){
|
| 168 |
const name = getName();
|
| 169 |
+
setName(name); syncRoomUI();
|
|
|
|
| 170 |
els.status.style.display = "flex";
|
| 171 |
+
renderEmbed(name); // sẽ tự fallback sang iframe nếu cần
|
| 172 |
+
setTimeout(()=> els.chatBox.scrollIntoView({behavior:"smooth"}), 40);
|
| 173 |
}
|
| 174 |
|
| 175 |
+
// ====== Actions ======
|
| 176 |
function enterChat(){
|
| 177 |
els.login.style.display = "none";
|
| 178 |
els.chatBox.style.display = "block";
|
|
|
|
| 182 |
els.join.addEventListener("click", enterChat);
|
| 183 |
els.name.addEventListener("keydown", e => { if(e.key === "Enter") enterChat(); });
|
| 184 |
|
|
|
|
| 185 |
els.newRoom.addEventListener("click", async ()=>{
|
| 186 |
room = `cvnss4-0-${Math.random().toString(36).slice(2,8)}`;
|
| 187 |
syncRoomUI();
|
|
|
|
| 192 |
els.linkArea.style.display = "flex";
|
| 193 |
|
| 194 |
try{ await navigator.clipboard?.writeText?.(link); toast("✅ Link đã copy!"); }catch(_){}
|
| 195 |
+
setTimeout(()=>{ if(els.linkArea.style.display!=="none") els.linkArea.style.display="none"; }, 9000);
|
| 196 |
|
| 197 |
els.copy.onclick = async ()=>{
|
| 198 |
try{
|
|
|
|
| 204 |
};
|
| 205 |
});
|
| 206 |
|
| 207 |
+
// Prefill
|
| 208 |
const last = localStorage.getItem("cvnss4_name"); if(last) els.name.value = last;
|
| 209 |
syncRoomUI(); els.name.focus({preventScroll:true});
|
| 210 |
})();
|