Spaces:
Paused
Paused
Download index.html from myott/ott-player: direct link, hf CLI and curl.
- Browser
- Download file 220 kB
-
https://huggingface.co/spaces/myott/ott-player/resolve/main/index.html
- Command line
-
hf download hf://spaces/myott/ott-player/index.html
-
curl -L -o index.html https://huggingface.co/spaces/myott/ott-player/resolve/main/index.html
220 kB
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover" />
<meta name="theme-color" content="#0f1115" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<title>OTT Player</title>
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="manifest" href="/manifest.webmanifest">
<meta name="theme-color" content="#0f1115">
<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin>
<link rel="preload" href="https://cdn.jsdelivr.net/npm/hls.js@1.5.15/dist/hls.min.js" as="script" crossorigin>
<script src="https://cdn.jsdelivr.net/npm/hls.js@1.5.15/dist/hls.min.js" defer></script>
<link rel="apple-touch-icon" href="/favicon.svg" />
<style>
:root {
--bg: #0f1115;
--panel: #161a22;
--panel2: #1d222c;
--border: #2a313d;
--text: #e6e8ec;
--muted: #8a93a6;
--accent: #ff5b6a;
--accent2: #4ea1ff;
--new: #ffb020;
--safe-top: env(safe-area-inset-top, 0px);
--safe-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
overscroll-behavior: none; }
body { min-height: 100dvh; }
button { font-family: inherit; }
input { font-family: inherit; font-size: 16px; /* iOS ์ค ๋ฐฉ์ง */ }
/* โโโโโ ๊ณตํต ํผ/๋ฒํผ โโโโโ */
.btn { background: var(--panel2); border: 1px solid var(--border); color: var(--text);
border-radius: 8px; padding: 8px 12px; font-size: 13px; cursor: pointer; }
.btn:active { background: #2a313d; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: #e34758; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 8px 10px; min-width: 38px; }
input.text { background: var(--panel2); border: 1px solid var(--border); color: var(--text);
border-radius: 8px; padding: 8px 12px; outline: none; width: 100%; }
input.text:focus { border-color: var(--accent2); }
/* โโโโโ ์๋จ ์ฑ๋ฐ โโโโโ */
.appbar { position: sticky; top: 0; z-index: 30; background: var(--panel);
border-bottom: 1px solid var(--border);
padding: calc(8px + var(--safe-top)) 10px 8px;
display: flex; align-items: center; gap: 8px; }
.appbar h1 { margin: 0; font-size: 15px; flex: 1; min-width: 0; overflow: hidden;
text-overflow: ellipsis; white-space: nowrap; }
.appbar h1 small { color: var(--muted); font-weight: normal; font-size: 11px; margin-left: 6px; }
.appbar .domain { font-size: 10px; color: #6ee7a8; }
.appbar .domain.bad { color: #ff7b7b; }
/* โโโโโ ๋น๋์ค โโโโโ */
.video-wrap { position: relative; background: #000; width: 100%; aspect-ratio: 16/9; }
.video-wrap.fill { aspect-ratio: auto; height: 100%; flex: 1; }
video { width: 100%; height: 100%; background: #000; display: block; }
.video-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
color: var(--muted); font-size: 13px; padding: 16px; text-align: center; pointer-events: none; }
.video-empty.hide { display: none; }
.video-loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
color: var(--accent2); font-size: 13px; background: rgba(0,0,0,0.6); padding: 8px 12px; border-radius: 6px; }
/* ์๋จ ํ์ด์ง ๋ก๋ฉ ๋ฐ โ ๋ณด๊ดํจ ํด๋ฆญ ํ episodes/play ๋ก๋ ํ
์ ํ์ */
#topLoader { position: fixed; top: 0; left: 0; right: 0; height: 3px;
background: transparent; z-index: 9999; pointer-events: none;
opacity: 0; transition: opacity 0.2s; }
#topLoader.show { opacity: 1; }
#topLoader::before { content: ''; display: block; height: 100%;
background: linear-gradient(90deg, transparent, var(--accent), var(--accent), transparent);
background-size: 50% 100%; background-repeat: no-repeat;
animation: topLoaderSlide 1s linear infinite;
box-shadow: 0 0 8px var(--accent); }
@keyframes topLoaderSlide {
0% { background-position: -50% 0; }
100% { background-position: 150% 0; }
}
.rate-toast { position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
background: rgba(0,0,0,0.75); color: #fff; padding: 8px 18px; border-radius: 999px;
font-size: 20px; font-weight: 800; font-family: "Bebas Neue", sans-serif;
letter-spacing: 0.05em; opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 6; }
.rate-toast.show { opacity: 1; }
/* ์ผ์์ ์ง ์ค๋ฒ๋ ์ด โ ๊ฐ์ด๋ฐ ํฐ ์ฌ์๋ฒํผ */
.pause-overlay {
position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
width: 96px; height: 96px; border-radius: 50%;
background: rgba(0,0,0,0.6); border: 2px solid rgba(255,255,255,0.3);
color: #fff; font-size: 40px; padding-left: 6px;
display: flex; align-items: center; justify-content: center;
cursor: pointer; z-index: 4; backdrop-filter: blur(6px);
transition: transform 0.15s, background 0.15s;
animation: pauseAppear 0.25s ease-out;
}
.pause-overlay:hover { transform: translate(-50%, -50%) scale(1.08); background: rgba(229,9,20,0.85); }
.pause-overlay[hidden] { display: none; }
@keyframes pauseAppear {
from { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
/* ์คํ๋/์๋ฉ ์คํต ๋ฒํผ - ๋น๋์ค ์ฐํ๋จ(์ปจํธ๋กค๋ฐ ์) */
.skip-btn { position: absolute; bottom: 60px; right: 16px; z-index: 6;
background: rgba(0,0,0,0.75); color: #fff; border: 1px solid rgba(255,255,255,0.3);
padding: 10px 18px; border-radius: 22px; font-size: 14px; font-weight: 600;
cursor: pointer; opacity: 0; transform: translateY(8px);
transition: opacity 0.25s, transform 0.25s; pointer-events: none; }
.skip-btn.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.skip-btn:hover { background: rgba(229,9,20,0.85); border-color: rgba(255,255,255,0.5); }
.video-wrap.locked .skip-btn { display: none !important; }
@media (max-width: 1023.98px) {
.skip-btn { bottom: 50px; right: 12px; padding: 8px 14px; font-size: 13px; }
}
/* ์์ ์ฐ์๋จ โ ์ปจํธ๋กค๋ฐ์ ๊ฒน์น์ง ์๊ฒ */
.fs-zoom-btn { position: absolute; top: 10px; right: calc(10px + env(safe-area-inset-right, 0px)); z-index: 5;
background: rgba(0,0,0,0.55); color: #fff; border: 1px solid rgba(255,255,255,0.2);
width: 36px; height: 36px; border-radius: 6px; font-size: 16px; cursor: pointer;
opacity: 0; transition: opacity 0.15s; }
.fs-zoom-btn:hover { background: rgba(0,0,0,0.75); }
/* ํฐ์น(hover ์์) ํ๊ฒฝ์์ ํญ์ ๋ณด์ โ ๋ชจ๋ฐ์ผ/Capacitor WebView ๋ฑ */
@media (hover: none) { .fs-zoom-btn { opacity: 0.7; } }
/* ํ๋ฉด ์ ๊ธ ๋ฒํผ โ ๋ชจ๋ฐ์ผ ํ์คํฌ๋ฆฐ์ผ ๋๋ง ์ข์ธก ์ค์ ํ์ */
.lock-btn { position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
z-index: 2147483646; background: rgba(0,0,0,0.55); color: #fff;
border: 1px solid rgba(255,255,255,0.25); width: 48px; height: 48px;
border-radius: 50%; font-size: 20px; cursor: pointer; padding: 0;
display: none; align-items: center; justify-content: center;
opacity: 0.85; transition: opacity 0.15s; }
.lock-btn:active { opacity: 1; }
/* ํ์คํฌ๋ฆฐ + ๋ชจ๋ฐ์ผ/ํฐ์น ํ๊ฒฝ์์๋ง ๋ณด์ด๊ฒ */
.video-wrap:fullscreen .lock-btn,
.video-wrap:-webkit-full-screen .lock-btn { display: flex; }
@media (any-pointer: fine) and (min-width: 1024px) {
.video-wrap:fullscreen .lock-btn,
.video-wrap:-webkit-full-screen .lock-btn { display: none; }
}
/* idle(ํฐ์น/๋ง์ฐ์ค ๋ฉ์ถค) ์ ์๋ ์จ๊น โ show-controls๊ฐ ๋น ์ง๋ฉด ํ์ด๋์์.
์ ๊ธ ํด์ ์ํ: show-controls ์ ์งํ๊ฒ(0.85)
์ ๊ธ ์ํ: show-controls ์ ํฌ๋ฏธํ๊ฒ(0.25), ๋๋ฅด๋ฉด 1. ์ฌ์ฉ์๊ฐ ๋ค์ ํญํ๋ฉด ๋ค์ 0.25๋ก ์ ๊น ๋
ธ์ถ. */
.video-wrap:fullscreen .lock-btn,
.video-wrap:-webkit-full-screen .lock-btn { opacity: 0; pointer-events: none; transition: opacity 0.25s ease; }
.video-wrap:fullscreen.show-controls .lock-btn,
.video-wrap:-webkit-full-screen.show-controls .lock-btn { opacity: 0.85; pointer-events: auto; }
.video-wrap:fullscreen.locked.show-controls .lock-btn,
.video-wrap:-webkit-full-screen.locked.show-controls .lock-btn { opacity: 0.25; pointer-events: auto; }
.video-wrap:fullscreen.locked.show-controls .lock-btn:active,
.video-wrap:-webkit-full-screen.locked.show-controls .lock-btn:active { opacity: 1; }
/* ์ ๊ธ ์ํ: ๋น๋์ค ์ปจํธ๋กค/์ค ์ปจํธ๋กค/ํ์คํฌ๋ฆฐ ๋ฒํผ ๋ฑ ๋ค ๊ฐ๋ฆฌ๊ณ ์ ๊ธ ๋ฒํผ๋ง ํ์ฑ */
.video-wrap.locked video::-webkit-media-controls { display: none !important; }
/* ๋ธ๋ผ์ฐ์ ๊ธฐ๋ณธ ์ปจํธ๋กค๋ฐ์ ์ ์ฒดํ๋ฉด ๋ฒํผ ์์ ์ ๊ฑฐ (controlslist ๋ฌด์ํ๋ ๋ธ๋ผ์ฐ์ ๋์) */
#player::-webkit-media-controls-fullscreen-button { display: none !important; }
#player::-internal-media-controls-fullscreen-button { display: none !important; }
/* ์์ ์ ๊ธธ๊ฒ๋๋ฅด๊ธฐ ์ '๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ์ ์ฅ' / ํ
์คํธ ์ ํ ์ฝ์์ ์ฐจ๋จ (3๋ฐฐ์ hold ์ถฉ๋) */
#player {
-webkit-touch-callout: none;
-webkit-user-select: none;
user-select: none;
}
/* 3๋ฐฐ์ hold ์บก์ฒ์ฉ ํฌ๋ช
์ค๋ฒ๋ ์ด โ video ์, ์ปจํธ๋กค๋ฐ ์๋ */
.hold-overlay { position: absolute; inset: 0; z-index: 2;
background: transparent;
-webkit-touch-callout: none;
-webkit-user-select: none;
user-select: none;
/* touch-action: none โ ๋ธ๋ผ์ฐ์ native gesture(ํ์น/๋๋ธํญ์ค/ํฌ) ์ ๋ถ ๋๊ณ
์ฐ๋ฆฌ JS์์ ์ง์ ์ฒ๋ฆฌ. 'manipulation'์ ํ์น ์์ฒด๋ฅผ ๋ง์๋ฒ๋ ค NG. */
touch-action: none; }
.video-wrap.locked .hold-overlay { display: none; }
.video-wrap.locked .fs-zoom-btn,
.video-wrap.locked .side-toggle-btn,
.video-wrap.locked .pause-overlay,
.video-wrap.locked .zoom-ctrl { display: none !important; }
.video-wrap.locked video { pointer-events: none; }
/* .lock-btn ์ ๊ธ opacity๋ ์ :fullscreen ๋ธ๋ก(143~153)์์ show-controls ๊ธฐ๋ฐ์ผ๋ก ๊ด๋ฆฌ.
์ฌ๊ธฐ์ ๊ฐ์ 0.25 ๊ท์น์ ๋๋ฉด idle ์์๋ ์ฌ๋ผ์ง์ง ์๊ณ , pointer-events:none๊ณผ
๊ฒน์ณ ํด์ ํด๋ฆญ๋ ์ ๋ฐ๋ ์ฌ๊ณ ๊ฐ ๋๋ค(2026-05-31 ์ฌ๊ณ ). */
.video-wrap:hover .fs-zoom-btn { opacity: 1; }
.side-toggle-btn { position: absolute; top: 10px; left: 10px; z-index: 5;
background: rgba(0,0,0,0.55); color: #fff; border: 1px solid rgba(255,255,255,0.2);
width: 36px; height: 36px; border-radius: 6px; font-size: 14px; cursor: pointer;
opacity: 0; transition: opacity 0.15s; }
.video-wrap:hover .side-toggle-btn { opacity: 1; }
/* ํ์คํฌ๋ฆฐ์์๋ ์ข์ธก ํจ๋ ์์ฒด๊ฐ ์์ผ๋ ํ๋ฒ๊ฑฐ๋ ์จ๊น */
.video-wrap:fullscreen .side-toggle-btn,
.video-wrap:-webkit-full-screen .side-toggle-btn { display: none !important; }
@media (max-width: 1023.98px) { .side-toggle-btn { display: none; } }
.video-wrap:fullscreen { background: #000; width: 100vw; height: 100vh; }
.video-wrap:-webkit-full-screen { background: #000; width: 100vw; height: 100vh; }
.video-wrap:fullscreen .fs-zoom-btn { opacity: 1; }
.video-wrap:fullscreen video { width: 100%; height: 100%; object-fit: contain; position: relative; z-index: 1; }
.video-wrap:-webkit-full-screen video { width: 100%; height: 100%; object-fit: contain; position: relative; z-index: 1; }
/* ์ค ๋ชจ๋ ์ ์ฉ ์ปจํธ๋กค ์ค๋ฒ๋ ์ด โ ๋ง์ฐ์ค ์์ง์ผ ๋๋ง ๋ณด์ */
.zoom-ctrl { position: absolute; left: 0; right: 0; bottom: 0; z-index: 10;
display: flex; align-items: center; gap: 10px;
background: linear-gradient(to top, rgba(0,0,0,0.9), rgba(0,0,0,0.4) 80%, transparent);
padding: 10px 14px 8px; color: #fff; font-size: 13px;
pointer-events: auto;
opacity: 0; transition: opacity 0.25s ease; }
.zoom-ctrl[hidden] { display: none; }
.zoom-ctrl * { pointer-events: auto; }
/* ์ผ๋ฐ ๋ชจ๋: ๋ง์ฐ์ค hover ์ ์ปจํธ๋กค ํ์. show-controls(ํฐ์น/ํ์คํฌ๋ฆฐ) ํด๋์ค๋ ํ์. */
.video-wrap:hover .zoom-ctrl,
.video-wrap.show-controls .zoom-ctrl { opacity: 1; }
/* ํ์คํฌ๋ฆฐ์ผ ๋ :hover ๊ท์น ๋ฌดํจํ โ show-controls ํด๋์ค๋ก๋ง ์ ์ด (idle ์ ์๋ ์จ๊น ์ํด) */
.video-wrap:fullscreen:hover .zoom-ctrl,
.video-wrap:-webkit-full-screen:hover .zoom-ctrl { opacity: 0; }
.video-wrap:fullscreen.show-controls .zoom-ctrl,
.video-wrap:-webkit-full-screen.show-controls .zoom-ctrl { opacity: 1; }
/* ํ์คํฌ๋ฆฐ์ผ ๋ z-index ์ต๋ (์๋งยท๊ธฐํ ์) */
.video-wrap:fullscreen .zoom-ctrl,
.video-wrap:-webkit-full-screen .zoom-ctrl { z-index: 2147483647; padding: 14px 16px 12px; }
/* ํ์คํฌ๋ฆฐ ์ ์ฉ ๋ฒํผ์ ์ผ๋ฐ ๋ชจ๋์์ ์จ๊น */
.zoom-ctrl .zc-fs-only { display: none; }
.video-wrap:fullscreen .zoom-ctrl .zc-fs-only,
.video-wrap:-webkit-full-screen .zoom-ctrl .zc-fs-only { display: inline-block; }
.video-wrap.show-controls { cursor: default; }
.video-wrap.hide-cursor { cursor: none; }
/* video์ inline cursor: grab์ด ๋ฐํ ์์ ์ ์์ด !important๋ก ๋ฎ์ โ ํ์คํฌ๋ฆฐ idle ์ ์๋ฐ๋ฅ๋ ์จ๊น */
.video-wrap.hide-cursor video { cursor: none !important; }
.video-wrap.hide-cursor .fs-zoom-btn { opacity: 0; pointer-events: none; }
.zoom-ctrl .zc-btn { background: transparent; border: 0; color: #fff; font-size: 18px;
cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.zoom-ctrl .zc-btn:hover { background: rgba(255,255,255,0.15); }
.zoom-ctrl .zc-time { font-variant-numeric: tabular-nums; min-width: 100px; font-size: 12px; }
.zoom-ctrl .zc-bar { flex: 1; height: 4px; cursor: pointer; accent-color: #e50914;
background: rgba(255,255,255,0.3); border-radius: 2px; -webkit-appearance: none; appearance: none; }
/* โฎ ๋๋ณด๊ธฐ ๋ฉ๋ด โ ๋น๋์ค ์ปจํธ๋กค๋ฐ ์์ ๋ ์๋ ํ์
*/
.more-menu { position: absolute; right: 12px; bottom: 56px; z-index: 11;
background: rgba(20,22,28,0.96); border: 1px solid rgba(255,255,255,0.15);
border-radius: 8px; padding: 6px; min-width: 200px;
max-width: calc(100vw - 24px); box-sizing: border-box;
box-shadow: 0 6px 24px rgba(0,0,0,0.6); }
.more-menu *, .more-menu *::before, .more-menu *::after { box-sizing: border-box; }
/* PIP + ๋ค์ด๋ก๋ ํ ์ค(2์นธ grid) */
.more-menu .more-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 4px;
border-top: 1px solid rgba(255,255,255,0.08); padding-top: 4px; }
.more-menu .more-actions .more-item { margin-top: 0; border-top: 0; padding: 8px 8px;
text-align: center; font-size: 12px; }
.more-menu .more-actions .more-item[hidden] { display: none; }
/* ๋ค์ด๋ก๋ ์จ๊น ์ํ์ผ ๋ PIP๊ฐ ํ ์ค ์ ์ฒด ์ฐจ์ง */
.more-menu .more-actions:has(> .more-item[hidden]) { grid-template-columns: 1fr; }
.more-menu[hidden] { display: none; }
.video-wrap:fullscreen .more-menu,
.video-wrap:-webkit-full-screen .more-menu { bottom: 60px; z-index: 2147483647; }
.more-menu .more-sec { padding: 6px 4px; }
.more-menu .more-sec-h { color: #8a93a3; font-size: 11px; padding: 0 6px 4px; }
.more-menu .more-rates { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; }
.more-menu .more-rates button { background: transparent; border: 1px solid rgba(255,255,255,0.1);
color: #e3e6eb; font-size: 11px; padding: 4px 0; border-radius: 4px; cursor: pointer;
font-variant-numeric: tabular-nums; }
.more-menu .more-rates button:hover { background: rgba(255,255,255,0.08); }
.more-menu .more-rates button.active { background: #e50914; border-color: #e50914; color: #fff; }
.more-menu .more-item { display: block; width: 100%; text-align: left;
background: transparent; border: 0; color: #e3e6eb; font-size: 13px;
padding: 8px 10px; border-radius: 4px; cursor: pointer;
border-top: 1px solid rgba(255,255,255,0.08); margin-top: 4px; }
.more-menu .more-item:hover { background: rgba(255,255,255,0.08); }
/* ์คํต ๋งํน: ๋ฉ์ธ ๋ฒํผ + ์ฐ์ธก ์์ โ ์ด๊ธฐํ ๋ฒํผ ํ ์ค */
.more-menu .more-skip-row { display: flex; align-items: stretch; gap: 4px; margin-top: 4px;
border-top: 1px solid rgba(255,255,255,0.08); padding-top: 4px; }
.more-menu .more-skip-row .more-skip-main { flex: 1; border-top: 0; margin-top: 0;
display: flex; align-items: center; gap: 8px; }
.more-menu .more-skip-row .more-skip-main .lbl { flex: 1; }
.more-menu .more-skip-row .more-skip-main .t { color: #ffd54a; font-variant-numeric: tabular-nums; font-size: 12px; }
.more-menu .more-skip-row .more-skip-main .t:empty::before { content: 'โ'; color: #555; }
.more-menu .more-skip-clear { background: transparent; border: 0; color: #ff9090;
font-size: 13px; padding: 0 8px; border-radius: 4px; cursor: pointer; }
.more-menu .more-skip-clear:hover { background: rgba(255,144,144,0.15); }
/* ์คํต ๋งํน ์ปจํ
์คํธ ๋ฉ๋ด */
.skip-ctx-menu { position: absolute; z-index: 2147483647; background: rgba(20,22,28,0.96);
border: 1px solid rgba(255,255,255,0.15); border-radius: 8px; padding: 4px;
box-shadow: 0 4px 20px rgba(0,0,0,0.6); min-width: 180px; }
.skip-ctx-menu[hidden] { display: none; }
.skip-ctx-menu button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
background: transparent; border: 0; color: #e3e6eb; font-size: 13px;
padding: 8px 12px; border-radius: 4px; cursor: pointer; }
.skip-ctx-menu button .lbl { flex: 1; }
.skip-ctx-menu button .t { color: #ffd54a; font-variant-numeric: tabular-nums;
font-size: 11px; min-width: 44px; text-align: right; }
.skip-ctx-menu button .t:empty::before { content: 'โ'; color: #555; }
.skip-ctx-menu button:hover { background: rgba(255,255,255,0.08); }
.skip-ctx-menu button[data-skip="clear"] { color: #ff9090; border-top: 1px solid rgba(255,255,255,0.1); margin-top: 2px; }
.zoom-ctrl .zc-bar::-webkit-slider-thumb { -webkit-appearance: none; appearance: none;
width: 14px; height: 14px; border-radius: 50%; background: #e50914; cursor: pointer; }
.zoom-ctrl .zc-bar::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%;
background: #e50914; border: 0; cursor: pointer; }
.zoom-ctrl .zc-vol { width: 80px; height: 4px; cursor: pointer; accent-color: #fff;
background: rgba(255,255,255,0.3); border-radius: 2px; -webkit-appearance: none; appearance: none; }
.zoom-ctrl .zc-vol::-webkit-slider-thumb { -webkit-appearance: none; appearance: none;
width: 12px; height: 12px; border-radius: 50%; background: #fff; cursor: pointer; }
.zoom-ctrl .zc-vol::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%;
background: #fff; border: 0; cursor: pointer; }
/* โโโโโ ์ฝํ
์ธ ์์ญ โโโโโ */
.content { padding: 12px 12px calc(80px + var(--safe-bot)); }
/* ๋นต๋ถ์ค๋ฌ๊ธฐ/๋ฉํ */
.now-meta { margin-bottom: 12px; }
.now-meta .title-row { display: flex; align-items: center; gap: 8px; }
.now-meta .title { font-size: 16px; font-weight: 700; line-height: 1.35; flex: 1; min-width: 0; }
.now-meta .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.now-meta .dl-btn { background: transparent; border: 1px solid var(--border);
color: var(--muted);
width: 30px; height: 30px; border-radius: 8px; cursor: pointer; flex: 0 0 auto;
display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.now-meta .dl-btn:hover { background: var(--panel2); color: var(--text); }
.now-meta .dl-btn:active { transform: scale(0.95); }
.now-meta:empty { display: none; }
/* ํ์ฐจ ๊ฐ๋ก์คํฌ๋กค ์นฉ */
.ep-strip { display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden;
padding: 4px 0 10px; -webkit-overflow-scrolling: touch;
scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.25) transparent;
min-width: 0; max-width: 100%; }
.ep-strip::-webkit-scrollbar { height: 6px; }
.ep-strip::-webkit-scrollbar-track { background: transparent; }
.ep-strip::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.25); border-radius: 999px; }
.ep-strip::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.45); }
.ep-chip { flex: 0 0 auto; background: var(--panel2); border: 1px solid var(--border);
color: var(--text); padding: 8px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
min-width: 56px; text-align: center; }
.ep-chip:active { background: #2a313d; }
.ep-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.ep-strip.hidden, .ep-empty.hidden { display: none; }
/* ํ์ฐจ ๊ทธ๋ฆฌ๋ (ํผ์นจ) */
.ep-grid-wrap { margin-top: 8px; }
.ep-grid-toggle { background: transparent; border: 0; color: var(--muted); font-size: 12px;
padding: 4px 0; cursor: pointer; }
/* ep-grid๋ ๋จ์ ์ปจํ
์ด๋ (๊ฒ์ input + ๊ทธ๋ฆฌ๋ ๋ณธ์ฒด). ๊ทธ๋ฆฌ๋๋ ์์ชฝ epGridList์. */
.ep-grid { margin-top: 6px; }
.ep-grid.hidden { display: none; }
#epGridList { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
gap: 6px; }
#epGridList .ep-chip { width: 100%; min-width: 0; padding: 8px; border-radius: 8px; }
/* ์น์
ํค๋ */
.section-h { display: flex; align-items: center; gap: 10px; margin: 20px 0 8px; }
.section-h h2 { margin: 0; font-size: 13px; color: var(--muted); font-weight: 600;
text-transform: uppercase; letter-spacing: 0.05em; }
.section-h .spacer { flex: 1; }
/* ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ฆฌ์คํธ */
.fav-list { display: flex; flex-direction: column; gap: 4px; }
.fav-list:empty::before { content: "๏ผ ๋ฒํผ์ผ๋ก ์์์ ์ถ๊ฐํ์ธ์. ๊ฒ์์์ ์ถ๊ฐํ ์๋ ์์ต๋๋ค.";
display: block; padding: 18px; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center;
background: var(--panel); border-radius: 10px; }
.fav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel);
border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.fav-item:active { background: var(--panel2); }
.fav-item.active { background: #1d2c45; border-color: #3a5380; }
.fav-item .ftxt { flex: 1; min-width: 0; }
.fav-item .ftxt b { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical;
overflow: hidden; text-overflow: ellipsis; word-break: break-word; font-size: 14px; line-height: 1.25; }
.fav-item .ftxt .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.fav-item .new-badge { background: var(--new); color: #1a1305; font-size: 10px; font-weight: 800;
padding: 2px 7px; border-radius: 999px; letter-spacing: 0.5px; }
.fav-item .resume-badge { background: var(--accent2); color: #07111e; font-size: 10px; font-weight: 800;
padding: 2px 7px; border-radius: 999px; letter-spacing: 0.3px; }
.fav-item .badge-col { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
/* โโโโโ ๋ธ๋๋ ๋ก๊ณ โโโโโ */
.brand { cursor: pointer; user-select: none; }
.brand {
font-family: "Bebas Neue", "Arial Black", "Impact", -apple-system, sans-serif;
font-weight: 900;
letter-spacing: 0.02em;
text-transform: uppercase;
line-height: 1;
display: inline-flex;
align-items: center;
gap: 0.2em;
}
.brand .b-ott { color: #e50914; }
.brand .b-sep { color: #e6e8ec; opacity: 0.7; font-weight: 400; transform: translateY(-0.05em); }
.brand .b-player { color: #fff; }
.brand-wrap { padding: 16px 14px 14px; display: flex; align-items: center; gap: 10px;
border-bottom: 1px solid var(--border); background:
radial-gradient(ellipse at top left, rgba(229,9,20,0.12), transparent 70%),
var(--panel); }
.brand-wrap .brand { font-size: 30px; }
.appbar .brand { font-size: 22px; }
/* โโโโโ ์๋จ ๋ชจ๋/๋๋ฉ์ธ ๋ฐฐ์ง โโโโโ */
.mode-badge, .domain-badge {
font-size: 10px; font-weight: 800; letter-spacing: 0.05em;
padding: 3px 7px; border-radius: 999px;
border: 1px solid var(--border); white-space: nowrap;
font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
text-transform: uppercase;
}
.mode-badge { background: rgba(110,231,168,0.10); color: #6ee7a8; border-color: rgba(110,231,168,0.30); }
.mode-badge.mode-cdp { background: rgba(110,231,168,0.10); color: #6ee7a8; border-color: rgba(110,231,168,0.30); }
.mode-badge.mode-local { background: rgba(96,165,250,0.10); color: #93c5fd; border-color: rgba(96,165,250,0.30); }
.mode-badge.mode-hf { background: rgba(244,114,182,0.10); color: #f9a8d4; border-color: rgba(244,114,182,0.30); }
.domain-badge { color: #e6e8ec; background: rgba(255,255,255,0.04); cursor: pointer; }
.domain-badge:hover { border-color: rgba(255,255,255,0.35); background: rgba(255,255,255,0.09); }
.domain-badge.bad { color: #fca5a5; border-color: rgba(252,165,165,0.30); background: rgba(252,165,165,0.08); }
.domain-badge.ov { color: #fcd34d; border-color: rgba(252,211,77,0.40); background: rgba(252,211,77,0.10); } /* ์๋ ์ค๋ฒ๋ผ์ด๋ ํ์ */
/* โโโโโ ๋๋ฉ์ธ ์ ํ ํ์
โโโโโ */
#domainPop {
position: fixed; z-index: 9999; display: none;
min-width: 240px; padding: 12px;
background: var(--panel, #16181d); border: 1px solid var(--border, #2a2d34);
border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,0.55);
font-size: 13px; color: #e6e8ec;
}
#domainPop.show { display: block; }
#domainPop .dp-title { font-size: 11px; color: var(--muted, #8b909a); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .05em; }
#domainPop .dp-opt { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
#domainPop .dp-opt:hover { background: rgba(255,255,255,0.06); }
#domainPop .dp-opt input[type=radio] { accent-color: #e50914; margin: 0; }
#domainPop .dp-opt label { cursor: pointer; flex: 1; display: flex; align-items: center; gap: 6px; }
#domainPop .dp-numwrap { display: flex; align-items: center; gap: 4px; font-family: ui-monospace, Consolas, monospace; }
#domainPop .dp-numwrap input.dp-num {
width: 58px; text-align: center; font-family: inherit; font-size: 13px;
padding: 3px 4px; border-radius: 6px; border: 1px solid var(--border, #2a2d34);
background: #0e1014; color: #e6e8ec;
}
#domainPop .dp-sub { font-size: 11px; color: var(--muted, #8b909a); }
#domainPop .dp-actions { display: flex; gap: 6px; margin-top: 10px; }
#domainPop .dp-actions button {
flex: 1; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--border, #2a2d34);
background: #1c1f26; color: #e6e8ec; cursor: pointer; font-size: 12px; font-weight: 700;
}
#domainPop .dp-actions button.primary { background: #e50914; border-color: #e50914; color: #fff; }
#domainPop .dp-actions button:hover { filter: brightness(1.15); }
#domainPop .dp-msg { font-size: 11px; margin-top: 8px; min-height: 14px; }
#domainPop .dp-msg.ok { color: #6ee7a8; }
#domainPop .dp-msg.err { color: #fca5a5; }
/* ๋ฐฐ์ง ๋ฌถ์: ์ฐ์ธก ์๋จ ๊ณ ์ . ๋ฐ์คํฌํยท๋ชจ๋ฐ์ผ ๋ชจ๋ ๊ฐ๋ก(์ข:๋ชจ๋, ์ฐ:๋๋ฉ์ธ). ๋ฐ์คํฌํ์ brand-wrap์ ๊ฐ์ฅ ์์ชฝ ์ ๋ ฌ. */
.badge-stack { margin-left: auto; display: flex; flex-direction: row; align-items: center; gap: 6px; align-self: flex-start; }
.appbar .mode-badge, .appbar .domain-badge { font-size: 9px; padding: 2px 6px; }
/* โโโโโ ํ๋กํ ํญ โโโโโ */
.profile-bar { padding: 8px 12px 10px; background: var(--panel);
border-bottom: 1px solid var(--border); }
.profile-tabs { display: flex; gap: 8px; width: 100%; }
.profile-tab {
flex: 1; min-width: 0;
background: linear-gradient(135deg, var(--panel2) 0%, #1a1f2a 100%);
border: 1px solid var(--border); color: var(--muted);
height: 32px; border-radius: 8px; font-size: 14px; font-weight: 800;
cursor: pointer; padding: 0 6px;
font-family: "Bebas Neue", "Arial Black", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; letter-spacing: 0.05em;
transition: all 0.18s ease;
position: relative; overflow: hidden;
white-space: nowrap; text-overflow: ellipsis;
}
.profile-tab::before { content: ''; position: absolute; inset: 0;
background: linear-gradient(135deg, rgba(229,9,20,0.0), rgba(229,9,20,0.0));
transition: background 0.2s; pointer-events: none; }
.profile-tab:hover { color: var(--text); border-color: #3a4252;
transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.profile-tab:hover::before { background: linear-gradient(135deg, rgba(229,9,20,0.08), rgba(229,9,20,0.0)); }
.profile-tab.active {
background: linear-gradient(135deg, #ff5b6a 0%, #e50914 55%, #b00710 100%);
border-color: #e50914; color: #fff;
box-shadow: 0 4px 16px rgba(229,9,20,0.5), inset 0 1px 0 rgba(255,255,255,0.2);
transform: translateY(-1px);
}
.profile-tab.active::before { background: none; }
.profile-tab:active { transform: translateY(0); }
/* โโโโโ ํค๋
ธ๋ผ์ด์ธ ๋ญํน โโโโโ */
.ranking-box { padding: 14px 12px 18px; border-top: 1px solid var(--border); }
.ranking-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.ranking-head h3 { margin: 0; font-size: 13px; color: var(--muted); font-weight: 600;
text-transform: uppercase; letter-spacing: 0.05em; flex: 1; }
.ranking-tabs { display: flex; gap: 4px; background: var(--panel2); padding: 3px; border-radius: 8px; }
.ranking-tabs button { background: transparent; border: 0; color: var(--muted); font-size: 11px;
padding: 4px 10px; cursor: pointer; border-radius: 6px; font-weight: 600; }
.ranking-tabs button.active { background: var(--accent); color: #fff; }
.ranking-list { display: flex; flex-direction: column; gap: 4px; }
.rk-item { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px; background: var(--panel2);
border: 1px solid var(--border); border-radius: 10px; cursor: pointer; overflow: hidden; }
.rk-item:active, .rk-item:hover { background: #232936; }
.rk-item .rk-rank { font-size: 16px; font-weight: 900; color: var(--accent); min-width: 22px; text-align: center;
font-family: "Bebas Neue", "Arial Black", sans-serif; }
.rk-item .rk-poster { width: 36px; height: 50px; object-fit: cover; border-radius: 4px;
background: #2a313d; flex-shrink: 0; }
.rk-item .rk-poster.placeholder { display: flex; align-items: center; justify-content: center;
font-size: 10px; color: var(--muted); }
.rk-item .rk-title { flex: 1; min-width: 0; }
.rk-item .rk-title b { display: block; font-size: 13px; line-height: 1.3; overflow: hidden;
text-overflow: ellipsis; white-space: nowrap; }
.rk-item .rk-title .rk-meta { font-size: 10px; color: var(--muted); margin-top: 2px; }
.rk-item .rk-more { background: transparent; border: 0; color: var(--accent2); font-size: 11px;
cursor: pointer; padding: 4px 6px; flex-shrink: 0; }
.rk-item .rk-more:hover { color: var(--accent); }
.rk-detail { background: var(--panel); border: 1px solid var(--border); border-top: 0;
border-radius: 0 0 10px 10px; padding: 10px 12px; margin-top: -8px; margin-bottom: 4px;
font-size: 12px; color: var(--text); line-height: 1.5; display: none; }
.rk-detail.open { display: block; }
.rk-detail .syn { color: var(--text); margin-bottom: 8px; font-size: 12px; }
.rk-detail .meta-row { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 11px; }
.rk-detail .meta-row span b { color: var(--text); font-weight: 500; margin-left: 4px; }
.rk-detail .cast { margin-top: 6px; color: var(--muted); font-size: 11px; }
.rk-detail .cast b { color: var(--text); font-weight: 500; }
.rk-detail .loading { color: var(--muted); font-style: italic; }
.rk-detail .trailer-wrap { margin-top: 10px; }
.rk-detail .trailer-loading { color: var(--muted); font-size: 11px; font-style: italic; }
.rk-detail .trailer-label { font-size: 10px; color: var(--muted); margin-bottom: 4px;
text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.rk-detail .trailer-frame { position: relative; padding-top: 56.25%; /* 16:9 */
background: #000; border-radius: 6px; overflow: hidden; }
.rk-detail .trailer-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%;
border: 0; }
/* ์นด๋ ์ฐ์ธก ์ก์
์ปฌ๋ผ: โ ์ / โ ์๋ */
.fav-item .actcol { display: flex; flex-direction: column; align-items: center;
justify-content: space-between; align-self: stretch; gap: 6px; margin-left: 6px; }
.fav-item .markdone { background: transparent; border: 0; color: var(--muted); font-size: 16px;
padding: 4px 8px; cursor: pointer; line-height: 1; }
.fav-item .markdone:hover, .fav-item .markdone:active { color: #6ee7a8; }
.fav-item .delbtn { background: transparent; border: 0; color: var(--muted); font-size: 18px;
padding: 4px 8px; cursor: pointer; }
.fav-item .delbtn:active { color: var(--accent); }
/* ๊ฒ์ ๊ฒฐ๊ณผ */
.search-list { display: flex; flex-direction: column; gap: 4px; }
.sr-item { padding: 10px 12px; background: var(--panel); border: 1px solid var(--border);
border-radius: 10px; cursor: pointer; }
.sr-item:active { background: var(--panel2); }
.sr-item b { display: block; font-size: 14px; line-height: 1.35; }
.sr-item .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.sr-item .meta.star { color: var(--new); }
/* source ๋ฐฐ์ง */
.src-badge { display: inline-block; font-size: 10px; padding: 1px 5px; border-radius: 4px;
vertical-align: middle; margin-right: 4px; font-weight: 700; letter-spacing: 0.5px; }
.src-badge.ani { background: #5b3df5; color: #fff; }
.src-badge.tv { background: #16a34a; color: #fff; } /* ๋๋ผ๋ง */
.fb-badge { display: inline-block; font-size: 9px; padding: 1px 4px; border-radius: 3px;
background: #404555; color: #c5cad6; font-weight: 600; letter-spacing: 0.3px;
vertical-align: middle; margin-left: 4px; opacity: 0.8; }
.src-badge.tv.ent { background: #d97706; color: #fff; } /* ์๋ฅ */
.src-badge.tv.mov { background: #1865f2; color: #fff; } /* ์ํ */
/* ๊ฒ์๋ฐ */
.search-bar { display: flex; gap: 6px; margin-bottom: 8px; }
.search-bar input { flex: 1; }
/* ํ๋จ ๊ณ ์ ์ก์
*/
.fab { position: fixed; right: 16px; bottom: calc(20px + var(--safe-bot)); z-index: 40;
background: var(--accent); border: 0; color: #fff; width: 56px; height: 56px;
border-radius: 50%; box-shadow: 0 6px 20px rgba(0,0,0,0.5); font-size: 24px; cursor: pointer; }
.fab:active { background: #e34758; }
/* โโโโโ ๋ชจ๋ฌ โโโโโ */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: none;
align-items: flex-end; justify-content: center; z-index: 100; padding: 0; }
.modal-bg.show { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--border);
border-radius: 16px 16px 0 0; width: 100%; max-width: 560px; padding: 20px;
padding-bottom: calc(20px + var(--safe-bot)); }
.modal h2 { margin: 0 0 12px; font-size: 16px; }
.modal label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal .hint { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.modal code { background: var(--panel2); padding: 1px 5px; border-radius: 3px; font-size: 11px; }
/* โโโโโ ๋ฐ์คํฌํ (>= 1024px): 2์ปฌ๋ผ โโโโโ */
@media (min-width: 1024px) {
body { display: grid; grid-template-columns: var(--left-w, 340px) 1fr;
grid-template-rows: 100dvh; overflow: hidden; }
body.with-transition { transition: grid-template-columns 0.2s ease; }
body.left-collapsed { grid-template-columns: 0 1fr; }
body.left-collapsed .pane.left { visibility: hidden; }
/* ๋ฆฌ์ฌ์ด์ฆ ํธ๋ค */
.resize-handle { position: absolute; top: 0; right: -3px; width: 6px; height: 100%;
cursor: ew-resize; z-index: 20; background: transparent; transition: background 0.15s; }
.resize-handle:hover, .resize-handle.dragging { background: var(--accent2); }
body.left-collapsed .resize-handle { display: none; }
.appbar { display: none; }
.pane { background: var(--panel); border-right: 1px solid var(--border);
overflow-y: auto; display: flex; flex-direction: column; position: relative; }
.pane.right { border-right: 0; border-left: 1px solid var(--border); }
.pane-head { padding: 14px 14px 8px; border-bottom: 1px solid var(--border);
position: sticky; top: 0; background: var(--panel); z-index: 1; }
.pane-head h2 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.pane-head .domain { font-size: 11px; color: #6ee7a8; }
main.center { display: flex; flex-direction: column; background: #000;
min-width: 0; overflow: hidden; }
.video-wrap { aspect-ratio: auto; flex: 1; min-height: 0; }
.center-bottom { background: var(--bg); padding: 12px 16px;
max-height: 38vh; overflow-y: auto; }
.fab { display: none; }
.show-on-mobile { display: none !important; }
.pane-foot { border-top: 1px solid var(--border); padding: 10px;
display: flex; gap: 6px; position: sticky; bottom: 0; background: var(--panel); }
.pane-foot .btn { flex: 1; }
/* ์ฆ๊ฒจ์ฐพ๊ธฐ ์นด๋๋ ๋ฐ์คํฌํ์์๋ ์ข๊ฒ */
.pane.left .fav-item { padding: 8px 10px; border-radius: 8px; }
.pane.left .fav-item .ftxt b { font-size: 13px; }
.pane.right .sr-item { padding: 8px 10px; border-radius: 8px; }
.pane.right .sr-item b { font-size: 13px; }
/* โโโโโ ์ปค์คํ
์คํฌ๋กค๋ฐ (๋ฐ์คํฌํ ์ ์ฉ) โโโโโ */
.pane, .center-bottom {
scrollbar-width: thin;
scrollbar-color: rgba(255,255,255,0.12) transparent;
scrollbar-gutter: stable;
}
.pane::-webkit-scrollbar,
.center-bottom::-webkit-scrollbar { width: 10px; height: 10px; }
.pane::-webkit-scrollbar-track,
.center-bottom::-webkit-scrollbar-track { background: transparent; }
.pane::-webkit-scrollbar-thumb,
.center-bottom::-webkit-scrollbar-thumb {
background: rgba(255,255,255,0.08);
border: 2px solid transparent;
background-clip: padding-box;
border-radius: 999px;
transition: background 0.18s ease;
}
.pane:hover::-webkit-scrollbar-thumb,
.center-bottom:hover::-webkit-scrollbar-thumb {
background: rgba(255,255,255,0.18);
background-clip: padding-box;
}
.pane::-webkit-scrollbar-thumb:hover,
.center-bottom::-webkit-scrollbar-thumb:hover {
background: var(--accent2);
background-clip: padding-box;
}
.pane::-webkit-scrollbar-thumb:active,
.center-bottom::-webkit-scrollbar-thumb:active {
background: var(--accent);
background-clip: padding-box;
}
.pane::-webkit-scrollbar-corner,
.center-bottom::-webkit-scrollbar-corner { background: transparent; }
}
/* โโโโโ ๋ชจ๋ฐ์ผ (< 1024px) โโโโโ */
@media (max-width: 1023.98px) {
.hide-on-mobile { display: none !important; }
.pane { display: block; }
.pane-head, .pane-foot { display: none; }
.pane.right .right-tabs { display: flex; background: var(--panel);
border-radius: 10px; padding: 4px; margin-bottom: 10px; }
.pane.right .right-tabs button { flex: 1; background: transparent; border: 0; color: var(--muted);
padding: 8px; font-size: 13px; cursor: pointer; border-radius: 6px; }
.pane.right .right-tabs button.active { background: var(--panel2); color: var(--text); }
}
/* โโโโโ A2: ํ์ฐจ ์นฉ ์ง๋๋ฐ + finished ์ฒดํฌ โโโโโ */
.ep-chip { position: relative; overflow: hidden; }
.ep-chip .ep-progress { position: absolute; left: 0; bottom: 0; height: 3px;
background: var(--accent); pointer-events: none; transition: width 0.2s; }
.ep-chip.finished .ep-progress { background: #6ee7a8; }
.ep-chip .ep-check { position: absolute; top: 2px; right: 4px; color: #6ee7a8;
font-size: 10px; font-weight: 900; }
/* E-14: ๋ฏธ์์ฒญ ํ์ฐจ ์ ํ์ (์๋จ ์ฐ์ธก ์์ ํ์ dot) */
.ep-chip.unwatched::after { content: ''; position: absolute; top: 4px; right: 5px;
width: 5px; height: 5px; border-radius: 50%; background: var(--muted); opacity: 0.55; }
.ep-chip.unwatched.active::after { display: none; }
/* H-11/H-5: ์์ ์ฐ์๋จ ์
๋ ํธ ๋ฐ์ค๋ค (ํ์ง/์ค๋์ค/์๋ง) */
.hls-quality, .hls-audio, .hls-sub {
position: absolute; z-index: 5;
background: rgba(0,0,0,0.55); color: #fff; border: 1px solid rgba(255,255,255,0.2);
border-radius: 6px; padding: 4px 6px; font-size: 11px; cursor: pointer;
opacity: 0; transition: opacity 0.15s; display: none; top: 12px;
}
.hls-quality { right: 56px; }
.hls-audio { right: 120px; }
.hls-sub { right: 184px; }
.video-wrap:hover .hls-quality.has-levels,
.video-wrap:hover .hls-audio.has-levels,
.video-wrap:hover .hls-sub.has-levels { opacity: 1; }
.hls-quality.has-levels, .hls-audio.has-levels, .hls-sub.has-levels { display: block; }
.video-wrap.locked .hls-quality, .video-wrap.locked .hls-audio, .video-wrap.locked .hls-sub { display: none !important; }
.video-wrap:fullscreen .hls-quality.has-levels,
.video-wrap:fullscreen .hls-audio.has-levels,
.video-wrap:fullscreen .hls-sub.has-levels { opacity: 1; }
/* F-8: ๋ค์ ํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ (์์ ์ฐ์๋จ) */
.next-preview { position: absolute; top: 56px; right: 12px; z-index: 12;
background: rgba(0,0,0,0.78); color: #fff; border: 1px solid rgba(255,255,255,0.2);
padding: 6px 12px; border-radius: 16px; font-size: 12px; cursor: pointer;
opacity: 0; transform: translateY(-4px); transition: opacity 0.2s, transform 0.2s;
pointer-events: none; touch-action: manipulation; }
.next-preview.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.next-preview:hover { background: var(--accent); border-color: var(--accent); }
.video-wrap.locked .next-preview { display: none !important; }
/* ํ์คํฌ๋ฆฐ์์ zoom-ctrl์ด 2147483647๋ก ์ฌ๋ผ๊ฐ๋ ๋ค์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ ๊ทธ ์๋ก โ ๋ชจ๋ฐ์ผ ํ์คํฌ๋ฆฐ์์ ํด๋ฆญ ๊ฐ๋ฅ ๋ณด์ฅ. */
.video-wrap:fullscreen .next-preview,
.video-wrap:-webkit-full-screen .next-preview { z-index: 2147483647; }
/* โโโโโ E-2: ๋ณด๊ดํจ ์นด๋ ํฌ์คํฐ โโโโโ */
.fav-item .fav-poster { width: 44px; height: 60px; border-radius: 4px;
object-fit: cover; background: var(--panel2); flex-shrink: 0; }
.fav-item .fav-poster.placeholder { display: flex; align-items: center; justify-content: center;
color: var(--muted); font-size: 10px; }
@media (max-width: 1023.98px) {
.fav-item .fav-poster { width: 52px; height: 70px; }
}
/* โโโโโ E-3: ์๋์๊ฐ โโโโโ */
.fav-item .meta .ago { color: var(--accent2); font-size: 10px; margin-left: 4px; }
.fav-item.flash { animation: flashHighlight 1.5s ease-out; }
@keyframes flashHighlight {
0%, 30% { box-shadow: 0 0 0 3px var(--accent); }
100% { box-shadow: 0 0 0 0 rgba(229,9,20,0); }
}
/* โโโโโ A1: ๊ฒ์ ์๋์์ฑ ๋๋กญ๋ค์ด โโโโโ */
.ac-wrap { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 50;
background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
margin-top: 4px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); max-height: 280px;
overflow-y: auto; display: none; }
.ac-list.show { display: block; }
.ac-item { padding: 8px 12px; cursor: pointer; font-size: 13px;
display: flex; align-items: center; gap: 8px; }
.ac-item:hover, .ac-item.focused { background: rgba(78,161,255,0.15); }
.ac-item .ac-icon { color: var(--muted); font-size: 12px; width: 14px; flex-shrink: 0; }
.ac-item .ac-label { flex: 1; min-width: 0; overflow: hidden;
text-overflow: ellipsis; white-space: nowrap; }
.ac-item .ac-del { background: transparent; border: 0; color: var(--muted);
font-size: 14px; padding: 0 4px; cursor: pointer; opacity: 0; }
.ac-item:hover .ac-del { opacity: 0.7; }
.ac-item .ac-del:hover { opacity: 1; color: var(--accent); }
/* โโโโโ A4: ์๋ฒ ์๋ต ์คํจ ์๋จ ๋ฐฐ๋ โโโโโ */
.err-banner { position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
background: linear-gradient(90deg, #c92a39, #e0394a); color: #fff;
text-align: center; padding: 8px 12px; font-size: 12px; font-weight: 600;
box-shadow: 0 2px 8px rgba(0,0,0,0.5); transform: translateY(-100%);
transition: transform 0.3s; }
.err-banner.show { transform: translateY(0); }
/* โโโโโ B11: ๋ถํ
์ ์ด์ด๋ณด๊ธฐ ๋น
๋ฐฐ๋ โโโโโ */
.resume-hero { display: flex; align-items: center; gap: 12px; padding: 12px 16px;
margin: 10px 16px; background: linear-gradient(90deg, rgba(229,9,20,0.18), rgba(229,9,20,0.05));
border: 1px solid rgba(229,9,20,0.4); border-radius: 12px; cursor: pointer;
transition: transform 0.15s, background 0.15s; }
.resume-hero:hover { transform: translateY(-1px); background: linear-gradient(90deg, rgba(229,9,20,0.28), rgba(229,9,20,0.1)); }
.resume-hero .rh-ico { font-size: 24px; color: var(--accent); }
.resume-hero .rh-txt { flex: 1; min-width: 0; }
.resume-hero .rh-txt b { font-size: 14px; display: block; overflow: hidden;
text-overflow: ellipsis; white-space: nowrap; }
.resume-hero .rh-txt small { font-size: 11px; color: var(--muted); }
.resume-hero .rh-close { background: transparent; border: 0; color: var(--muted);
font-size: 18px; cursor: pointer; padding: 4px 8px; }
.resume-hero .rh-close:hover { color: var(--text); }
@media (min-width: 1024px) {
/* ๋ฐ์คํฌํ์์ body๊ฐ grid๋ผ resume-hero๊ฐ grid item์ผ๋ก ์ข์ธก ์ปฌ๋ผ์ ์ฐจ์งํด ๋ ์ด์์ ๊นจ์ง.
๋ฐ์คํฌํ์ ์ฌ์ด๋ ํจ๋์ ๋ณด๊ดํจ ์นด๋๋ก ๋์ผ ์ ๋ณด ๋ณด์ด๋ฏ๋ก hero ์์ฒด ์จ๊น. */
.resume-hero { display: none !important; }
}
/* โโโโโ B13: ํ์ฐจ ๋ผ๋ฒจ ๊ฒ์ โโโโโ */
.ep-search { display: flex; gap: 6px; margin-bottom: 6px; }
.ep-search input { flex: 1; padding: 6px 10px; font-size: 12px;
background: var(--panel2); border: 1px solid var(--border); color: var(--text);
border-radius: 6px; outline: none; }
.ep-search input:focus { border-color: var(--accent2); }
.ep-chip.ep-hidden { display: none; }
/* โโโโโ C5: ๋ค์ ํ ์นด์ดํธ๋ค์ด ์ค๋ฒ๋ ์ด โโโโโ */
/* z-index: zoom-ctrl(10)ยทmore-menu(11)๋ณด๋ค ์. ๋ชจ๋ฐ์ผ์์ zoom-ctrl์ด opacity:0์ด์ด๋
pointer-events:auto๋ผ ncCancel/ncGo ํด๋ฆญ์ด ๊ฐ๋ก์ฑ์ฌ์ ์ ๋จน๋ ์ฌ๊ณ (2026-06-08) ๋ฐฉ์ง. */
.next-countdown { position: absolute; right: 16px; bottom: 70px; z-index: 12;
background: rgba(0,0,0,0.85); color: #fff; border: 1px solid rgba(255,255,255,0.2);
border-radius: 12px; padding: 12px 14px; min-width: 220px;
display: none; flex-direction: column; gap: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.6); }
.next-countdown.show { display: flex; }
/* ํ์คํฌ๋ฆฐ์์ zoom-ctrl์ด 2147483647๋ก ์ฌ๋ผ๊ฐ๋ ์นด์ดํธ๋ค์ด๋ ๊ทธ ์์ ๋ ์ผ ํด๋ฆญ ๊ฐ๋ฅ. */
.video-wrap:fullscreen .next-countdown,
.video-wrap:-webkit-full-screen .next-countdown { z-index: 2147483647; }
/* ๋ชจ๋ฐ์ผ ํฐ์น ํ๊ฒฝ์์ ์นด์ดํธ๋ค์ด ๋ฒํผ์ ํญ์ ์ต์ฐ์ ์ผ๋ก ํด๋ฆญ ๋ฐ์์ผ ํจ */
.next-countdown button { touch-action: manipulation; }
.next-countdown .nc-label { font-size: 12px; color: #ccc; }
.next-countdown .nc-title { font-size: 14px; font-weight: 700; overflow: hidden;
text-overflow: ellipsis; white-space: nowrap; }
.next-countdown .nc-bar { height: 3px; background: rgba(255,255,255,0.15);
border-radius: 2px; overflow: hidden; }
.next-countdown .nc-bar-fill { height: 100%; background: var(--accent);
width: 100%; transition: width 0.95s linear; }
.next-countdown .nc-actions { display: flex; gap: 6px; margin-top: 4px; }
.next-countdown button { flex: 1; padding: 6px 10px; font-size: 12px;
background: var(--panel2); border: 1px solid var(--border); color: #fff;
border-radius: 6px; cursor: pointer; }
.next-countdown .nc-go { background: var(--accent); border-color: var(--accent); }
@media (max-width: 1023.98px) {
.next-countdown { right: 8px; bottom: 56px; min-width: 200px; padding: 10px 12px; }
}
/* โโโโโ D2: ๋ณด๊ดํจ ์ ๋ ฌ ๋๋กญ๋ค์ด โโโโโ */
.sort-bar { display: flex; align-items: center; gap: 6px; padding: 4px 10px 6px;
font-size: 11px; color: var(--muted); }
.sort-bar select { background: var(--panel2); border: 1px solid var(--border);
color: var(--text); font-size: 11px; padding: 3px 6px; border-radius: 5px; outline: none;
font-family: inherit; }
/* โโโโโ D10: ๊ฒ์ ๊ฒฐ๊ณผ โ
์ถ๊ฐ ๋ฒํผ โโโโโ */
.sr-item { position: relative; }
.sr-item .sr-fav { position: absolute; top: 6px; right: 8px;
background: transparent; border: 0; color: var(--muted); font-size: 18px;
cursor: pointer; padding: 4px 6px; line-height: 1; transition: color 0.15s, transform 0.15s; }
.sr-item .sr-fav:hover { transform: scale(1.15); color: var(--new); }
.sr-item .sr-fav.added { color: var(--new); }
/* โโโโโ D12: ์๋/์๋ ์ธ๋์ผ์ดํฐ โโโโโ */
.media-toast { position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
background: rgba(0,0,0,0.78); color: #fff; padding: 8px 18px; border-radius: 999px;
font-size: 14px; font-weight: 700; opacity: 0; transition: opacity 0.2s;
pointer-events: none; z-index: 8; }
.media-toast.show { opacity: 1; }
/* โโโโโ D14: ํต๊ณ ๋ชจ๋ฌ โโโโโ */
.stats-modal { background: var(--panel); border: 1px solid var(--border);
border-radius: 16px; max-width: 480px; padding: 20px;
max-height: 80vh; overflow-y: auto; }
.stats-modal .stat-row { display: flex; justify-content: space-between;
padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.stats-modal .stat-row:last-of-type { border-bottom: 0; }
.stats-modal .stat-row b { color: var(--accent2); }
/* โโโโโ ๋ชจ๋ฐ์ผ: ์ฌ์๋ฐ ์ปดํฉํธ โโโโโ */
@media (max-width: 640px) {
/* ํ์คํฌ๋ฆฐ์ด ์๋ ๋ชจ๋ฐ์ผ ์ธ๋ผ์ธ ์ปจํธ๋กค๋ฐ */
.video-wrap:not(:fullscreen):not(:-webkit-full-screen) .zoom-ctrl { gap: 6px; padding: 8px 8px 6px; }
.video-wrap:not(:fullscreen):not(:-webkit-full-screen) .zoom-ctrl .zc-btn { font-size: 16px; padding: 4px 6px; }
.video-wrap:not(:fullscreen):not(:-webkit-full-screen) .zoom-ctrl .zc-time { min-width: 0; font-size: 11px; white-space: nowrap; }
/* ๋ณผ๋ฅจ ์ฌ๋ผ์ด๋ ์จ๊น โ ์์๊ฑฐ ์์ด์ฝ๋ง ๋
ธ์ถ */
.video-wrap:not(:fullscreen):not(:-webkit-full-screen) .zoom-ctrl .zc-vol { display: none; }
}
</style>
</head>
<body>
<!-- ์๋จ ๋ก๋ฉ ๋ฐ โ selectFav ์ง์
์ ํ์, ์๋ฃ ์ ์จ๊น -->
<div id="topLoader" aria-hidden="true"></div>
<!-- A4: ์๋ฒ ์๋ต ์คํจ ๋ฐฐ๋ -->
<div class="err-banner" id="errBanner">์๋ฒ ์๋ต ์์ โ ์๋๋ณต๊ตฌ ์งํ ์คโฆ</div>
<!-- B11: ์ด์ด๋ณด๊ธฐ ๋น
๋ฐฐ๋ (์๋จ) -->
<div class="resume-hero" id="resumeHero" style="display:none">
<div class="rh-ico">โถ</div>
<div class="rh-txt"><b id="rhTitle"></b><small id="rhMeta"></small></div>
<button class="rh-close" id="rhClose" aria-label="๋ซ๊ธฐ">โ</button>
</div>
<!-- ๋๋ฉ์ธ ์ ํ ํ์
(๋ฐฐ์ง ํด๋ฆญ ์ ํ์, ๋ฐ์คํฌํยท๋ชจ๋ฐ์ผ ๊ณต์ฉ) -->
<div id="domainPop">
<div class="dp-title">tvchak ์ฝํ
์ธ ๋๋ฉ์ธ</div>
<div class="dp-opt">
<input type="radio" name="dpMode" id="dpAuto" value="auto">
<label for="dpAuto">์๋ <span class="dp-sub">(announce ์ถ์ข
)</span></label>
</div>
<div class="dp-opt">
<input type="radio" name="dpMode" id="dpLive" value="live">
<label for="dpLive">๋ผ์ด๋ธ <span class="dp-sub">tvchak.live</span></label>
</div>
<div class="dp-opt">
<input type="radio" name="dpMode" id="dpNum" value="num">
<label for="dpNum">
<span class="dp-numwrap">tvchak<input class="dp-num" id="dpNumInput" type="number" min="1" max="9999" placeholder="208">.com</span>
</label>
</div>
<div class="dp-actions">
<button type="button" id="dpApply" class="primary">์ ์ฉ</button>
<button type="button" id="dpCancel">๋ซ๊ธฐ</button>
</div>
<div class="dp-msg" id="dpMsg"></div>
</div>
<!-- ๋ชจ๋ฐ์ผ ์ฑ๋ฐ -->
<div class="appbar show-on-mobile" style="background:
radial-gradient(ellipse at top left, rgba(229,9,20,0.15), transparent 70%),
var(--panel);">
<h1 id="appbarTitle" class="brand">
<span class="b-ott">OTT</span>
<span class="b-sep">โ</span>
<span class="b-player">PLAYER</span>
</h1>
<div class="badge-stack">
<span class="mode-badge" id="modeBadgeMob" title="์คํ ๋ชจ๋">โฆ</span>
<span class="domain-badge" id="domainBadgeMob" title="ํ์ฌ tvchak ๋๋ฉ์ธ">โฆ</span>
</div>
<div class="domain" id="domainStatus" hidden></div>
<small id="favCount" style="color:var(--muted);font-size:11px" hidden>0</small>
<button class="btn icon ghost" id="btnSearchToggle" title="๊ฒ์">๐</button>
</div>
<div class="profile-bar show-on-mobile">
<div class="profile-tabs" id="profileTabsMob"></div>
</div>
<!-- ์ข (๋ฐ์คํฌํ) -->
<aside class="pane left hide-on-mobile" id="paneLeft">
<div class="resize-handle" id="resizeHandle" title="๋๋น ์กฐ์ (๋๋๊ทธ)"></div>
<!-- ๋ก๊ณ -->
<div class="brand-wrap">
<h1 class="brand">
<span class="b-ott">OTT</span>
<span class="b-sep">โ</span>
<span class="b-player">PLAYER</span>
</h1>
<div class="badge-stack">
<span class="mode-badge" id="modeBadge" title="์คํ ๋ชจ๋">โฆ</span>
<span class="domain-badge" id="domainBadge" title="ํ์ฌ tvchak ๋๋ฉ์ธ">โฆ</span>
</div>
</div>
<!-- ํ๋กํ ํญ -->
<div class="profile-bar">
<div class="profile-tabs" id="profileTabs"></div>
</div>
<!-- ๊ฒ์ (๋ก๊ณ ๋ฐ) -->
<div style="padding:0 10px 6px">
<div class="search-bar ac-wrap">
<input class="text" id="searchInput" type="search" placeholder="์ ๋ชฉ์ผ๋ก ๊ฒ์" autocomplete="off" />
<button class="btn primary" id="btnSearch">๐</button>
<div class="ac-list" id="acListDt"></div>
</div>
<div id="searchResultsWrap" style="display:none;margin-top:8px">
<div style="display:flex;align-items:center;gap:8px;margin-bottom:6px">
<small style="color:var(--muted);font-size:11px;flex:1">๊ฒ์ ๊ฒฐ๊ณผ</small>
<button class="btn ghost" id="searchCloseDt" style="padding:2px 8px;font-size:11px">๋ซ๊ธฐ</button>
</div>
<div class="search-list" id="searchResults"></div>
</div>
</div>
<!-- ๋ณด๊ดํจ -->
<div style="padding:10px 12px 4px;border-top:1px solid var(--border);display:flex;align-items:center;gap:6px">
<h2 style="margin:0;font-size:13px;font-weight:600;color:var(--muted);letter-spacing:0.3px;flex:1">๋ด ๋ณด๊ดํจ</h2>
<button class="btn ghost" id="btnStatsDt" title="์์ฒญ ํต๊ณ" style="padding:2px 6px;font-size:13px">โ</button>
</div>
<div class="sort-bar">
<span>์ ๋ ฌ</span>
<select id="sortSelDt">
<option value="default">์ด์ด๋ณด๊ธฐ ์ฐ์ (๊ธฐ๋ณธ)</option>
<option value="recent">์ต๊ทผ ์์ฒญ์</option>
<option value="added">์ต๊ทผ ์ถ๊ฐ์</option>
<option value="title">์ ๋ชฉ์</option>
</select>
</div>
<div style="padding:0 10px 0" id="favListDt"></div>
<!-- ํค๋
ธ๋ผ์ด์ธ ๋ญํน -->
<div class="ranking-box hide-on-mobile" id="rankingBoxDt"></div>
</aside>
<!-- ์ค์ -->
<main class="center">
<div class="video-wrap" id="videoWrap">
<video id="player" preload="metadata" playsinline webkit-playsinline autopictureinpicture></video>
<!-- 3๋ฐฐ์ ๊พน๋๋ฅด๊ธฐ / ์ผ๋ฐ ์ธํฐ๋์
์บก์ฒ์ฉ ํฌ๋ช
์ค๋ฒ๋ ์ด.
์ผ์ฑ์ธํฐ๋ทยท์ผ๋ถ ์๋ Chrome์์ <video>๊ฐ long-press ์ด๋ฒคํธ๋ฅผ ์์ฒด์ ์ผ๋ก ์๋นํด
video์ ์ง์ ๋ถ์ธ ํธ๋ค๋ฌ๊ฐ ์ ๋จนํ. z-index:2 (video=1 ์) + ์ฐ๋ฆฌ UI(์ปจํธ๋กค๋ฐ ๋ฑ)๋ ๋ ์. -->
<div id="holdOverlay" class="hold-overlay"></div>
<div class="video-empty" id="videoEmpty">โถ ์ฆ๊ฒจ์ฐพ๊ธฐ๋ฅผ ์ ํํ๊ฑฐ๋ ๊ฒ์ํด๋ณด์ธ์.</div>
<div class="video-loading" id="videoLoading" style="display:none">๋ถ๋ฌ์ค๋ ์คโฆ</div>
<button id="btnSideToggle" class="side-toggle-btn" title="์ข์ธก ํจ๋ ํ ๊ธ">โฐ</button>
<button id="btnFsZoom" class="fs-zoom-btn" title="ํ๋ ๊ฐ๋ฅํ ์ ์ฒดํ๋ฉด">โถ</button>
<!-- ๋ชจ๋ฐ์ผ ํ์คํฌ๋ฆฐ ์ ์ฉ ํ๋ฉด ์ ๊ธ ๋ฒํผ (์ข์ธก ์ค์). ํ์์ CSS๋ก ์จ๊น.
์ด๊ธฐ ์์ด์ฝ์ "์ด๋ฆฐ ์๋ฌผ์ " โ ๋๋ฅด๋ฉด ์ ๊ธด๋ค๋ ์๋ฏธ. -->
<button id="btnLock" class="lock-btn" title="ํ๋ฉด ์ ๊ธ" aria-label="ํ๋ฉด ์ ๊ธ">
<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<rect x="4" y="11" width="16" height="10" rx="2"></rect>
<path d="M8 11V8a4 4 0 0 1 8 0v3M16 5v3"></path>
</svg>
</button>
<button id="pauseOverlay" class="pause-overlay" hidden>โถ</button>
<!-- ์คํ๋/์๋ฉ ์คํต ๋ฒํผ (chapter ๋๋ ์ฌ์ฉ์ ๋งํน ๊ตฌ๊ฐ ์ง์
์ ํ์) -->
<button id="btnSkip" class="skip-btn" hidden>์คํต โญ</button>
<!-- (์ ๊ฑฐ๋จ) โ ์ด์ zoom-ctrl์ด ์ผ๋ฐ/ํ์คํฌ๋ฆฐ ๊ณต์ฉ์ด๋ผ skipMarkers ํ๋๋ก ํต์ผ -->
<!-- (์ด์ #skipCtxMenu ์ฐํด๋ฆญ ๋ฉ๋ด๋ ์ ๊ฑฐ. ์คํต ๋งํน์ ์ปจํธ๋กค๋ฐ โฎ '๋๋ณด๊ธฐ' ๋ฉ๋ด๋ก ์ด๋.) -->
<!-- H-11: ํ์ง ์ ํ / H-5: ์ค๋์คยท์๋ง -->
<select id="hlsQuality" class="hls-quality" aria-label="ํ์ง"></select>
<select id="hlsAudio" class="hls-audio" aria-label="์ค๋์ค"></select>
<select id="hlsSub" class="hls-sub" aria-label="์๋ง"></select>
<!-- F-8: ๋ค์ ํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ -->
<button id="nextPreview" class="next-preview">๋ค์ โถ</button>
<!-- C5: ๋ค์ ํ ์นด์ดํธ๋ค์ด -->
<div id="nextCountdown" class="next-countdown">
<div class="nc-label">๋ค์ ํ ์๋์ฌ์๊น์ง <span id="ncSec">5</span>์ด</div>
<div class="nc-title" id="ncTitle"></div>
<div class="nc-bar"><div class="nc-bar-fill" id="ncBar"></div></div>
<div class="nc-actions">
<button id="ncCancel">์ทจ์</button>
<button id="ncGo" class="nc-go">์ง๊ธ ์์ฒญ</button>
</div>
</div>
<!-- D12: ์๋/์ฌ์์๋ ์ธ๋์ผ์ดํฐ -->
<div id="mediaToast" class="media-toast"></div>
<!-- ์ค ๋ชจ๋ ์ ์ฉ ์ปจํธ๋กค ์ค๋ฒ๋ ์ด -->
<div id="zoomCtrl" class="zoom-ctrl">
<button id="zcPlay" class="zc-btn" title="์ฌ์/์ผ์์ ์ง (Space/K)">โถ</button>
<span id="zcTime" class="zc-time">0:00 / 0:00</span>
<input id="zcBar" class="zc-bar" type="range" min="0" max="1000" value="0" style="flex:1;" />
<button id="zcMute" class="zc-btn" title="์์๊ฑฐ (M)">๐</button>
<input id="zcVol" class="zc-vol" type="range" min="0" max="100" value="100" title="๋ณผ๋ฅจ" />
<button id="zcMore" class="zc-btn" title="๋๋ณด๊ธฐ (์ฌ์์๋ยทPIPยท๋ค์ด๋ก๋)" aria-label="๋๋ณด๊ธฐ">โฎ</button>
<button id="zcReset" class="zc-btn zc-fs-only" title="์ค 1๋ฐฐ๋ก">โบ</button>
<button id="zcExit" class="zc-btn zc-fs-only" title="์ ์ฒดํ๋ฉด ๋๊ฐ๊ธฐ">โ</button>
</div>
<!-- โฎ ๋๋ณด๊ธฐ ๋ฉ๋ด (PIPยท์ฌ์์๋ยท๋ค์ด๋ก๋) -->
<div id="moreMenu" class="more-menu" hidden>
<div class="more-sec">
<div class="more-sec-h">์ฌ์ ์๋</div>
<div class="more-rates">
<button data-rate="0.5">0.5ร</button>
<button data-rate="0.75">0.75ร</button>
<button data-rate="1">1ร</button>
<button data-rate="1.25">1.25ร</button>
<button data-rate="1.5">1.5ร</button>
<button data-rate="1.75">1.75ร</button>
<button data-rate="2">2ร</button>
</div>
</div>
<div class="more-actions">
<button class="more-item" id="mmPip" title="PIP (D)">๐ช PIP</button>
<button class="more-item" id="mmDownload" hidden title="๋ค์ด๋ก๋">โฌ ๋ค์ด๋ก๋</button>
</div>
<div class="more-sec">
<div class="more-skip">
<div class="more-skip-row">
<button class="more-item more-skip-main" data-skip="opEnd" title="์คํ๋ ๋ (์์=0:00 ์๋)"><span class="lbl">์คํ๋ ๋</span><span class="t" data-key="opEnd"></span></button>
<button class="more-skip-clear" data-skip="clearOp" title="์คํ๋ ์ด๊ธฐํ" aria-label="์คํ๋ ์ด๊ธฐํ">โ</button>
</div>
<div class="more-skip-row">
<button class="more-item more-skip-main" data-skip="edFromEnd" title="์๋ฉ ์คํต ์์์ "><span class="lbl">์๋ฉ ์์</span><span class="t" data-key="edFromEnd"></span></button>
<button class="more-skip-clear" data-skip="clearEd" title="์๋ฉ ์ด๊ธฐํ" aria-label="์๋ฉ ์ด๊ธฐํ">โ</button>
</div>
</div>
</div>
</div>
</div>
<!-- ๋ชจ๋ฐ์ผ/๋ฐ์คํฌํ ๋ชจ๋์์ ๋น๋์ค ์๋์ ๋ฉํ+ํ์ฐจ+(๋ชจ๋ฐ์ผ์ ์ฆ๊ฒจ์ฐพ๊ธฐ/๊ฒ์๊น์ง) -->
<div class="center-bottom content">
<div class="now-meta" id="nowMeta"></div>
<!-- ํ์ฐจ ๊ฐ๋ก ์คํฌ๋กค + ๊ทธ๋ฆฌ๋ ํ ๊ธ (๊ธฐ๋ณธ ์ ํ โ ์ฌ์ฉ์๊ฐ '์ ์ฒด ๋ณด๊ธฐ' ํด๋ฆญ ์๋ง ํผ์นจ) -->
<div id="epSection" style="display:none">
<div class="section-h">
<h2>ํ์ฐจ</h2>
<button class="ep-grid-toggle" id="epGridToggle">์ ์ฒด ๋ณด๊ธฐ</button>
</div>
<div class="ep-strip" id="epStrip"></div>
<div class="ep-grid hidden" id="epGrid">
<div class="ep-search"><input type="search" id="epSearch" placeholder="ํ์ฐจ ๋ฒํธ ๊ฒ์ (์: 1162)" autocomplete="off" /></div>
<div id="epGridList"></div>
</div>
</div>
<!-- ๋ชจ๋ฐ์ผ์์๋ง: ๊ฒ์(์๋จ) / ์ฆ๊ฒจ์ฐพ๊ธฐ / ๋ญํน -->
<div class="show-on-mobile">
<!-- ๊ฒ์ (๋ณด๊ดํจ ์) -->
<div class="section-h" id="searchHead" style="display:none">
<h2>๊ฒ์ ๊ฒฐ๊ณผ</h2>
<button class="btn ghost" id="searchClose" style="padding:4px 8px;font-size:11px">๋ซ๊ธฐ</button>
</div>
<div class="search-bar ac-wrap" id="searchBar" style="display:none">
<input class="text" id="searchInputMob" type="search" placeholder="์ ๋ชฉ์ผ๋ก ๊ฒ์" autocomplete="off" />
<button class="btn primary" id="btnSearchMob">๐</button>
<div class="ac-list" id="acListMob"></div>
</div>
<div class="search-list" id="searchResultsMob" style="margin-bottom:12px"></div>
<div class="section-h" style="display:flex;align-items:center;gap:6px">
<h2 style="flex:1">๋ด ๋ณด๊ดํจ</h2>
<button class="btn ghost" id="btnStatsMob" title="์์ฒญ ํต๊ณ" style="padding:2px 8px;font-size:14px">โ</button>
</div>
<div class="sort-bar">
<span>์ ๋ ฌ</span>
<select id="sortSelMob">
<option value="default">์ด์ด๋ณด๊ธฐ ์ฐ์ (๊ธฐ๋ณธ)</option>
<option value="recent">์ต๊ทผ ์์ฒญ์</option>
<option value="added">์ต๊ทผ ์ถ๊ฐ์</option>
<option value="title">์ ๋ชฉ์</option>
</select>
</div>
<div class="fav-list" id="favListMob"></div>
<!-- ํค๋
ธ๋ผ์ด์ธ ๋ญํน (๋ชจ๋ฐ์ผ ๋ณด๊ดํจ ๋ฐ) -->
<div class="ranking-box show-on-mobile" id="rankingBoxMob"></div>
</div>
</div>
</main>
<!-- G-10: ๋จ์ถํค ์๋ด ๋ชจ๋ฌ -->
<div class="modal-bg" id="shortcutsModal">
<div class="stats-modal">
<h2 style="margin:0 0 12px;font-size:16px">๋จ์ถํค ์๋ด</h2>
<div style="font-size:13px;color:var(--text)">
<div class="stat-row"><span>Space / K</span><b>์ฌ์ / ์ผ์์ ์ง</b></div>
<div class="stat-row"><span>M</span><b>์์๊ฑฐ ํ ๊ธ</b></div>
<div class="stat-row"><span>โ / โ</span><b>5์ด ์ด๋ (Shift = 10์ด)</b></div>
<div class="stat-row"><span>N / P</span><b>๋ค์ ํ / ์ด์ ํ</b></div>
<div class="stat-row"><span>F</span><b>ํ์คํฌ๋ฆฐ (ํ๋ ๊ฐ๋ฅ)</b></div>
<div class="stat-row"><span>D</span><b>Picture-in-Picture</b></div>
<div class="stat-row"><span>S</span><b>์ข์ธก ํจ๋ ์ ๊ธฐ/ํผ์น๊ธฐ</b></div>
<div class="stat-row"><span>+ / โ</span><b>ํ์คํฌ๋ฆฐ ์์ ํ๋/์ถ์</b></div>
<div class="stat-row"><span>Shift + / โ</span><b>์ฌ์ ์๋ 0.25ร ์กฐ์ </b></div>
<div class="stat-row" style="margin-top:6px;padding-top:6px;border-top:1px solid var(--border)"><span>]</span><b>์คํ๋ ๋ ๋งํน (์์=0:00 ์๋)</b></div>
<div class="stat-row"><span>;</span><b>์๋ฉ ์คํต (ํ์ฌ ์์น์ ๋จ์ ์๊ฐ์ผ๋ก ์๋ ์ ์ฅ)</b></div>
<div class="stat-row"><span>'</span><b>๋งํน ์ ์ฒด ์ด๊ธฐํ</b></div>
<div class="stat-row" style="margin-top:6px;padding-top:6px;border-top:1px solid var(--border)"><span>?</span><b>์ด ์๋ด ๋ณด๊ธฐ</b></div>
<div style="margin-top:14px;font-size:11px;color:var(--muted)">
โข ์์ ์ฐํด๋ฆญ / ๊ธธ๊ฒ ๋๋ฅด๊ธฐ โ ๋งํน ๋ฉ๋ด<br>
โข โฎ ๋ฒํผ โ ์ฌ์์๋ยทPIPยท๋ค์ด๋ก๋<br>
โข ๋ค์ ํ ์นด์ดํธ๋ค์ด ์ค์๋ Enter=์ง๊ธ ์์ฒญ, Esc=์ทจ์, Space=์ผ์์ ์ง
</div>
</div>
<div class="actions" style="margin-top:14px;text-align:right">
<button class="btn" id="shortcutsClose">๋ซ๊ธฐ</button>
</div>
</div>
</div>
<!-- D14: ์์ฒญ ํต๊ณ ๋ชจ๋ฌ -->
<div class="modal-bg" id="statsModal">
<div class="stats-modal">
<h2 style="margin:0 0 10px;font-size:16px">์์ฒญ ํต๊ณ</h2>
<div id="statsBody" style="font-size:13px;color:var(--text)"></div>
<div class="actions" style="margin-top:14px;text-align:right">
<button class="btn" id="statsClose">๋ซ๊ธฐ</button>
</div>
</div>
</div>
<!-- ์ถ๊ฐ ๋ชจ๋ฌ -->
<div class="modal-bg" id="addModal">
<div class="modal">
<h2>์ฆ๊ฒจ์ฐพ๊ธฐ ์ถ๊ฐ</h2>
<label>ํฐ๋น์ฐฉ URL ๋๋ ์์ ID</label>
<input class="text" id="addUrl" type="text" placeholder="122838 ๋๋ https://tvchakโฆ/detail/id/122838.html" />
<div class="hint">์ซ์ ID(์: <code>122838</code>) ๋๋ detail/play URL์ ๋ถ์ฌ๋ฃ์ด๋ ๋ฉ๋๋ค.</div>
<div class="actions">
<button class="btn" id="addCancel">์ทจ์</button>
<button class="btn primary" id="addOk">์ถ๊ฐ</button>
</div>
</div>
</div>
<script>
'use strict';
// โโโ ์๊ตฌ ์ธ์ฆ ํ ํฐ (Basic Auth ํ ๋ฒ ํต๊ณผ ํ ์๊ตฌ ์ ์ง) โโโ
// localStorage์ ํ ํฐ ์ ์ฅ โ fetch ๊ฐ๋ก์ฑ์ X-Auth-Token ํค๋ ์๋ ์ฒจ๋ถ.
// ์ฟ ํค๊ฐ ITP/์บ์ ์ฒญ์๋ก ๋ง๋ฃ๋ผ๋ ํ ํฐ๋ง ์์ผ๋ฉด ์๋ฒ๊ฐ ์ฆ์ ์ฟ ํค ์ฌ๋ฐ๊ธ.
(function setupAuthToken() {
const LS_AUTH = 'tvchak.authToken';
const _fetch = window.fetch.bind(window);
window.fetch = function(input, init) {
init = init || {};
const headers = new Headers(init.headers || (typeof input !== 'string' && input.headers) || {});
const tok = localStorage.getItem(LS_AUTH);
if (tok && !headers.has('X-Auth-Token')) headers.set('X-Auth-Token', tok);
init.headers = headers;
// ์ฟ ํค ํฌํจ ๋ณด์ฅ
if (!init.credentials) init.credentials = 'same-origin';
return _fetch(input, init);
};
// ํ ํฐ ์์ผ๋ฉด ํ ๋ฒ ์์ฒญํด์ ๋ฐ์ ์ ์ฅ (ํ์ฌ ์์ฒญ์ Basic Auth/์ฟ ํค๋ก ์ด๋ฏธ ํต๊ณผํ ์ํ์ฌ์ผ ํจ)
if (!localStorage.getItem(LS_AUTH)) {
_fetch('/api/auth-token', { credentials: 'same-origin' })
.then(r => r.ok ? r.json() : null)
.then(j => { if (j && j.token) localStorage.setItem(LS_AUTH, j.token); })
.catch(() => {});
}
})();
// โโโ ์ํ/์ ์ฅ โโโ
const LS_PROFILE = 'tvchak.profile';
let currentProfile = parseInt(localStorage.getItem(LS_PROFILE) || '1', 10);
if (!(currentProfile >= 1 && currentProfile <= 5)) currentProfile = 1;
const lsKey = (k) => `tvchak.p${currentProfile}.${k}`;
const LS_FAV = () => lsKey('favs');
const LS_LAST = () => lsKey('lastFavId');
const LS_RECENT_SEARCH = 'tvchak.recentSearch'; // ์ ์ญ (ํ๋กํ ๋ฌด๊ด)
const LS_SORT = () => lsKey('sortMode');
const LS_RESUME_HERO_DISMISS = () => lsKey('resumeHeroDismiss'); // ๋ง์ง๋ง ๋ซ์ favId+label
// ์ต๊ทผ ๊ฒ์์ด (์ ์ญ, ์์ 10๊ฐ)
function loadRecentSearches() {
try { return JSON.parse(localStorage.getItem(LS_RECENT_SEARCH)) || []; } catch { return []; }
}
function pushRecentSearch(wd) {
wd = (wd || '').trim();
if (!wd) return;
let list = loadRecentSearches().filter(w => w !== wd);
list.unshift(wd);
if (list.length > 10) list = list.slice(0, 10);
localStorage.setItem(LS_RECENT_SEARCH, JSON.stringify(list));
}
function removeRecentSearch(wd) {
const list = loadRecentSearches().filter(w => w !== wd);
localStorage.setItem(LS_RECENT_SEARCH, JSON.stringify(list));
}
let favs = load(LS_FAV(), []);
let lastFavId = localStorage.getItem(LS_LAST());
let domainInfo = null;
let currentFavId = null;
let currentFavSource = null; // 'tvchak' | 'anilife' โ ๊ฐ์ id๊ฐ ๋ ์์ค์ ์์ ์ ์์
let currentEpList = [];
let currentEpIdx = -1;
let activeRightTab = 'ep'; // ๋ฐ์คํฌํ ์ฐ์ธก
function load(k, def) { try { return JSON.parse(localStorage.getItem(k)) || def; } catch { return def; } }
function save(k, v) { localStorage.setItem(k, JSON.stringify(v)); }
// ์ฌ์ฉ์๊ฐ ์ด๋ค ํ์ฐจ๋ฅผ ๋ณธ ๊ฒฐ๊ณผ lastSeenLabel/lastSeenCount๊ฐ ๊ฐฑ์ ๋ ๋ ํธ์ถ.
// lastSeenLabel === latestLabel์ด๋ฉด "๋ค ๋ฐ๋ผ์ก์" ์์ โ caughtUpAtLabel/Count ๋งํน.
// ์ดํ ์ ํ์ฐจ๊ฐ ์ถ๊ฐ๋๋ฉด(=latestLabelยทknownCount ๋ณํ) NEW ํ์ ๊ฐ๋ฅ.
function markCaughtUpIfNeeded(f) {
if (!f) return;
if (f.lastSeenLabel && f.latestLabel && f.lastSeenLabel === f.latestLabel) {
f.caughtUpAtLabel = f.latestLabel;
f.caughtUpAtCount = f.knownCount != null ? f.knownCount : (f.lastSeenCount || null);
}
}
// ์๋ฒ ๋๊ธฐํ: saveFavs๋ ํญ์ ๋ก์ปฌ+์๋ฒ ์์ชฝ์. ๋น๋ฒํ PUT ๋ฐฉ์ง๋ฅผ ์ํด ๋๋ฐ์ด์ค.
let _saveTimer = null;
let _pendingPut = false; // ๋๋ฐ์ด์ค ํ์ ๋ค์ด๊ฐ ์์ง ์๋ฒ๋ก ์ ๊ฐ ๋ณ๊ฒฝ ์์์ ํ์ (pull๊ณผ ์ถฉ๋ ๋ฐฉ์ง)
function saveFavs() {
save(LS_FAV(), favs);
// ๋๋ฐ์ด์ค 1์ด
clearTimeout(_saveTimer);
_pendingPut = true;
_saveTimer = setTimeout(() => {
fetch('/api/favs?profile=' + currentProfile, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ favs, lastFavId }),
}).catch(() => {}).finally(() => { _pendingPut = false; });
}, 1000);
}
// E1: ํ๋กํ ๋ณ์นญ (์๋ฒ์ ์ ์ฅ โ ๋ชจ๋ ๋๋ฐ์ด์ค ๊ณต์ )
let _profileLabels = {1:'', 2:'', 3:'', 4:'', 5:''};
async function loadProfileLabels() {
try {
const r = await api('/api/profile-labels');
if (r && r.labels) {
_profileLabels = { ..._profileLabels, ...r.labels };
renderProfileTabs();
}
} catch (e) { console.warn('loadProfileLabels:', e.message); }
}
async function saveProfileLabel(n, name) {
name = (name || '').trim().slice(0, 30);
_profileLabels[n] = name;
renderProfileTabs();
// n๋ฒ ํ๋กํ์ favs payload์ nickname์ ํฉ์ณ์ PUT (์๋ฒ๊ฐ ๋ค๋ฅธ ํ๋ ๋ณด์กด)
try {
const cur = load(`tvchak.p${n}.favs`, []);
const last = localStorage.getItem(`tvchak.p${n}.lastFavId`);
await fetch('/api/favs?profile=' + n, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ favs: cur, lastFavId: last, nickname: name }),
});
} catch (e) { console.warn('saveProfileLabel:', e.message); }
}
function promptProfileLabel(n) {
// inline input โ ํ์ฑ ํญ ๋ด๋ถ์ input ์์ฑ
for (const host of [$('#profileTabs'), $('#profileTabsMob')]) {
if (!host) continue;
const btn = host.querySelector(`.profile-tab[data-n="${n}"]`);
if (!btn || btn.querySelector('input')) continue;
const cur = _profileLabels[n] || '';
btn.textContent = '';
const inp = document.createElement('input');
inp.type = 'text';
inp.value = cur;
inp.placeholder = '๋ณ์นญ (์: ๋์, ๊ฐ์กฑ)';
inp.maxLength = 30;
inp.style.cssText = 'width:100%;background:transparent;border:0;outline:0;color:inherit;font:inherit;text-align:center;padding:0;box-sizing:border-box;display:block;';
inp.addEventListener('click', e => e.stopPropagation());
inp.addEventListener('keydown', (e) => {
if (e.key === 'Enter') { e.preventDefault(); inp.blur(); }
if (e.key === 'Escape') { e.preventDefault(); _profileLabels[n] = cur; renderProfileTabs(); }
});
inp.addEventListener('blur', () => {
const newName = inp.value.trim();
if (newName !== cur) saveProfileLabel(n, newName);
else renderProfileTabs();
});
btn.appendChild(inp);
setTimeout(() => { inp.focus(); inp.select(); }, 0);
}
}
async function switchProfile(n) {
n = parseInt(n, 10);
if (!(n >= 1 && n <= 5)) return;
// E1: ์ด๋ฏธ ํ์ฑ ํญ์ ๋ค์ ํด๋ฆญํ๋ฉด ๋ณ์นญ ์
๋ ฅ ๋ชจ๋
if (n === currentProfile) {
promptProfileLabel(n);
return;
}
currentProfile = n;
localStorage.setItem(LS_PROFILE, String(n));
// ์ ํ๋กํ ๋ก๋ฉ
favs = load(LS_FAV(), []);
lastFavId = localStorage.getItem(LS_LAST());
currentFavId = null;
stopPlayer();
renderFavs();
renderProfileTabs();
await pullFavsFromServer();
renderFavs();
if (lastFavId && favs.find(f => f.id == lastFavId)) {
await selectFav(+lastFavId, { silent: true });
}
}
function renderProfileTabs() {
for (const host of [$('#profileTabs'), $('#profileTabsMob')]) {
if (!host) continue;
host.innerHTML = '';
for (let i = 1; i <= 5; i++) {
const b = document.createElement('button');
b.className = 'profile-tab' + (i === currentProfile ? ' active' : '');
b.dataset.n = i;
const lab = _profileLabels[i];
// ๋ณ์นญ์ด ์์ผ๋ฉด ๋ณ์นญ ํ์, ์์ผ๋ฉด ์ซ์. ํ์ฑ ํญ์ ํด๋ฆญ ์ ๋ณ์นญ ํธ์ง.
b.textContent = lab || String(i);
b.title = lab ? `${lab} (ํ๋กํ ${i}) โ ๋ค์ ํด๋ฆญํ๋ฉด ์ด๋ฆ ์์ ` : `ํ๋กํ ${i} โ ๋ค์ ํด๋ฆญํ๋ฉด ์ด๋ฆ ์ง์ `;
b.addEventListener('click', () => switchProfile(i));
host.appendChild(b);
}
}
}
async function pullFavsFromServer() {
// ๋๋ฐ์ด์ค ํ์ push ๋๊ธฐ ์ค์ด๋ฉด pull ๋ณด๋ฅ โ ๋ด ๋ก์ปฌ ๋ณ๊ฒฝ์ด ๋ฎ์ด์ฐ์ฌ์ง์ง ์๊ฒ
if (_pendingPut) return;
try {
const r = await fetch('/api/favs?profile=' + currentProfile, { cache: 'no-store' });
if (!r.ok) return;
const data = await r.json();
if (!Array.isArray(data.favs)) return;
const serverEmpty = data.favs.length === 0;
const localHasData = favs && favs.length > 0;
if (serverEmpty && localHasData) {
await fetch('/api/favs?profile=' + currentProfile, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ favs, lastFavId }),
}).catch(() => {});
return;
}
if (!serverEmpty) {
favs = data.favs;
// ๋ง์ด๊ทธ๋ ์ด์
: source ์์ผ๋ฉด tvchak์ผ๋ก ์ฑ์
let migrated = false;
for (const f of favs) {
if (!f.source) { f.source = 'tvchak'; migrated = true; }
}
// 1ํ์ฑ ๋ง์ด๊ทธ๋ ์ด์
: caughtUpAt* ์๊ณ lastSeenLabel === latestLabel์ด๋ฉด ๋ฐ๋ผ์ก์ ๊ฒ์ผ๋ก ๊ฐ์ฃผ
for (const f of favs) {
if (f.caughtUpAtLabel == null && f.lastSeenLabel && f.latestLabel && f.lastSeenLabel === f.latestLabel) {
markCaughtUpIfNeeded(f);
migrated = true;
}
}
if (data.lastFavId) { lastFavId = String(data.lastFavId); localStorage.setItem(LS_LAST(), lastFavId); }
save(LS_FAV(), favs);
if (migrated) saveFavs();
}
} catch {}
}
const $ = s => document.querySelector(s);
const $$ = s => [...document.querySelectorAll(s)];
const esc = s => String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
const isMobile = () => matchMedia('(max-width: 1023.98px)').matches;
// namu CDN์ datacenter/์ผ๋ถ ์ฌ์ฉ์ IP๋ฅผ 403 ์ฐจ๋จ โ ์ฐ๋ฆฌ ์๋ฒ /img-proxy ๊ฒฝ์ ๋ก ์ฐํ.
const viaProxy = (u) => /^https:\/\/i\.namu\.wiki\//.test(u || '') ? `/img-proxy?url=${encodeURIComponent(u)}` : u;
// E-3: ์๋์๊ฐ ("๋ฐฉ๊ธ", "3๋ถ ์ ", "์ด์ ", "3์ผ ์ " ๋ฑ)
function timeAgo(ts) {
if (!ts) return '';
const sec = Math.max(0, (Date.now() - ts) / 1000);
if (sec < 60) return '๋ฐฉ๊ธ';
if (sec < 3600) return Math.floor(sec / 60) + '๋ถ ์ ';
if (sec < 86400) return Math.floor(sec / 3600) + '์๊ฐ ์ ';
if (sec < 172800) return '์ด์ ';
if (sec < 604800) return Math.floor(sec / 86400) + '์ผ ์ ';
if (sec < 2592000) return Math.floor(sec / 604800) + '์ฃผ ์ ';
if (sec < 31536000) return Math.floor(sec / 2592000) + '๊ฐ์ ์ ';
return Math.floor(sec / 31536000) + '๋
์ ';
}
// H-9: ํ๊ธ ์ด์ฑ ์ถ์ถ (์๋ชจ ๋ถ๋ฆฌ). ์๋ฌธ/์ซ์/ํน์๋ฌธ์๋ ๊ทธ๋๋ก.
function toChosung(str) {
const CHO = ['ใฑ','ใฒ','ใด','ใท','ใธ','ใน','ใ
','ใ
','ใ
','ใ
','ใ
','ใ
','ใ
','ใ
','ใ
','ใ
','ใ
','ใ
','ใ
'];
let out = '';
for (const c of String(str || '')) {
const code = c.charCodeAt(0) - 0xAC00;
if (code >= 0 && code <= 11171) out += CHO[Math.floor(code / 588)];
else out += c.toLowerCase();
}
return out;
}
// H-9 ํฌํผ: ์ฟผ๋ฆฌ๊ฐ ๋ชจ๋ ใฑ-ใ
์์์ผ๋ก๋ง ๊ตฌ์ฑ๋์ด ์๋์ง (์ด์ฑ ๊ฒ์ ๋ชจ๋ ํ์ )
function isChosungQuery(q) {
return /^[ใฑ-ใ
\s]+$/.test(q);
}
// โโโ API โโโ
// A4: API ์คํจ ์ฐ์ ์นด์ดํธ โ ๋ฐฐ๋ ํ์
let _apiConsecutiveFail = 0;
function _setErrBanner(on) {
const el = document.getElementById('errBanner');
if (!el) return;
el.classList.toggle('show', !!on);
}
async function api(path, opts = {}) {
// ๊ธฐ๋ณธ 60์ด timeout (HF Spaces ์๋ต ๋๋ฆด ๋ ๋๋น). hang ๋ฐฉ์ง.
const timeoutMs = opts.timeout || 60000;
const ctrl = new AbortController();
const t = setTimeout(() => ctrl.abort(), timeoutMs);
try {
const r = await fetch(path, { cache: 'no-store', signal: ctrl.signal });
if (!r.ok) throw new Error('HTTP ' + r.status);
const j = await r.json();
if (_apiConsecutiveFail > 0) { _apiConsecutiveFail = 0; _setErrBanner(false); }
return j;
} catch (e) {
_apiConsecutiveFail++;
if (_apiConsecutiveFail >= 2) _setErrBanner(true);
throw e;
} finally {
clearTimeout(t);
}
}
// โโโ ๋๋ฉ์ธ ํ์ โโโ
async function loadDomain() {
try {
const d = await api('/api/domain');
domainInfo = d;
const txt = d.domain ? d.domain : '๋๋ฉ์ธ ํ์ง ์คํจ';
$('#domainStatus').textContent = txt;
if (!d.domain) $('#domainStatus').classList.add('bad');
if ($('#domainStatusDt')) $('#domainStatusDt').textContent = 'ํ์ฌ: ' + txt;
// ์๋จ ๋ฐฐ์ง (์ข์ธก ๋ชจ๋ / ์ฐ์ธก ๋๋ฉ์ธ). ๋ฐ์คํฌํยท๋ชจ๋ฐ์ผ ๋ ๋ค.
const mode = d.mode || 'local';
const modeLabel = mode === 'cdp' ? 'CDP' : mode === 'hf' ? 'HF' : 'LOCAL';
for (const id of ['modeBadge', 'modeBadgeMob']) {
const el = document.getElementById(id);
if (!el) continue;
el.textContent = modeLabel;
el.classList.remove('mode-cdp', 'mode-local', 'mode-hf');
el.classList.add('mode-' + mode);
}
const domainShort = d.domain ? d.domain.replace(/\.com$/, '') : 'โ
';
const isOverride = !!(d.override || d.forced); // ์๋ ๊ณ ์ ์ํ๋ฉด ๋ฐฐ์ง๋ฅผ ๋
ธ๋๊ฒ
for (const id of ['domainBadge', 'domainBadgeMob']) {
const el = document.getElementById(id);
if (!el) continue;
el.textContent = domainShort;
el.classList.toggle('bad', !d.domain);
el.classList.toggle('ov', isOverride && !!d.domain);
el.title = (isOverride ? '์๋ ๊ณ ์ ' : '์๋(announce)') + ': ' + (d.domain || 'ํ์ง ์คํจ') + ' โ ํด๋ฆญํด์ ๋ณ๊ฒฝ';
}
} catch (e) {
$('#domainStatus').textContent = 'API ์ค๋ฅ';
$('#domainStatus').classList.add('bad');
for (const id of ['modeBadge', 'modeBadgeMob', 'domainBadge', 'domainBadgeMob']) {
const el = document.getElementById(id);
if (el) { el.textContent = 'ERR'; el.classList.add('bad'); }
}
}
}
// โโโ ๋๋ฉ์ธ ์ ํ ํ์
โโโ
// ๋ฐฐ์ง ํด๋ฆญ โ ํ์
. ์๋ / ๋ผ์ด๋ธ(tvchak.live) / ๋ฒํธ(tvchakNNN.com, ์ง์ ์
๋ ฅ) ์ค ์ ํ.
// POST /api/domain-override ๋ก ์๋ฒ์ ์ ์ฅ โ ๋ชจ๋ ๊ธฐ๊ธฐ ๊ณตํต ๋ฐ์. '์๋' ์ ํ ์ ์ค๋ฒ๋ผ์ด๋ ํด์ .
function openDomainPop(anchorEl) {
const pop = $('#domainPop');
if (!pop) return;
const msg = $('#dpMsg'); if (msg) { msg.textContent = ''; msg.className = 'dp-msg'; }
// ํ์ฌ ์ํ๋ก ๋ผ๋์ค/์
๋ ฅ ํ๋ฆฌํ
const d = domainInfo || {};
const cur = d.domain || '';
const numM = cur.match(/^tvchak(\d+)\.com$/);
if (d.override || d.forced) {
if (cur === 'tvchak.live') $('#dpLive').checked = true;
else if (numM) { $('#dpNum').checked = true; $('#dpNumInput').value = numM[1]; }
else $('#dpAuto').checked = true;
} else {
$('#dpAuto').checked = true;
// ์๋์ด์ด๋ ๋ฒํธ ์
๋ ฅ์นธ์ ํ์ฌ ๊ฐ์ง๋ ๋ฒํธ๋ฅผ ์ฐธ๊ณ ์ฉ์ผ๋ก ์ฑ์๋
if (numM && !$('#dpNumInput').value) $('#dpNumInput').value = numM[1];
}
if (d.forced) {
if (msg) { msg.textContent = 'โ ์๋ฒ๊ฐ FORCE_DOMAIN์ผ๋ก ๊ณ ์ ์ค โ ์ ์ฅํด๋ ๋ฌด์๋ฉ๋๋ค.'; msg.className = 'dp-msg err'; }
}
// ์์น: ์ต์ปค ๋ฐฐ์ง ์๋. ํ๋ฉด ๋ฐ์ผ๋ก ์ ๋๊ฐ๊ฒ ํด๋จํ.
pop.classList.add('show');
const r = anchorEl.getBoundingClientRect();
const pw = pop.offsetWidth, ph = pop.offsetHeight;
let left = Math.min(r.left, window.innerWidth - pw - 8);
left = Math.max(8, left);
let top = r.bottom + 6;
if (top + ph > window.innerHeight - 8) top = Math.max(8, r.top - ph - 6);
pop.style.left = left + 'px';
pop.style.top = top + 'px';
}
function closeDomainPop() { const pop = $('#domainPop'); if (pop) pop.classList.remove('show'); }
async function applyDomainOverride() {
const msg = $('#dpMsg');
const setMsg = (t, cls) => { if (msg) { msg.textContent = t; msg.className = 'dp-msg ' + (cls || ''); } };
const mode = (document.querySelector('input[name="dpMode"]:checked') || {}).value;
let domain = null; // null = ์๋(ํด์ )
if (mode === 'live') domain = 'tvchak.live';
else if (mode === 'num') {
const n = ($('#dpNumInput').value || '').trim();
if (!/^\d+$/.test(n)) { setMsg('๋ฒํธ๋ฅผ ์ซ์๋ก ์
๋ ฅํด ์ฃผ์ธ์.', 'err'); return; }
domain = 'tvchak' + n + '.com';
}
setMsg('์ ์ฉ ์คโฆ', '');
try {
const r = await fetch('/api/domain-override', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ domain }),
});
const j = await r.json().catch(() => ({}));
if (!r.ok || j.error) throw new Error(j.error || ('HTTP ' + r.status));
setMsg(domain ? ('๊ณ ์ : ' + domain) : '์๋(announce)์ผ๋ก ๋ณต๊ท', 'ok');
await loadDomain(); // ๋ฐฐ์ง ์ฆ์ ๊ฐฑ์
// ๋๋ฉ์ธ์ด ๋ฐ๋์์ผ๋ ํ์ฌ ์ด๋ฆฐ ํ์ฐจ/๋ชฉ๋ก์ ๋ค์ ์ก์
๋ถํฐ ์ ๋๋ฉ์ธ์ผ๋ก fetch๋จ.
setTimeout(closeDomainPop, 700);
} catch (e) {
setMsg('์คํจ: ' + (e.message || e), 'err');
}
}
// ๋ฐฐ์ง ํด๋ฆญ ๋ฐ์ธ๋ฉ (๋ฐ์คํฌํยท๋ชจ๋ฐ์ผ)
for (const id of ['domainBadge', 'domainBadgeMob']) {
const el = document.getElementById(id);
if (el) el.addEventListener('click', (ev) => { ev.stopPropagation(); openDomainPop(el); });
}
{
const applyBtn = $('#dpApply'); if (applyBtn) applyBtn.addEventListener('click', applyDomainOverride);
const cancelBtn = $('#dpCancel'); if (cancelBtn) cancelBtn.addEventListener('click', closeDomainPop);
// ๋ฐ๊นฅ ํด๋ฆญ / ESC ๋ก ๋ซ๊ธฐ
document.addEventListener('click', (ev) => {
const pop = $('#domainPop');
if (pop && pop.classList.contains('show') && !pop.contains(ev.target)) closeDomainPop();
});
document.addEventListener('keydown', (ev) => { if (ev.key === 'Escape') closeDomainPop(); });
// ๋ฒํธ ์
๋ ฅ์นธ ํฌ์ปค์ค ์ ์๋์ผ๋ก '๋ฒํธ' ๋ผ๋์ค ์ ํ
const numInput = $('#dpNumInput');
if (numInput) numInput.addEventListener('focus', () => { $('#dpNum').checked = true; });
}
// โโโ ์
๋ ฅ ํ์ฑ โโโ
function parseInput(input) {
input = input.trim();
let m;
// anilife URL
if ((m = input.match(/anilife\.app\/content\/(\d+)/i))) return { id: +m[1], source: 'anilife' };
// tvchak ํจํด๋ค
if ((m = input.match(/\/vod\/play\/id\/(\d+)\/sid\/(\d+)\/nid\/(\d+)/))) return { id: +m[1], sid: +m[2], nid: +m[3], source: 'tvchak' };
if ((m = input.match(/\/vod\/detail\/id\/(\d+)/))) return { id: +m[1], source: 'tvchak' };
if (/^\d+$/.test(input)) return { id: +input, source: 'tvchak' };
return null;
}
// โโโ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ ๋ โโโ
function renderFavs() {
const filterMob = ($('#filterMob')?.value || '').trim().toLowerCase();
const filterDt = ($('#filter')?.value || '').trim().toLowerCase();
const activeId = currentFavId || lastFavId;
// ์ ๋ ฌ: โ ์ด์ด๋ณด๊ธฐ ๊ฐ๋ฅ โ โก NEW โ โข ์ ๋ชฉ ๊ฐ๋๋ค
// NEW: "๋ค ๋ฐ๋ผ์ก์ ํ ์ ํ์ฐจ๊ฐ ์ง์ง๋ก ์ถ๊ฐ๋" ๊ฒฝ์ฐ์๋ง ํ์
// - ์ด์ด๋ณด๊ธฐ ์์ผ๋ฉด ์ ๋ NEW ์ ๋ธ (์ด์ด๋ณด๊ธฐ ์ฐ์ )
// - ์ฌ์ฉ์๊ฐ ์ต์ ํ ์์ฒญ ์์ ์ caughtUpAtLabel/caughtUpAtCount ๋งํน๋จ (markCaughtUp)
// - ์ดํ latestLabel์ด ๋งํน๊ฐ๊ณผ ๋ค๋ฅด๊ณ + knownCount๊ฐ ์ฆ๊ฐํ์ผ๋ฉด โ ์ง์ง ์ ํ์ฐจ ์ถ๊ฐ โ NEW
// - ์ด์ค ๊ฒ์ฆ์ผ๋ก ๋ผ๋ฒจ ์ฌ๋ฐฐ์ดยท7.5ํ ๊ฐ์ ๋
ธ์ด์ฆ์ ๊ฐํจ
const isNewOf = f => {
if (isResumableOf(f)) return false;
if (!f.latestLabel || !f.caughtUpAtLabel) return false;
if (f.latestLabel === f.caughtUpAtLabel) return false;
if (f.knownCount == null || f.caughtUpAtCount == null) return false;
return f.knownCount > f.caughtUpAtCount;
};
const isResumableOf = f => {
if (!f.lastLabel || !f.progress) return false;
const p = f.progress[f.lastLabel];
return !!(p && !p.finished && typeof p.time === 'number' && p.time > 5);
};
const rank = f => isResumableOf(f) ? 0 : (isNewOf(f) ? 1 : 2);
// D2: ์ ๋ ฌ ๋ชจ๋
const sortMode = localStorage.getItem(LS_SORT()) || 'default';
let sorted;
if (sortMode === 'recent') {
sorted = [...favs].sort((a, b) => (b.clickedAt || 0) - (a.clickedAt || 0));
} else if (sortMode === 'added') {
sorted = [...favs].sort((a, b) => (b.addedAt || 0) - (a.addedAt || 0));
} else if (sortMode === 'title') {
sorted = [...favs].sort((a, b) => (a.title || '').localeCompare(b.title || '', 'ko'));
} else {
sorted = [...favs].sort((a, b) => {
const r = rank(a) - rank(b);
if (r !== 0) return r;
if (rank(a) <= 1) return (b.clickedAt || 0) - (a.clickedAt || 0);
return (a.title || '').localeCompare(b.title || '', 'ko');
});
}
// ํ์ฑ(ํ์ฌ ์์ฒญ ์ค) ์๋ฆฌ์ฆ๋ ๋ชจ๋ ์ ๋ ฌ ๋ชจ๋์์ ๋ฌด์กฐ๊ฑด ๋งจ ์
if (activeId != null) {
const activeIdx = sorted.findIndex(f => f.id == activeId);
if (activeIdx > 0) {
const [active] = sorted.splice(activeIdx, 1);
sorted.unshift(active);
}
}
for (const [host, filter] of [[$('#favListMob'), filterMob], [$('#favListDt'), filterDt]]) {
if (!host) continue;
host.innerHTML = '';
// H-9: ์ด์ฑ ๊ฒ์ ์ง์ โ ์ฟผ๋ฆฌ๊ฐ ใฑ-ใ
๋ง์ด๋ฉด ์ด์ฑ ๋งค์นญ, ์๋๋ฉด ์ผ๋ฐ substring
const list = sorted.filter(f => {
if (!filter) return true;
const title = (f.title || '').toLowerCase();
if (title.includes(filter)) return true;
if (isChosungQuery(filter)) return toChosung(f.title).includes(filter.replace(/\s/g, ''));
return false;
});
for (const f of list) {
const isNew = isNewOf(f);
const isResumable = isResumableOf(f);
// ์ด์ด๋ณด๊ธฐ + NEW ๋์ ํ์ ๊ฐ๋ฅ (5/14 ๋ค ๋ณด๊ณ 5/21 ์กฐ๊ธ ๋ณธ ๊ฒฝ์ฐ ๋ฑ)
const newCount = (isNew && f.knownCount != null && f.lastSeenCount != null)
? Math.max(0, f.knownCount - f.lastSeenCount) : 0;
// ์ง๋ ์๊ฐ (mm:ss)
let resumeTimeText = '';
if (isResumable) {
const t = f.progress[f.lastLabel].time;
const mm = String(Math.floor(t / 60)).padStart(2, '0');
const ss = String(Math.floor(t % 60)).padStart(2, '0');
resumeTimeText = `${mm}:${ss}`;
}
const src = f.source || 'tvchak';
// E2: source/์นดํ
๊ณ ๋ฆฌ ๋ฐฐ์ง โ anilife๋ ํญ์ "์ ๋", tvchak์ fav.category(๋๋ผ๋ง/์๋ฅ ๋ฑ)๊ฐ ์์ผ๋ฉด ๊ทธ๊ฑธ ์ฌ์ฉ
let badge = '';
if (src === 'anilife') {
badge = '<span class="src-badge ani">์ ๋</span> ';
} else if (f.category) {
const cls = /์๋ฅ/.test(f.category) ? 'tv ent'
: /์ํ/.test(f.category) ? 'tv mov'
: /์ ๋/.test(f.category) ? 'ani'
: 'tv';
badge = `<span class="src-badge ${cls}">${esc(f.category)}</span> `;
} else {
badge = '<span class="src-badge tv">๋๋ผ๋ง</span> '; // tvchak ๊ธฐ๋ณธ๊ฐ
}
const div = document.createElement('div');
div.className = 'fav-item' + (String(f.id) === String(activeId) && (currentFavSource ? currentFavSource === src : true) ? ' active' : '');
if (isNew) div.dataset.new = '1'; // E-4: ์คํฌ๋กค ํ๊น
if (f.title) div.title = f.title; // H-16: ์ข์ ํจ๋์์ tooltip
// E-2: ํฌ์คํฐ ๋
ธ๋ โ ์ ํจ URL ์๋๊ฑฐ๋ placeholder ํจํด์ด๋ฉด ๊ธ์ placeholder
const isValidPoster = f.poster
&& /^https?:\/\//.test(f.poster)
&& !/\/template\//.test(f.poster);
const initial = esc((f.title || '?').slice(0, 1));
// onerror: posterAlt ์์ผ๋ฉด ํ ๋ฒ ์๋, ๊ทธ๋๋ ์คํจํ๋ฉด ๊ธ์ placeholder
const altUrl = f.posterAlt && /^https?:\/\//.test(f.posterAlt) ? esc(viaProxy(f.posterAlt)) : '';
const onerr = altUrl
? `if(this.dataset.tried){this.outerHTML='<div class="fav-poster placeholder">${initial}</div>'}else{this.dataset.tried=1;this.src='${altUrl}'}`
: `this.outerHTML='<div class="fav-poster placeholder">${initial}</div>'`;
const posterHTML = isValidPoster
? `<img class="fav-poster" loading="lazy" src="${esc(viaProxy(f.poster))}" alt="" referrerpolicy="no-referrer" onerror="${onerr}">`
: `<div class="fav-poster placeholder">${initial}</div>`;
// E-3: ์๋์๊ฐ โ clickedAt ์๊ณ ์ผ์ฃผ์ผ ์ด๋ด์ผ ๋๋ง ํ์ (์ค๋๋ ๊ฑด ํ์ ์ ํจ)
const ago = (f.clickedAt && (Date.now() - f.clickedAt) < 7 * 86400000) ? timeAgo(f.clickedAt) : '';
div.innerHTML = `
${posterHTML}
<div class="ftxt">
<b>${badge}${esc(f.title || '(์ ๋ชฉ ๋ก๋ฉโฆ)')}</b>
<div class="meta">
${f.knownCount != null ? f.knownCount + 'ํ' : 'ID ' + f.id}
${isResumable ? ` ยท โถ ${esc(f.lastLabel)} ${resumeTimeText}๋ถํฐ` :
(f.lastSeenLabel ? ` ยท ๋ง์ง๋ง ${esc(f.lastSeenLabel)}` : '')}
${isNew ? ` ยท ์ต์ ${esc(f.latestLabel)}` : ''}
${ago ? `<span class="ago">ยท ${esc(ago)}</span>` : ''}
</div>
</div>
${(isResumable || isNew) ? `<div class="badge-col">
${isResumable ? `<span class="resume-badge">์ด์ด๋ณด๊ธฐ</span>` : ''}
${isNew ? `<span class="new-badge">NEW${newCount > 1 ? ' ' + newCount : ''}</span>` : ''}
</div>` : ''}
<div class="actcol">
<button class="delbtn" data-del="${f.id}" title="์ญ์ " aria-label="์ญ์ ">โ</button>
${isResumable || isNew ? `<button class="markdone" data-done="${f.id}" title="๋ค ๋ณธ ๊ฑธ๋ก ์ฒ๋ฆฌ" aria-label="๋ค ๋ณธ ๊ฑธ๋ก ์ฒ๋ฆฌ">โ</button>` : '<span></span>'}
</div>
`;
div.addEventListener('click', e => {
if (e.target.dataset.del !== undefined || e.target.dataset.done !== undefined) return;
selectFav(f.id, { source: src });
});
// ์ฐํด๋ฆญ/๊ธธ๊ฒ๋๋ฅด๊ธฐ โ ํฌ์คํฐ URL ์๋ ๋ณ๊ฒฝ.
// namu ์๋ ์ถ์ถ์ด ์ ๋๋ ์ํ์ ์ฌ์ฉ์๊ฐ ์ง์ ๋ณด์ ํ ์ ์๊ฒ.
div.addEventListener('contextmenu', (e) => {
e.preventDefault();
const cur = f.poster || '';
const input = prompt(`'${f.title || f.id}' ํฌ์คํฐ URL\n(๋น์ฐ๋ฉด ์ ๊ฑฐ โ ๊ธฐ๋ณธ ํ์ ๋ฐ์ค)`, cur);
if (input == null) return; // ์ทจ์
const trimmed = input.trim();
if (trimmed && !/^https?:\/\//.test(trimmed)) {
alert('http:// ๋๋ https://๋ก ์์ํ๋ URL์ด์ด์ผ ํฉ๋๋ค.');
return;
}
f.poster = trimmed || null;
saveFavs();
renderFavs();
});
// โ ๋ค ๋ณธ ๊ฑธ๋ก ์ฒ๋ฆฌ: ๋ชจ๋ ํ์ฐจ finished ๋งํน + ์ต์ ๊น์ง ๋ณธ ๊ฑธ๋ก ๊ฐฑ์
div.querySelector('.markdone')?.addEventListener('click', e => {
e.stopPropagation();
f.progress = f.progress || {};
// ์๋ ค์ง ๋ชจ๋ ํ์ฐจ์ finished:true ๋งํน (currentEpList๊ฐ ์ด ์๋ฆฌ์ฆ์ ๋ค๋ฅผ ์ ์์ด latestLabel ๊ธฐ์ค์ผ๋ก๋ง ์์ ํ๊ฒ ์ฒ๋ฆฌ)
// ์ผ๋ฐ ์ผ์ด์ค: ํ์ฐจ ๋ผ๋ฒจ์ด "Nํ" ํํ๋ผ 1~knownCount๊น์ง finished ๋งํน
if (f.knownCount && f.latestLabel) {
// ๋ผ๋ฒจ ํจํด: "Nํ"๊ฐ ๊ฐ์ฅ ํํจ. "์ Nํ"ยท"์ Nํ"๋ ์์ ์ ์์ด latestLabel ์์ฒด๋ finished๋ก ๋ฐ์.
for (let i = 1; i <= f.knownCount; i++) {
const lab = `${i}ํ`;
f.progress[lab] = f.progress[lab] || { time: 0 };
f.progress[lab].finished = true;
f.progress[lab].time = 0; // ์ด์ด๋ณด๊ธฐ ์ ๋จ๋๋ก time ์ด๊ธฐํ
}
// latestLabel(์๋ฅ์ "์ Nํ"์ผ ์ ์์) ๋ ์ง์ ๋งํน
f.progress[f.latestLabel] = f.progress[f.latestLabel] || { time: 0 };
f.progress[f.latestLabel].finished = true;
f.progress[f.latestLabel].time = 0;
}
f.lastFinishedLabel = f.latestLabel || f.lastLabel || null;
f.lastSeenLabel = f.latestLabel || null;
if (f.knownCount != null) f.lastSeenCount = f.knownCount;
markCaughtUpIfNeeded(f);
// lastLabel/lastSid/lastNid๋ ๊ทธ๋๋ก ๋๋, ์ด์ด๋ณด๊ธฐ ํ์ ์์ ๋น ์ง๋๋ก progress.time์ 0์ผ๋ก ๋ง๋ ์ํ๊ฐ ํต์ฌ.
saveFavs();
renderFavs();
if (typeof renderEpisodes === 'function' && currentFavId === f.id) renderEpisodes();
showMediaToast?.(`'${f.title || ''}' ๋ค ๋ณธ ๊ฑธ๋ก ์ฒ๋ฆฌ๋จ`);
});
div.querySelector('.delbtn').addEventListener('click', e => {
e.stopPropagation();
if (confirm(`'${f.title || f.id}' ์ญ์ ํ ๊น์?`)) {
favs = favs.filter(x => !(x.id === f.id && (x.source || 'tvchak') === src));
saveFavs();
if (currentFavId === f.id && currentFavSource === src) { currentFavId = null; currentFavSource = null; stopPlayer(); }
renderFavs();
}
});
host.appendChild(div);
}
}
const n = favs.length;
$('#favCount').textContent = n;
if ($('#favCountDt')) $('#favCountDt').textContent = n;
}
// ์๋จ ๋นจ๊ฐ ๋ก๋ฉ ๋ฐ โ ๋ณด๊ดํจ ํด๋ฆญ ํ episodes/play ๋ก๋ ํ
์ ํ์
let _topLoaderCount = 0;
function showTopLoader() {
_topLoaderCount++;
document.getElementById('topLoader')?.classList.add('show');
}
function hideTopLoader() {
_topLoaderCount = Math.max(0, _topLoaderCount - 1);
if (_topLoaderCount === 0) document.getElementById('topLoader')?.classList.remove('show');
}
// โโโ ์ฆ๊ฒจ์ฐพ๊ธฐ ์ ํ โโโ
async function selectFav(id, opts = {}) {
// source ์ง์ ๋๋ฉด ๊ทธ ์์ค์ favorite, ์๋๋ฉด ๊ฐ์ id ์ค ์๋ฌด๊ฑฐ๋(๋ ๊ฑฐ์ ํธํ)
const f = opts.source
? favs.find(x => x.id === id && (x.source || 'tvchak') === opts.source)
: favs.find(x => x.id === id);
if (!f) return;
if (!f.source) f.source = 'tvchak'; // ๋ง์ด๊ทธ๋ ์ด์
currentFavSource = f.source;
currentFavId = id;
lastFavId = String(id);
localStorage.setItem(LS_LAST(), lastFavId);
// ์นด๋ ํด๋ฆญ(=ํ์ฌ ๋ณด๊ณ ์๋ ์๋ฆฌ์ฆ)์ ๋ชจ๋ ๋๋ฐ์ด์ค์ ์ฆ์ ์๋ฆผ.
// - clickedAt ๊ฐฑ์ : ์ ๋ ฌ์์ "์ต๊ทผ ๋ณธ ๊ฒ" ์๋ก ์ฌ๋ผ์ด
// - saveFavs: ๋๋ฐ์ด์ค ํ์ ๋ค์ด๊ฐ 1์ด ๋ค ์๋ฒ PUT (lastFavId ํฌํจ) โ ๋ค๋ฅธ ๋๋ฐ์ด์ค๊ฐ ๋ค์ pull/๋ถํ
๋ ๋๊ธฐํ
// silent ๋ชจ๋(๋ถํ
์ ์๋ ์ ํ)์์ ๊ฐฑ์ ํ์ง ์์ โ ์ค์ ์ฌ์ฉ์ ์ก์
๋ง ๊ธฐ๋ก
if (!opts.silent) {
f.clickedAt = Date.now();
saveFavs();
}
renderFavs();
showTopLoader();
try {
await loadEpisodes(f);
let { sid, nid } = opts;
if (sid == null || nid == null) {
// ์ฐ์ ์์: โ ๋ง์ง๋ง ๋ณธ ํ์ฐจ์ ์ด์ด๋ณด๊ธฐ ์งํ๋ฅ ์์ผ๋ฉด ๊ทธ๊ฒ๋ถํฐ (์ฌ์ฉ์๊ฐ ๊ฑฐ๊ธฐ๋ก ๋์๊ฐ ์ํ) > โก ๊ทธ ์ธ ์ด์ด๋ณด๊ธฐ ํ๋ณด ์ค ์ต์ > โข lastLabel > โฃ ์ต์ ํ
if (f.progress) {
// โ lastLabel์ด ์ด์ด๋ณด๊ธฐ ๊ฐ๋ฅ ์ํ๋ฉด ๋ฌด์กฐ๊ฑด ๊ทธ๊ฒ๋ถํฐ
// (์ฌ์ฉ์๊ฐ ์ ํ์ฐจ๋ก ๋์๊ฐ ๋ณด๊ณ ์๋ ๊ฒฝ์ฐ, ์๋ก๊ณ ์นจํด๋ ๊ฑฐ๊ธฐ์ ์ฌ๊ฐ)
if (f.lastLabel) {
const lastEp = currentEpList.find(e => e.label === f.lastLabel);
const lastProg = f.progress[f.lastLabel];
if (lastEp && lastProg?.time > 5 && !lastProg.finished) {
sid = lastEp.sid; nid = lastEp.nid;
}
}
// โก lastLabel์ด finished๊ฑฐ๋ ์งํ๋ฅ ์์ผ๋ฉด โ ๋ค๋ฅธ ์ด์ด๋ณด๊ธฐ ํ๋ณด ์ค nid ์์ ๊ฒ(=์ต์ )
if (sid == null) {
const resumeCandidates = currentEpList
.filter(e => f.progress[e.label]?.time > 5 && !f.progress[e.label]?.finished)
.sort((a, b) => a.sid - b.sid || a.nid - b.nid);
if (resumeCandidates.length) {
sid = resumeCandidates[0].sid; nid = resumeCandidates[0].nid;
}
}
}
if (sid == null && f.lastSid != null && f.lastNid != null) {
sid = f.lastSid; nid = f.lastNid;
// ์ฌ์ฉ์๊ฐ ๋ช
์์ ์ผ๋ก ํด๋ฆญํ ๊ฒฝ์ฐ์๋ง "๋๊น์ง ๋ณธ ํ์ฐจ โ ๋ค์ ํ" ์๋ ์งํ
const lastLabel = f.lastLabel || (currentEpList.find(e => e.sid === sid && e.nid === nid)?.label);
if (!opts.silent && lastLabel && f.progress && f.progress[lastLabel]?.finished) {
const sortedAsc = [...currentEpList].sort((a, b) => a.sid - b.sid || a.nid - b.nid);
const idx = sortedAsc.findIndex(e => e.label === lastLabel);
if (idx > 0) {
const nextNewer = sortedAsc[idx - 1];
sid = nextNewer.sid; nid = nextNewer.nid;
}
}
}
if (sid == null && currentEpList.length) {
// ์์ฒญ๊ธฐ๋ก ์์ผ๋ฉด ์๋ฆฌ์ฆ 1ํ๋ถํฐ (์คํ ๋ฆฌ์ ์ฒซ ํ). ์ฌ์ดํธ์ nid๊ฐ ๊ฐ์ฅ ํฐ ๊ฒ์ด 1ํ.
const ep1 = [...currentEpList].sort((a, b) => b.sid - a.sid || b.nid - a.nid)[0];
sid = ep1.sid; nid = ep1.nid;
console.log('[selectFav] ์์ฒญ๊ธฐ๋ก ์์ โ 1ํ ์๋์ ํ', ep1);
}
if (sid == null) return;
console.log('[selectFav] ์ต์ข
์ ํ:', { sid, nid, fromFav: { lastSid: f.lastSid, lastNid: f.lastNid }, opts });
}
await playEpisode(id, sid, nid, { userInitiated: !opts.silent });
} finally {
hideTopLoader();
}
}
// โโโ ํ์ฐจ ๋ชฉ๋ก โโโ
async function loadEpisodes(fav) {
$('#epSection').style.display = 'none';
try {
const src = fav.source || 'tvchak';
const titleQ = fav.title ? `&title=${encodeURIComponent(fav.title)}` : '';
// ํด๋ฐฑ ๋งคํ ํํธ: ํด๋ผ์ด์ธํธ๊ฐ ์๊ณ ์๋ linkkf id + anilife ํ์ฐจ ์ โ ์๋ฒ๊ฐ ๊ฒ์ ๋จ๊ณ ์คํต ๊ฐ๋ฅ
const fbQ = (src === 'anilife' && fav.fallbackLinkkfId) ? `&fallbackId=${fav.fallbackLinkkfId}` : '';
const countQ = (src === 'anilife' && fav.knownCount) ? `&count=${fav.knownCount}` : '';
const ep = await api(`/api/episodes?id=${fav.id}&source=${src}${titleQ}${fbQ}${countQ}`);
if (ep.error) {
console.warn('episodes', ep.error);
return;
}
if (ep.title && !fav.title) fav.title = ep.title;
if (ep.category && !fav.category) fav.category = ep.category; // E2: tvchak ์นดํ
๊ณ ๋ฆฌ (๋๋ผ๋ง/์๋ฅ/์ํ ๋ฑ)
// linkkf ํด๋ฐฑ ์ฌ์ฉ ์ฌ์ค ์ ์ฅ โ ๋ค์ ํธ์ถ์ fallbackId ์ง์ ์ ๋ฌ
if (ep._fallbackLinkkfId) fav.fallbackLinkkfId = ep._fallbackLinkkfId;
fav.usingFallback = ep._fallbackSource || null; // UI ๋ฐฐ์ง์ฉ
// E-2: ์ placeholder URL ์ ๋ฆฌ + ep ์๋ต์ poster ํ์ฉ + posterAlt (anilife์ฉ fallback)
if (fav.poster && /\/template\//.test(fav.poster)) fav.poster = null;
if (ep.poster) fav.poster = ep.poster; // ํญ์ ์ต์ ๊ฐ์ผ๋ก ๊ฐฑ์ (์๋ฒ๊ฐ namu fallback ๊ฑฐ์น ๊ฒฐ๊ณผ)
if (ep.posterAlt) fav.posterAlt = ep.posterAlt;
fav.knownCount = ep.count;
// ์ฌ์ดํธ์ ์ต์ ํ์ฐจ ๋ผ๋ฒจ (nid=1)
const latest = (ep.episodes || []).find(e => e.sid === 1 && e.nid === 1) || (ep.episodes || [])[0];
// ๋ผ๋ฒจ ๋ง์ด๊ทธ๋ ์ด์
: ๊ธฐ์กด progress/lastLabel ์ด dateLabel(์: "26/05/19") ์ด์์ผ๋ฉด ์ label("1ํ") ๋ก ๊ต์ฒด.
// ์๋ฒ๊ฐ ์ ๊ทํ๋ label + ์๋ณธ dateLabel์ ๊ฐ์ด ์ค. ๋ ๋ค ํ์ธํด์ ๋งคํ.
if (Array.isArray(ep.episodes)) {
const oldToNew = {};
for (const e of ep.episodes) {
if (e.dateLabel && e.dateLabel !== e.label) oldToNew[e.dateLabel] = e.label;
}
// progress ํค ๊ต์ฒด
if (fav.progress && Object.keys(oldToNew).length) {
const newProg = {};
for (const k of Object.keys(fav.progress)) {
const newK = oldToNew[k] || k;
newProg[newK] = fav.progress[k];
}
fav.progress = newProg;
}
// lastLabel / lastSeenLabel / lastFinishedLabel ๋งคํ
for (const key of ['lastLabel', 'lastSeenLabel', 'lastFinishedLabel']) {
if (fav[key] && oldToNew[fav[key]]) fav[key] = oldToNew[fav[key]];
}
}
fav.latestLabel = latest?.label || null;
// ์ฒ์ ๋ฑ๋กํ ๊ฒฝ์ฐ์ "์ด๋ฏธ ๋ณธ ์์ "์ ํ์ฌ ์ต์ ํ๋ก ๊ฐ์ฃผ (๊ทธ๋ฌ๋ฉด NEW๊ฐ ๋ ๋ฒ๋ฆฌ๋ ๊ฑธ ๋ง์)
if (fav.lastSeenLabel == null) {
fav.lastSeenLabel = fav.latestLabel;
fav.lastSeenCount = ep.count;
}
markCaughtUpIfNeeded(fav);
saveFavs();
currentEpList = ep.episodes || [];
renderEpisodes();
$('#epSection').style.display = currentEpList.length ? '' : 'none';
} catch (e) {
console.warn('loadEpisodes', e);
}
}
function renderEpisodes() {
const strip = $('#epStrip');
const gridList = $('#epGridList');
strip.innerHTML = '';
if (gridList) gridList.innerHTML = '';
if (!currentEpList.length) return;
const fav = favs.find(f => f.id === currentFavId);
// ์ฌ์ดํธ๊ฐ ๋ณด๋ด๋ ์์ ๊ทธ๋๋ก (nid=1์ด ์ด๋ฏธ ์ต์ ). ๊ทธ๋๋ ์์ ํ๊ฒ nid ์ค๋ฆ์ฐจ์ ๋ณด์ฅ.
const ordered = [...currentEpList].sort((a, b) => a.sid - b.sid || a.nid - b.nid);
// ํ์ฐจ ๊ทธ๋ฃนํ ๋นํ์ฑ โ ๋ชจ๋ ์นฉ์ ๋จ์ grid์ ํํํ๊ฒ ํ์
const epGridEl = document.getElementById('epGrid');
if (epGridEl) epGridEl.classList.remove('grouped');
for (const ep of ordered) {
const isCur = currentEpIdx >= 0
&& currentEpList[currentEpIdx]
&& currentEpList[currentEpIdx].sid === ep.sid
&& currentEpList[currentEpIdx].nid === ep.nid;
const label = ep.label || `${ep.nid}ํ`;
// A2: ์ง๋ ๊ณ์ฐ + E-14: ๋ฏธ์์ฒญ ์
const prog = fav?.progress?.[label];
const finished = !!prog?.finished;
const hasProgress = !!(prog && (prog.time > 5 || finished));
const dur = (prog?.time && prog?.duration && prog.duration > 0) ? (prog.time / prog.duration) : 0;
const widthPct = finished ? 100 : Math.min(95, Math.max(0, Math.round(dur * 100)));
const make = (fromGrid) => {
const b = document.createElement('button');
b.className = 'ep-chip' + (isCur ? ' active' : '') + (finished ? ' finished' : '') + (!hasProgress ? ' unwatched' : '');
b.dataset.label = label;
b.innerHTML = esc(label)
+ (finished ? '<span class="ep-check">โ</span>' : '')
+ (widthPct > 0 ? `<span class="ep-progress" style="width:${widthPct}%"></span>` : '');
b.addEventListener('click', () => {
playEpisode(currentFavId, ep.sid, ep.nid);
if (fromGrid) {
const v = $('#videoWrap') || $('#player');
v?.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});
return b;
};
strip.appendChild(make(false));
if (gridList) gridList.appendChild(make(true));
}
requestAnimationFrame(() => {
const active = strip.querySelector('.ep-chip.active');
if (active) active.scrollIntoView({ behavior: 'auto', inline: 'center', block: 'nearest' });
});
updateEpNavButtons(); // F-13
}
// B13: ํ์ฐจ ๊ฒ์ ํํฐ
(function setupEpSearch() {
const inp = document.getElementById('epSearch');
if (!inp) return;
inp.addEventListener('input', () => {
const q = inp.value.trim().toLowerCase();
const items = document.querySelectorAll('#epGridList .ep-chip');
items.forEach(el => {
const lab = (el.dataset.label || el.textContent || '').toLowerCase();
el.classList.toggle('ep-hidden', !!q && !lab.includes(q));
});
});
})();
$('#epGridToggle')?.addEventListener('click', () => {
const grid = $('#epGrid');
const isHidden = grid.classList.toggle('hidden');
$('#epGridToggle').textContent = isHidden ? '์ ์ฒด ๋ณด๊ธฐ' : '์ ๊ธฐ';
});
// ์ ์ญ hls ์ธ์คํด์ค (anilife ์ฌ์ ์ ์ฌ์ฉ)
let _currentHls = null;
// ํ์ฌ ์์์ chapter (anilife) - { op:{start,end}, ed:{start,end} } ๋๋ null
let _currentSkips = null;
// ์คํต ๋งํน ์๊ฐ ํ์๋ ์ฐํด๋ฆญ ๋ฉ๋ด ์์์๋ง (progressbar ๋ง์ปค๋ ์ ๊ฑฐ๋จ).
// ๋ฉ๋ด ์ด ๋๋ง๋ค fav.skip ์ฝ์ด ๊ฐ ๋ฒํผ์ .t์ ์๊ฐ ํ
์คํธ ์ฑ์.
const DEFAULT_ED_FROM_END_MIN = 2.0;
// fav.skip ๊ฐ์ฒด์ ํ์ฌ ์์์ duration์ ๋ณด๊ณ _currentSkips๋ฅผ ์ฌ๊ณ์ฐ.
// ์ฐ์ ์์: โ edFromEnd(์๋, ๊ถ์ฅ) โก edStart/edEnd(๊ตฌ๋ฒ์ ๋ช
์ ๋งํน). duration ๋ฏธ์ ์ด๋ฉด timeupdate์์ ๋ฆ๊ฒ ์ฑ์.
function rebuildCurrentSkips(fav) {
if (!fav?.skip) { _currentSkips = null; return; }
const s = fav.skip;
const skips = {};
if (typeof s.opStart === 'number' && typeof s.opEnd === 'number' && s.opEnd > s.opStart) {
skips.op = { start: s.opStart, end: s.opEnd };
}
// ์๋ฉ: edFromEnd๊ฐ ์์ผ๋ฉด ์๋ ๋ชจ๋ (duration ์ ๋๋ง ํ์ฑ)
const v = document.getElementById('player');
const dur = v && isFinite(v.duration) ? v.duration : 0;
if (typeof s.edFromEnd === 'number' && s.edFromEnd > 0) {
if (dur > 0) {
const edStart = Math.max(0, dur - s.edFromEnd * 60);
skips.ed = { start: edStart, end: dur };
}
// dur ์์ง ๋ชจ๋ฅด๋ฉด ed ๋ฏธ์ค์ โ duration ๋์ฐฉ ํ timeupdate ์ธก์์ ๋ค์ ๋น๋๋จ
} else if (typeof s.edStart === 'number') {
skips.ed = { start: s.edStart, end: (typeof s.edEnd === 'number' && s.edEnd > s.edStart) ? s.edEnd : Infinity };
}
_currentSkips = (skips.op || skips.ed) ? skips : null;
}
function updateSkipMenuLabels() {
const menu = document.getElementById('skipCtxMenu');
const moreMenu = document.getElementById('moreMenu');
if (!menu && !moreMenu) return;
const fav = currentFavId ? favs.find(f => f.id === currentFavId && (f.source || 'tvchak') === (currentFavSource || 'tvchak')) : null;
const s = fav?.skip || {};
const fmt = (n) => (typeof n === 'number') ? `${Math.floor(n/60)}:${String(Math.floor(n%60)).padStart(2,'0')}` : '';
// edFromEnd ๋ผ๋ฒจ: ํ์ฌ ์์์ ๋จ์ ์๊ฐ(๋ถ)์ ๋ณด์ฌ์ค ์ฌ์ฉ์๊ฐ "์ง๊ธ ํด๋ฆญํ๋ฉด ์ด ๊ฐ์ผ๋ก ์ ์ฅ๋๋ค"๋ ๊ฑธ ์ง๊ด์ ์ผ๋ก ์๊ฒ ํจ.
// ์์ ๋ฏธ๋ก๋ฉ์ด๊ฑฐ๋ currentTime์ด ๋ ๊ทผ์ฒ ์๋๋ฉด ๊ธฐ์กด ์ ์ฅ๊ฐ ํ์.
const v = document.getElementById('player');
const dur = v && isFinite(v.duration) ? v.duration : 0;
const remainMin = dur > 0 ? Math.max(0, (dur - v.currentTime) / 60) : 0;
const targets = [];
if (menu) targets.push(...menu.querySelectorAll('.t'));
if (moreMenu) targets.push(...moreMenu.querySelectorAll('.t'));
for (const el of targets) {
const key = el.dataset.key;
if (key === 'edFromEnd') {
if (remainMin > 0 && remainMin < 30) {
// ํ์ฌ ์์น ๊ธฐ์ค โ ํด๋ฆญ ์ ์ด ๊ฐ์ด ์ ์ฅ๋จ
el.textContent = `โ ${remainMin.toFixed(1)}๋ถ`;
} else if (typeof s.edFromEnd === 'number') {
el.textContent = `${s.edFromEnd}๋ถ`;
} else {
el.textContent = '์๋ฉ์์ ํด๋ฆญ';
}
} else {
el.textContent = fmt(s[key]);
}
}
}
// ์คํต ๋งํน ๊ณตํต ์ ์ฉ ํจ์ โ ํค๋ณด๋ยท์ฐํด๋ฆญ ๋ฉ๋ด ๊ณตํต ์ง์
์ .
// kind: 'opStart' | 'opEnd' | 'edStart' | 'edEnd' | 'clear'
function applySkipMark(kind) {
const v = document.getElementById('player');
if (!v || !currentFavId) return;
const fav = favs.find(f => f.id === currentFavId && (f.source || 'tvchak') === (currentFavSource || 'tvchak'));
if (!fav) return;
const t = Math.floor(v.currentTime);
const fmt = (s) => `${Math.floor(s/60)}:${String(s%60).padStart(2,'0')}`;
let msg = '';
if (kind === 'clear') { delete fav.skip; msg = '์คํต ๋งํน ์ด๊ธฐํ'; }
else if (kind === 'clearOp') {
if (fav.skip) { delete fav.skip.opStart; delete fav.skip.opEnd; if (Object.keys(fav.skip).length === 0) delete fav.skip; }
msg = '์คํ๋ ๋งํน ์ด๊ธฐํ';
}
else if (kind === 'clearEd') {
if (fav.skip) { delete fav.skip.edStart; delete fav.skip.edEnd; delete fav.skip.edFromEnd; if (Object.keys(fav.skip).length === 0) delete fav.skip; }
msg = '์๋ฉ ๋งํน ์ด๊ธฐํ';
}
else {
fav.skip = fav.skip || {};
if (kind === 'opStart') { fav.skip.opStart = t; msg = `์คํ๋ ์์: ${fmt(t)}`; }
else if (kind === 'opEnd') {
// ์คํ๋ ๋ ๋งํน: ์์์ด ๋ฏธ์ค์ ์ด๋ฉด ์๋์ผ๋ก 0์ด (์ฌ์ฉ์๊ฐ ํ ๋ฒ ํด๋ฆญ์ผ๋ก ์๋ฃ)
fav.skip.opEnd = t;
if (typeof fav.skip.opStart !== 'number') fav.skip.opStart = 0;
msg = `์คํ๋ ์คํต: ${fmt(fav.skip.opStart)} ~ ${fmt(t)}`;
}
else if (kind === 'edFromEnd') {
// ์๋ฉ: ํด๋ฆญ ์์ ์ ๋จ์ ์๊ฐ์ ์๋์ผ๋ก edFromEnd๋ก ์ ์ฅ. ์ฌ์ฉ์๊ฐ ์๋ฉ ์์์ ์ ์์นํ ํ ํด๋ฆญํ๋ ๊ฒ ์์ฐ์ค๋ฌ์.
// duration ๋ชจ๋ฅด๊ฑฐ๋ ๋จ์ ์๊ฐ์ด ๋๋ฌด ๊ธธ๊ฑฐ๋(์๋ฉ ์๋) ๋๋ฌด ์งง์ผ๋ฉด ๊ฑฐ๋ถ.
if (!isFinite(v.duration) || v.duration <= 0) {
if (typeof showToast === 'function') showToast('์์ ๊ธธ์ด๋ฅผ ์ ์ ์์ โ ์ ์ ํ ๋ค์');
return;
}
const remain = v.duration - v.currentTime;
const remainMin = remain / 60;
if (remainMin <= 0 || remainMin >= 30) {
if (typeof showToast === 'function') showToast('์๋ฉ ์์ ์ง์ (๋ 30๋ถ ์ด๋ด)์ผ๋ก ์ด๋ ํ ๋ค์');
return;
}
const m = Math.round(remainMin * 10) / 10; // ์์ 1์๋ฆฌ
fav.skip.edFromEnd = m;
delete fav.skip.edStart;
delete fav.skip.edEnd;
msg = `์๋ฉ ์คํต: ๋๋๊ธฐ ${m}๋ถ ์ ๋ถํฐ`;
}
else return;
// ์ ๊ทํ: ์์ยท๋์ด ๋ค์งํ ๊ฒฝ์ฐ ์๋ swap (์ฌ์ฉ์๊ฐ ํค ์์ ํท๊ฐ๋ ธ์ ๋ ์๋ ๋ณด์ )
if (fav.skip.opStart != null && fav.skip.opEnd != null && fav.skip.opStart > fav.skip.opEnd) {
[fav.skip.opStart, fav.skip.opEnd] = [fav.skip.opEnd, fav.skip.opStart];
msg += ' (์๋ ์ ๋ ฌ)';
}
if (fav.skip.edStart != null && fav.skip.edEnd != null && fav.skip.edStart > fav.skip.edEnd) {
[fav.skip.edStart, fav.skip.edEnd] = [fav.skip.edEnd, fav.skip.edStart];
msg += ' (์๋ ์ ๋ ฌ)';
}
}
saveFavs();
// ํ์ฌ ์์์๋ ์ฆ์ ๋ฐ์
rebuildCurrentSkips(fav);
updateSkipMenuLabels();
if (typeof showToast === 'function') showToast(msg);
}
// (์ด์ : ์ฐํด๋ฆญ/๊ธธ๊ฒ๋๋ฅด๊ธฐ โ ์คํต ๋งํน ์ปจํ
์คํธ ๋ฉ๋ด. ์ ๊ฑฐ๋จ.
// ์คํต ๋งํน์ ์ปจํธ๋กค๋ฐ โฎ '๋๋ณด๊ธฐ' ๋ฉ๋ด์์๋ง ์ ๊ทผ.)
// โโโ ์ฌ์ โโโ
async function playEpisode(id, sid, nid, opts = {}) {
const userInitiated = opts.userInitiated !== false; // ๊ธฐ๋ณธ true
$('#videoLoading').style.display = 'block';
$('#videoEmpty').classList.add('hide');
// ์ด์ ํ์ฐจ์์ ๋์๋ ์นด์ดํธ๋ค์ด์ด ์์ผ๋ฉด ์ฆ์ ์ ๋ฆฌ (์๋ ๋ค์ํ ์ง์
์ ์์กด ๋ฐฉ์ง)
try { cancelNextCountdown(); } catch {}
// ์๋ ์คํต ํ๋๊ทธ ํ์ฐจ๋ง๋ค ๋ฆฌ์
(op ์๋์ ํ / ed ์๋ ์นด์ดํธ๋ค์ด ๊ฐ 1ํ์ฉ)
playEpisode._opAutoSkipped = false;
playEpisode._edAutoTriggered = false;
playEpisode._clickedAtBumpedForCurrent = false;
// src ๊ต์ฒด ์งํ, ์ ์์ ๋ฉํ๋ฐ์ดํฐ ๋์ฐฉ(loadeddata) ์ ๊น์ง๋
// ์ด์ ์์์ currentTime์ผ๋ก timeupdate๊ฐ ํ๋ ๋ฒ ๋ ๋ฐํํ ์ ์๋ค.
// ๊ทธ ๋์ ์๋ฉ ์๋ ํธ๋ฆฌ๊ฑฐ๊ฐ ๋ ๋ฒ ๋ฐ์ฌ๋๋ ์ฌ๊ณ ์ฐจ๋จ.
playEpisode._skipsLoading = true;
try {
const fav = favs.find(f => f.id === id);
const src = (fav?.source) || 'tvchak';
const v = $('#player');
// ์ด์ HLS ์ ๋ฆฌ
if (_currentHls) { try { _currentHls.destroy(); } catch {} _currentHls = null; }
// ์ฌ์ฉ์๊ฐ ๋งํนํ ์คํ๋/์๋ฉ ๊ตฌ๊ฐ ์ ์ฉ (๊ฐ์ ์๋ฆฌ์ฆ = ๊ฐ์ fav ์์์ ๋ชจ๋ ํ์ฐจ ๊ณตํต).
// ์๋ฉ์ fav.skip.edFromEnd(๋๋๊ธฐ N๋ถ ์ , ์๋)์ ์ฐ์ ์ฌ์ฉ. duration ๋ฏธ์ ์ด๋ฉด loadedmetadata ํ ์ฌ๋น๋๋จ.
// tvchakยทanilife ๋ ๋ค ๋์ผํ๊ฒ ๋์. ์ฌ์ฉ์ ๋งํน์ anilife ์๋ chapter๋ณด๋ค ์ฐ์ .
rebuildCurrentSkips(fav);
let proxyUrl, isHls = false, p;
if (src === 'anilife') {
// anilife: nid๊ฐ episode_num, uniqueId๋ currentEpList์์ ์กฐํ
let ep = currentEpList.find(e => e.nid === nid) || currentEpList.find(e => e.sid === sid && e.nid === nid);
// currentEpList๊ฐ ๋น์ด์๊ฑฐ๋ ๋งค์นญ ์คํจ๋ฉด fav.id์ episodes๋ฅผ ์ฆ์ ๋ค์ ๋ก๋ (race ๋ณต๊ตฌ)
if (!ep?.uniqueId && fav) {
console.warn('[play] currentEpList ๋งค์นญ ์คํจ, episodes ๋ค์ ๋ก๋');
try {
await loadEpisodes(fav);
ep = currentEpList.find(e => e.nid === nid) || currentEpList.find(e => e.sid === sid && e.nid === nid);
} catch {}
}
const uniqueId = ep?.uniqueId;
if (!uniqueId) throw new Error('uniqueId not found for nid=' + nid);
p = await api(`/api/play?source=anilife&uniqueId=${encodeURIComponent(uniqueId)}`);
if (p.error || !p.manifest) throw new Error(p.error || 'no manifest');
const b64 = btoa(p.manifest);
proxyUrl = '/cdn?b64=1&u=' + encodeURIComponent(b64) + '&r=' + encodeURIComponent(p.referer || 'https://anilife.app/');
isHls = true;
// chapter โ ์คํ๋/์๋ฉ ์ถ์ . ํด๋ฆฌ์คํฑ:
// - ์ฒซ chapter (5๋ถ ์ดํ)๋ฉด ์คํ๋
// - ๋ง์ง๋ง chapter (๋๋ ๋์์ ๋๋ฒ์งธ, 5๋ถ ์ดํ)๋ฉด ์๋ฉ
// - "ํธ๋ ์ผ๋ฌ/๋ค์ํ ์๊ณ "์ฉ ๋ฏธ์ธ chapter๋ ๋ฌด์
// ์ฌ์ฉ์ ๋งํน(_currentSkips ์ด๋ฏธ ์ค์ ๋จ)์ด ์์ผ๋ฉด ์๋ chapter๋ ๋ฌด์
if (!_currentSkips && Array.isArray(p.chapters) && p.chapters.length >= 2) {
const chs = p.chapters;
const skips = {};
// ์คํ๋: ์ฒซ chapter, ์์ 0 ๊ทผ์ฒ + ๊ธธ์ด 10~300์ด
if (chs[0] && chs[0].start <= 5 && (chs[0].end - chs[0].start) <= 300 && (chs[0].end - chs[0].start) >= 10) {
skips.op = { start: chs[0].start, end: chs[0].end };
}
// ์๋ฉ: ๋์์๋ถํฐ ์ญ์์ผ๋ก, ๊ธธ์ด 10~300์ด์ด๋ฉด์ ์์ ๋๊น์ง ๊ฐ๊น์ด ๊ฒ
for (let i = chs.length - 1; i >= 0; i--) {
const len = chs[i].end - chs[i].start;
if (len >= 10 && len <= 300) { skips.ed = { start: chs[i].start, end: chs[i].end }; break; }
}
if (skips.op || skips.ed) _currentSkips = skips;
}
} else {
p = await api(`/api/play?id=${id}&sid=${sid}&nid=${nid}`);
if (p.error || !p.url) { const err = new Error(p.error || 'no url'); err.code = p.code; throw err; }
proxyUrl = '/cdn?u=' + encodeURIComponent(p.url) + '&r=' + encodeURIComponent(p.referer || '');
}
// H-11/H-5: HLS selectors ์ด๊ธฐํ
const qSel = document.getElementById('hlsQuality');
const aSel = document.getElementById('hlsAudio');
const sSel = document.getElementById('hlsSub');
for (const s of [qSel, aSel, sSel]) if (s) { s.innerHTML = ''; s.classList.remove('has-levels'); }
if (isHls) {
const ua = navigator.userAgent;
const isSafari = /^((?!chrome|android).)*safari/i.test(ua);
// hls.js๋ defer ๋ก๋๋ผ m3u8 ์์์ ๋น ๋ฅด๊ฒ ํด๋ฆญํ ๊ฒฝ์ฐ ์์ง ๋์ฐฉ ์ ์ผ ์ ์์ โ ์ต๋ 2์ด ์งง๊ฒ ๋๊ธฐ
if (!window.Hls && !isSafari) {
const t0 = Date.now();
while (!window.Hls && Date.now() - t0 < 2000) {
await new Promise(r => setTimeout(r, 50));
}
}
if (window.Hls && Hls.isSupported() && !isSafari) {
const hls = new Hls({ xhrSetup: (xhr) => { xhr.withCredentials = false; } });
_currentHls = hls;
hls.loadSource(proxyUrl);
hls.attachMedia(v);
// ๋ณ์ข
ํธ๋ ๋์ฐฉ ์ ์
๋ ํธ ์ฑ์ฐ๊ธฐ
hls.on(Hls.Events.MANIFEST_PARSED, () => {
// ํ์ง
const levels = hls.levels || [];
if (qSel && levels.length > 1) {
qSel.innerHTML = '<option value="-1">์๋</option>' + levels
.map((lv, i) => `<option value="${i}">${lv.height ? lv.height + 'p' : Math.round((lv.bitrate || 0) / 1000) + 'kbps'}</option>`)
.join('');
qSel.value = '-1';
qSel.classList.add('has-levels');
qSel.onchange = () => {
const v = parseInt(qSel.value, 10);
hls.currentLevel = v;
showMediaToast(v < 0 ? 'ํ์ง: ์๋' : (levels[v].height ? levels[v].height + 'p' : 'ํ์ง ๋ณ๊ฒฝ'));
};
}
});
// H-5: audio tracks
hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, () => {
const tracks = hls.audioTracks || [];
if (aSel && tracks.length > 1) {
aSel.innerHTML = tracks.map((t, i) => `<option value="${i}">๐ต ${esc(t.name || t.lang || '#' + i)}</option>`).join('');
aSel.value = String(hls.audioTrack);
aSel.classList.add('has-levels');
aSel.onchange = () => {
hls.audioTrack = parseInt(aSel.value, 10);
const tr = tracks[hls.audioTrack];
showMediaToast('์ค๋์ค: ' + (tr?.name || tr?.lang || ''));
};
}
});
// H-5: subtitle tracks
hls.on(Hls.Events.SUBTITLE_TRACKS_UPDATED, () => {
const subs = hls.subtitleTracks || [];
if (sSel && subs.length >= 1) {
sSel.innerHTML = '<option value="-1">์๋ง ๊บผ์ง</option>' + subs.map((t, i) => `<option value="${i}">๐ฌ ${esc(t.name || t.lang || '#' + i)}</option>`).join('');
sSel.value = String(hls.subtitleTrack);
sSel.classList.add('has-levels');
sSel.onchange = () => {
hls.subtitleTrack = parseInt(sSel.value, 10);
showMediaToast(hls.subtitleTrack < 0 ? '์๋ง ๋' : '์๋ง ์ผฌ');
};
}
});
} else if (v.canPlayType('application/vnd.apple.mpegurl')) {
v.src = proxyUrl;
v.load();
} else {
throw new Error('์ด ๋ธ๋ผ์ฐ์ ๋ HLS๋ฅผ ์ง์ํ์ง ์์ต๋๋ค');
}
} else {
v.src = proxyUrl;
v.load();
}
// ์๋์ฌ์ ์ ํจ โ ์ฌ์ฉ์๊ฐ โถ ๋๋ฌ์ผ ์์
// ์ด์ด๋ณด๊ธฐ: ํ์ฐจ๋ณ progress.time์ ๋ณต์ (-3์ด ๋ฐฑ์คํ๋ก ๋งฅ๋ฝ ์ด์ง๋ง ๋ณด๊ฐ)
// ์ ์ฅ throttle์ 10์ด๋ก ์ค์๊ณ pause/hidden/unload flush๊ฐ ์์ด -10์ด๊น์ง ๊ฐ ํ์ ์์.
const epForRestore = currentEpList.find(e => e.sid === sid && e.nid === nid) || currentEpList.find(e => e.nid === nid);
const labelForRestore = epForRestore?.label || `${nid}ํ`;
const prog = fav?.progress?.[labelForRestore];
if (prog && typeof prog.time === 'number' && prog.time > 5 && !prog.finished) {
const restore = () => {
try { v.currentTime = Math.max(0, prog.time - 3); } catch {}
v.removeEventListener('loadedmetadata', restore);
};
v.addEventListener('loadedmetadata', restore);
}
// E2: ์นดํ
๊ณ ๋ฆฌ ๋ฐฑ์
์บ์ฑ (fetchEpisodes์์ ๋ชป ๊ฐ์ ธ์์ผ๋ฉด play ์๋ต์์ ์ฑ์)
// ๊ฐ๋: tvchak vod_class๋ ์ข
์ข
"๊ธ์์ผ" ๊ฐ์ ๋ฐฉ์ก์์ผ์ ๋ฐํํจ โ ํ์ดํธ๋ฆฌ์คํธ ํต๊ณผ๋ง ์ ์ฅ.
if (fav && src === 'tvchak' && !fav.category && p.vod_data?.vod_class) {
const vc = String(p.vod_data.vod_class);
const m = vc.match(/(๋๋ผ๋ง|์๋ฅ|์ํ|์ ๋|์์ฌ๊ต์|๋คํ|ํค์ฆ|์คํฌ์ธ )/);
if (m) {
fav.category = m[1];
saveFavs();
renderFavs();
}
}
const title = (p.vod_data && p.vod_data.vod_name) || (fav && fav.title) || '';
const ep = currentEpList.find(e => e.sid === sid && e.nid === nid) || currentEpList.find(e => e.nid === nid);
const epLabel = (ep && ep.label) || `${nid}ํ`;
const sourceLabel = src === 'anilife' ? '<span class="src-badge ani">์ ๋</span> ' : '';
// ํด๋ฐฑ ์ฌ์ฉ ์ ์์ ๋ฐฐ์ง โ play ์๋ต์ _fallbackSource(์๋ฒ) ๋๋ fav.usingFallback(loadEpisodes์์ ์ ์ฅํ ๊ฐ)
const fbSrc = p._fallbackSource || fav?.usingFallback;
const fallbackBadge = fbSrc ? `<span class="fb-badge" title="์๋ณธ(${src}) ์ฐจ๋จยท์ฅ์ ๋ก ${fbSrc}์์ ์ฌ์ ์ค">${esc(fbSrc)}</span> ` : '';
// ๋ค์ด๋ก๋: tvchak์ ์ง์ mp4 ๋ค์ด๋ก๋, anilife๋ HLS๋ผ ์์ง ๋ฏธ์ง์
const canDownload = src === 'tvchak' && p.url;
const dlBtn = canDownload
? `<button class="dl-btn" id="btnDownload" title="๋ค์ด๋ก๋"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v12"></path><path d="M7 10l5 5 5-5"></path><path d="M5 21h14"></path></svg></button>`
: '';
$('#nowMeta').innerHTML = `
<div class="title-row">
<div class="title">${sourceLabel}${esc(title)}${fallbackBadge}</div>
${dlBtn}
</div>
<div class="sub">${esc(epLabel)}${ep?.subject ? ' ยท ' + esc(ep.subject) : ''} ${p.vod_data?.vod_class ? 'ยท ' + esc(p.vod_data.vod_class) : ''} ${p.vod_data?.vod_actor ? 'ยท ' + esc(p.vod_data.vod_actor) : ''}</div>
`;
// ๋ค์ด๋ก๋ ๋์์ ํจ์๋ก ์ถ์ถ โ nowMeta ๋ฒํผ๊ณผ moreMenu์์ ๊ณตํต ์ฌ์ฉ
if (canDownload) {
const safeName = `${title}_${epLabel}`.replace(/[\\/:*?"<>|]/g, '_').slice(0, 80) + '.mp4';
const dlUrl = '/cdn?u=' + encodeURIComponent(p.url)
+ '&r=' + encodeURIComponent(p.referer || '')
+ '&dl=' + encodeURIComponent(safeName);
window._currentDownload = { url: dlUrl, name: safeName };
const triggerDownload = () => {
const a = document.createElement('a');
a.href = dlUrl; a.download = safeName; a.rel = 'noopener';
document.body.appendChild(a); a.click(); a.remove();
};
$('#btnDownload')?.addEventListener('click', triggerDownload);
} else {
window._currentDownload = null;
}
// ์ฑ๋ฐ ๋ก๊ณ ๋ ๊ทธ๋๋ก ์ ์ง โ ์์ ์ ๋ณด๋ nowMeta์ ํ์
if (fav && userInitiated && !playEpisode._fallback) {
// ์ฌ์ฉ์๊ฐ ์ง์ ์ ํํ ๊ฒฝ์ฐ์๋ง last* ๊ฐฑ์
fav.lastSid = sid; fav.lastNid = nid;
fav.lastLabel = epLabel;
fav.lastSeenLabel = epLabel;
fav.clickedAt = Date.now();
if (fav.knownCount != null) fav.lastSeenCount = fav.knownCount;
markCaughtUpIfNeeded(fav);
saveFavs();
renderFavs();
}
currentEpIdx = currentEpList.findIndex(e => e.sid === sid && e.nid === nid);
renderEpisodes();
// ๋ชจ๋ฐ์ผ์์ ๋น๋์ค๋ก ์คํฌ๋กค
if (isMobile()) window.scrollTo({ top: 0, behavior: 'smooth' });
} catch (e) {
console.warn('play fail', e);
// CF_PASS_NEEDED = CDP ํต๊ณผ ํญ ํ ํฐ ๋ง๋ฃ(์๋ ์ฌํต๊ณผ๋ ์คํจ). ์ฌ์ฉ์๊ฐ CDP Chrome์์ ์๋ก๊ณ ์นจ ํ์.
if (e && e.code === 'CF_PASS_NEEDED') {
$('#videoEmpty').textContent = '์ฐ๊ฒฐ์ด ๋ง๋ฃ๋์ด์. ์ ์ ํ ๋ค์ ์๋ํ๊ฑฐ๋, CDP ์ฐฝ์ ์๋ก๊ณ ์นจํด ์ฃผ์ธ์.';
} else {
$('#videoEmpty').textContent = '์ฌ์ ์คํจ: ' + e.message + ' โ ๋ค๋ฅธ ํ์ฐจ๋ฅผ ์ ํํด๋ณด์ธ์.';
}
$('#videoEmpty').classList.remove('hide');
// ์ฌ์ฉ์๊ฐ ๋ช
์์ ์ผ๋ก ๋๋ฅธ ๊ฒ ์๋๋ผ ์๋ fallback์ผ ๋๋ง ์ต์ ํ๋ก ์๋
if (!playEpisode._fallback && currentEpList.length) {
const latest = [...currentEpList].sort((a, b) => a.sid - b.sid || a.nid - b.nid)[0];
if (latest.sid !== sid || latest.nid !== nid) {
playEpisode._fallback = true;
try { await playEpisode(id, latest.sid, latest.nid); } finally { playEpisode._fallback = false; }
}
}
} finally {
$('#videoLoading').style.display = 'none';
}
}
function stopPlayer() {
const v = $('#player');
if (_currentHls) { try { _currentHls.destroy(); } catch {} _currentHls = null; }
v.pause(); v.removeAttribute('src'); v.load();
$('#videoEmpty').classList.remove('hide');
$('#nowMeta').innerHTML = '';
currentEpList = []; currentEpIdx = -1;
$('#epSection').style.display = 'none';
}
// โโโ ์ฆ๊ฒจ์ฐพ๊ธฐ ์ถ๊ฐ โโโ
async function addFav(input, extra = {}) {
// input์ด ๊ฐ์ฒด๋ฉด ๊ฒ์ ๊ฒฐ๊ณผ์์ ์ง์ ํธ์ถ. ๋ฌธ์์ด์ด๋ฉด parseInput.
let parsed;
if (typeof input === 'object' && input !== null) {
parsed = { id: +input.id, source: input.source || 'tvchak', title: input.title || null, category: input.category || null, poster: input.poster || null };
} else {
parsed = parseInput(input);
}
if (!parsed) { alert('ํฐ๋น์ฐฉ/์ ๋๋ผ์ดํ URL์ด๋ ID(์ซ์)๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.'); return; }
// ๋ณด๊ดํจ ํค๋ (source, id) ์ โ ๊ฐ์ id๊ฐ ๋ ์์ค์ ์์ ์ ์์
const source = parsed.source || 'tvchak';
let fav = favs.find(f => f.id === parsed.id && (f.source || 'tvchak') === source);
if (!fav) {
fav = { id: parsed.id, source, title: parsed.title || null, category: parsed.category || null, poster: parsed.poster || null, addedAt: Date.now() };
if (parsed.sid != null) { fav.lastSid = parsed.sid; fav.lastNid = parsed.nid; }
favs.unshift(fav);
saveFavs();
}
renderFavs();
await selectFav(parsed.id, { ...(parsed.sid != null ? { sid: parsed.sid, nid: parsed.nid } : {}), source });
}
// โโโ ๊ฒ์ โโโ
async function doSearch(wd, hostId) {
if (!wd.trim()) return;
pushRecentSearch(wd); // A1: ์ต๊ทผ ๊ฒ์์ด์ ์ ์ฅ
const host = $('#' + hostId);
if (hostId === 'searchResults') $('#searchResultsWrap').style.display = '';
host.innerHTML = '<div style="padding:12px;color:var(--muted);font-size:12px">๊ฒ์ ์คโฆ</div>';
try {
// source=all ์ด๋ฉด ์์ชฝ ํฉ์ณ์ ์ด
const r = await api(`/api/search?source=all&wd=${encodeURIComponent(wd)}`);
const tv = r.tvchak || { items: [] };
const ani = r.anilife || { items: [] };
const allItems = [
...(tv.items || []).map(it => ({ ...it, source: 'tvchak' })),
...(ani.items || []).map(it => ({ ...it, source: 'anilife' })),
];
if (!allItems.length) {
host.innerHTML = '<div style="padding:12px;color:var(--muted);font-size:12px">๊ฒฐ๊ณผ ์์</div>';
return;
}
host.innerHTML = '';
for (const it of allItems) {
const already = favs.find(f => f.id === it.id && (f.source || 'tvchak') === it.source);
// E2: tvchak ๊ฒ์ ๊ฒฐ๊ณผ meta("์๋ฅ / 2026 / ...")์์ ์ฒซ ํ ํฐ์ ์นดํ
๊ณ ๋ฆฌ๋ก
let tvCat = null;
if (it.source === 'tvchak' && typeof it.meta === 'string') {
const m = it.meta.match(/(๋๋ผ๋ง|์๋ฅ|์ํ|์ ๋|์์ฌ๊ต์|๋คํ|ํค์ฆ|์คํฌ์ธ )/);
if (m) tvCat = m[1];
}
const badge = it.source === 'anilife'
? '<span class="src-badge ani">์ ๋</span> '
: tvCat
? `<span class="src-badge tv ${/์๋ฅ/.test(tvCat)?'ent':/์ํ/.test(tvCat)?'mov':''}">${esc(tvCat)}</span> `
: '<span class="src-badge tv">๋๋ผ๋ง</span> ';
const div = document.createElement('div');
div.className = 'sr-item';
div.innerHTML = `<b>${badge}${esc(it.title)}</b><div class="meta${already ? ' star' : ''}">${esc(it.meta || '')}${already ? ' ยท โ
์ฆ๊ฒจ์ฐพ๊ธฐ' : ''}</div>`
+ `<button class="sr-fav${already ? ' added' : ''}" data-favbtn aria-label="๋ณด๊ดํจ ์ถ๊ฐ">${already ? 'โ
' : 'โ'}</button>`;
// D10: โ
๋ฒํผ (์ด๋ฒคํธ stop)
div.querySelector('[data-favbtn]').addEventListener('click', async (e) => {
e.stopPropagation();
if (already) { showMediaToast('์ด๋ฏธ ๋ณด๊ดํจ์ ์์ด์'); return; }
await addFav({ id: it.id, source: it.source, title: it.title, category: tvCat, poster: it.poster || null });
const b = div.querySelector('[data-favbtn]');
b.classList.add('added'); b.textContent = 'โ
';
showMediaToast('๋ณด๊ดํจ์ ์ถ๊ฐ๋จ โ
');
});
// ์นด๋ ๋ณธ๋ฌธ ํด๋ฆญ์ ๊ธฐ์กด์ฒ๋ผ ์ฆ๊ฒจ์ฐพ๊ธฐ ์ถ๊ฐ
div.addEventListener('click', async (e) => {
if (e.target.closest('[data-favbtn]')) return;
await addFav({ id: it.id, source: it.source, title: it.title, category: tvCat, poster: it.poster || null });
if (isMobile()) closeMobileSearch();
});
host.appendChild(div);
}
} catch (e) {
host.innerHTML = `<div style="padding:12px;color:#ff7b7b">${esc(e.message)}</div>`;
}
}
// โโโ ๋ชจ๋ฐ์ผ ๊ฒ์ ํจ๋ โโโ
function openMobileSearch() {
$('#searchHead').style.display = '';
$('#searchBar').style.display = '';
$('#searchInputMob').focus();
}
function closeMobileSearch() {
$('#searchHead').style.display = 'none';
$('#searchBar').style.display = 'none';
$('#searchResultsMob').innerHTML = '';
$('#searchInputMob').value = '';
}
// โโโ ๋ชจ๋ฌ โโโ
function openAddModal() {
$('#addUrl').value = '';
$('#addModal').classList.add('show');
setTimeout(() => $('#addUrl').focus(), 50);
}
function closeAddModal() { $('#addModal').classList.remove('show'); }
// โโโ ์์ ํ๋/์ถ์: ๋ชจ๋ฐ์ผ(๋๋ธํญ/ํ์น) + ๋ฐ์คํฌํ(ํ /๋๋๊ทธ/๋๋ธํด๋ฆญ) โโโ
(function setupVideoZoom() {
const v = $('#player');
const wrap = $('#videoWrap');
let zoom = 1;
let tx = 0, ty = 0; // ํจ๋ ์คํ์
let lastTap = 0;
let pinchStart = null;
let dragStart = null;
// โถ ๋ฒํผ โ wrapper๋ฅผ ํ์คํฌ๋ฆฐ์ผ๋ก (์ด๋ฌ๋ฉด video ์์์ transform ์ค์ด ํตํจ)
$('#btnFsZoom')?.addEventListener('click', async (e) => {
e.stopPropagation();
try {
if (!isFullscreen()) {
await (wrap.requestFullscreen || wrap.webkitRequestFullscreen).call(wrap);
} else {
await (document.exitFullscreen || document.webkitExitFullscreen).call(document);
}
} catch {}
});
function apply() {
if (zoom === 1) {
v.style.transform = '';
v.style.cursor = '';
tx = 0; ty = 0;
} else {
v.style.transform = `translate(${tx}px, ${ty}px) scale(${zoom})`;
v.style.cursor = dragStart ? 'grabbing' : 'grab';
}
v.style.transformOrigin = 'center center';
}
function setZoom(z, cx, cy, opts = {}) {
const newZoom = Math.max(1, Math.min(4, z));
if (newZoom === 1) { tx = 0; ty = 0; }
zoom = newZoom;
clampPan();
apply();
// ํ์คํฌ๋ฆฐ ์์์ ์ฌ์ฉ์๊ฐ ์ง์ ์ค ์กฐ์ํ ๊ฒฝ์ฐ๋ง fav์ ์ ์ฅ (์๋ ๋ณต์ ์๋ ์ ์ฅ ์ ํจ)
if (!opts.silent && isFullscreen() && currentFavId) {
const fav = favs.find(f => f.id === currentFavId && (f.source || 'tvchak') === (currentFavSource || 'tvchak'));
if (fav) {
fav.zoom = fav.zoom || {};
const key = isMobile() ? 'mobile' : 'desktop';
// 1์ด๋ฉด ์ ์ฅ ํค ์ญ์ (๊ธฐ๋ณธ๊ฐ์ผ๋ก ๋ณต๊ท)
if (newZoom === 1) {
delete fav.zoom[key];
if (!fav.zoom.mobile && !fav.zoom.desktop) delete fav.zoom;
} else {
fav.zoom[key] = +newZoom.toFixed(3);
}
if (typeof saveFavs === 'function') saveFavs();
}
}
}
// ํ์คํฌ๋ฆฐ ์ง์
์ ์ ์ฅ๋ ์ค ์๋ ๋ณต์
function restoreSavedZoom() {
if (!currentFavId) return;
const fav = favs.find(f => f.id === currentFavId && (f.source || 'tvchak') === (currentFavSource || 'tvchak'));
const key = isMobile() ? 'mobile' : 'desktop';
const saved = fav?.zoom?.[key];
if (typeof saved === 'number' && saved > 1) {
setZoom(saved, null, null, { silent: true });
}
}
function clampPan() {
// ๋น๋์ค๊ฐ ํ๋ฉด ๋ฐ์ผ๋ก ๋๋ฌด ๋ฒ์ด๋์ง ์๊ฒ
const rect = v.getBoundingClientRect();
const maxX = rect.width * (zoom - 1) / 2;
const maxY = rect.height * (zoom - 1) / 2;
tx = Math.max(-maxX, Math.min(maxX, tx));
ty = Math.max(-maxY, Math.min(maxY, ty));
}
// ๋๋ธํด๋ฆญ โ ์ข์ธก 1/3์ -5์ด, ์ฐ์ธก 1/3์ +5์ด, ์ค์์ ํ์คํฌ๋ฆฐ ํ ๊ธ
v.addEventListener('dblclick', (e) => {
e.preventDefault();
const rect = v.getBoundingClientRect();
const x = e.clientX - rect.left;
const w = rect.width;
if (!isFinite(v.duration)) return;
if (x < w / 3) {
v.currentTime = Math.max(0, v.currentTime - 5);
showToast('โช -5์ด');
} else if (x > w * 2 / 3) {
v.currentTime = Math.min(v.duration, v.currentTime + 5);
showToast('+5์ด โฉ');
} else {
$('#btnFsZoom')?.click();
}
});
v.addEventListener('click', (e) => {
// ๋ชจ๋ฐ์ผ ๋๋ธํญ์ผ๋ก ์ค ํ ๊ธ โ ๋จ, ๋ง์ฐ์ค(pointerType์ด mouse)๋ ์ ์ธ.
// pointerType ํ์ธ ์ ๋๋ฉด ์ขํ ๊ธฐ๋ฐ: ๋๋ธํด๋ฆญ๊ณผ ๋์ผํ๊ฒ ์ค์ 1/3๋ง ์ค (์ข/์ฐ๋ ์ ํ์ ์ถฉ๋)
if (!('ontouchstart' in window)) return;
const now = Date.now();
if (now - lastTap < 350) {
// ์ค์ ์์ญ์์๋ง ์ค (์ข/์ฐ๋ click ํธ๋ค๋ฌ ๋๋์ ยฑ5์ด ๋ถ์ฐ๋ฌผ ๋ฐฉ์ง)
const rect = v.getBoundingClientRect();
const x = e.clientX - rect.left;
const w = rect.width;
if (x >= w / 3 && x <= w * 2 / 3) {
setZoom(zoom > 1 ? 1 : 1.75);
}
}
lastTap = now;
});
// ํ์คํฌ๋ฆฐ ์ฌ๋ถ โ wrapper๊ฐ ํ์คํฌ๋ฆฐ์ผ ๋๋ง (video ์์ฒด ํ์คํฌ๋ฆฐ์ transform ์ ๋จน์ด์ ์ ์ธ)
function isFullscreen() {
const fs = document.fullscreenElement || document.webkitFullscreenElement;
return fs === wrap;
}
// ๋ง์ฐ์คํ ์ค โ ํ์คํฌ๋ฆฐ์ผ ๋๋ง. document ๋ ๋ฒจ์์ ์ก์์ผ ํ์คํฌ๋ฆฐ ๋น๋์ค์๋ ๋๋ฌํจ.
document.addEventListener('wheel', (e) => {
if (!isFullscreen()) return;
if (e.ctrlKey) return;
// ํ์คํฌ๋ฆฐ ๋์์ด ์ฐ๋ฆฌ video์ธ์ง ํ์ธ
const fsEl = document.fullscreenElement || document.webkitFullscreenElement;
if (fsEl !== wrap) return;
e.preventDefault();
const delta = e.deltaY > 0 ? -0.15 : 0.15;
setZoom(zoom + delta);
}, { passive: false });
// ๋๋๊ทธ ํจ๋ โ document ๋ ๋ฒจ (ํ์คํฌ๋ฆฐ + ์ค 1 ์ด์์ผ ๋๋ง)
document.addEventListener('mousedown', (e) => {
const fsEl = document.fullscreenElement || document.webkitFullscreenElement;
if (fsEl !== wrap || zoom <= 1) return;
// ์ค๋ฒ๋ ์ด ์ปจํธ๋กค ํด๋ฆญ์ ๋ฌด์ (๋๋๊ทธ ํจ๋๊ณผ ์ถฉ๋ ๋ฐฉ์ง)
if (e.target.closest('#zoomCtrl, #btnFsZoom')) return;
e.preventDefault();
dragStart = { x: e.clientX - tx, y: e.clientY - ty };
v.style.cursor = 'grabbing';
});
// (์์ ํด๋ฆญ โ ์ฌ์/์ ์ง ํ ๊ธ์ ์ ๊ฑฐ. ์๋์น ์์ ์ผ์์ ์ง ๋น๋ฐ + ๋๋ฅด๊ณ ์๊ธฐ ๋ฐฐ์๊ณผ ์ธ์ง ์ถฉ๋.
// ์ฌ์/์ ์ง๋ ์ปจํธ๋กค๋ฐ โถ ๋ฒํผ ๋๋ Space/K ํค๋ก๋ง.)
// โโโ ๋๋ฅด๊ณ ์์ผ๋ฉด 3๋ฐฐ์ (press-and-hold) โโโ
// 500ms ์ด์ ๊พน ๋๋ฅด๊ณ ์์ผ๋ฉด playbackRate = 3, ์์ ๋ผ๋ฉด ์๋ ์๋ ๋ณต๊ท.
// ์ผ์ฑ์ธํฐ๋ทยท์ผ๋ถ ์๋ Chrome์์ <video>๊ฐ long-press ์ด๋ฒคํธ๋ฅผ ์์ฒด ์๋นํ๋ฏ๋ก
// video ์์ ํฌ๋ช
์ค๋ฒ๋ ์ด(#holdOverlay)๋ฅผ ๊น๊ณ ๊ฑฐ๊ธฐ์ ์ด๋ฒคํธ ์บก์ฒ.
// pointer ์ด๋ฒคํธ + touchstart/touchend ๋ ๋ค ๋ฑ๋ก(๋ธ๋ผ์ฐ์ ๋ณ ์ ๋จน๋ ๊ฒฝ์ฐ backup).
const holdOv = document.getElementById('holdOverlay');
let _holdTimer = null;
let _holdActive = false;
let _holdPrevRate = 1;
let _holdStartX = 0, _holdStartY = 0;
const HOLD_MS = 500;
const HOLD_MOVE_TOLERANCE = 12;
function _cancelHoldTimer() {
if (_holdTimer) { clearTimeout(_holdTimer); _holdTimer = null; }
}
function _exitHoldFast() {
if (!_holdActive) return;
_holdActive = false;
try { v.playbackRate = _holdPrevRate; } catch {}
}
function _holdStart(x, y) {
if (!currentFavId) return;
if (v.paused || v.ended) return;
_cancelHoldTimer();
_holdStartX = x; _holdStartY = y;
_holdTimer = setTimeout(() => {
_holdTimer = null;
_holdPrevRate = v.playbackRate || 1;
_holdActive = true;
try { v.playbackRate = 3; } catch {}
}, HOLD_MS);
}
function _holdMove(x, y) {
// hold ์ง์
ํ์ ์๊ฐ๋ฝ ๋ฏธ์ธ ๋จ๋ฆผ ๋ฌด์. ์ง์
์ (timer ๋๊ธฐ)์ผ ๋๋ง 40px+ ์ด๋์์ ์ทจ์.
if (!_holdTimer) return;
if (Math.abs(x - _holdStartX) > 40 || Math.abs(y - _holdStartY) > 40) {
_cancelHoldTimer();
}
}
function _holdEnd() {
_cancelHoldTimer();
_exitHoldFast();
}
// wrap์ ์บก์ฒ ๋จ๊ณ๋ก ํ ๋ฒ๋ง ๋ฑ๋ก (์ค๋ฒ๋ ์ด๋ wrap ์์์ด๋ผ ์บก์ฒ๋ฉด ํจ๊ป ์กํ).
// touch ์ด๋ฒคํธ๋ง ์ฌ์ฉ โ pointer๋ ์ผ๋ถ ๋ชจ๋ฐ์ผ ๋ธ๋ผ์ฐ์ ์์ video native ๋ ์ด์ด๊ฐ ํก์.
// pointerleave ๊ฐ์ ์๋๋ฐํ ์ข
๋ฃ ์ด๋ฒคํธ๋ ๋ฑ๋ก ์ ํจ (touchstart ์งํ leave๊ฐ ์ฆ์ ๋ฐํํ๋ ๊ฒฝ์ฐ ์์).
// ratechange ํ ์คํธ๊ฐ ๋ณ๋๋ก ๋ ์ ์ง์
/ํด์ ๋ ๊ทธ์ชฝ์ผ๋ก ์ฒ๋ฆฌ๋จ โ ์ฌ๊ธฐ์ ํ ์คํธ ํธ์ถ ์ ํจ.
// ๋๋ธํญ(ยฑ5์ด/์ค) ์ง์ ๊ฐ์ง โ touchstart์์ preventDefaultํ๋ฉด ๋ธ๋ผ์ฐ์ ์
// click/dblclick ํฉ์ฑ์ด ๋งํ video์ ๊ธฐ์กด dblclick ํธ๋ค๋ฌ๊ฐ ์ ๋์ํ๋ฏ๋ก
// wrap์์ ์ฐ๋ฆฌ๊ฐ ์ง์ ์ฒ๋ฆฌํ๋ค.
let _lastTapAt = 0, _lastTapX = 0, _lastTapY = 0;
const DBL_TAP_MS = 350;
const DBL_TAP_TOL = 30;
function _handleDoubleTap(x, y) {
const rect = v.getBoundingClientRect();
const lx = x - rect.left;
const w = rect.width;
if (!isFinite(v.duration)) return;
if (lx < w / 3) {
v.currentTime = Math.max(0, v.currentTime - 5);
if (typeof showToast === 'function') showToast('โช -5์ด');
} else if (lx > w * 2 / 3) {
v.currentTime = Math.min(v.duration, v.currentTime + 5);
if (typeof showToast === 'function') showToast('+5์ด โฉ');
}
// ์ค์: ์๋ฌด ์ผ๋ ์ ํจ (ํ๋๋ ํ์น์ค์ผ๋ก๋ง)
}
wrap.addEventListener('touchstart', (e) => {
const t = e.touches[0];
if (!t) return;
// ์ฐ๋ฆฌ UI ์์์ ์์๋ ํฐ์น๋ ์ ์ธ
// #nextCountdown ๋๋ฝ ์: wrap touchstart์ preventDefault๊ฐ click ํฉ์ฑ์ ๋ง๊ณ โ ๋ ๋ฒ์งธ ํญ์ด
// ๋๋ธํญ(+5์ด)์ผ๋ก ์กํ ์นด์ดํธ๋ค์ด ๋ฒํผ ํด๋ฆญ์ด ์์ ์ ๋จน๋ ์ฌ๊ณ (2026-06-08). ๋ฐ๋์ ํฌํจ.
// #nextPreview(F-8 ์ฐ์๋จ "๋ค์ โถ")๋ ๋์ผ ํจํด โ ๋ชจ๋ฐ์ผ์์ ์ ๋๋ฆฌ๋ ์ฌ๊ณ (2026-06-14).
if (e.target.closest('#zoomCtrl, #moreMenu, #btnFsZoom, #btnSideToggle, #pauseOverlay, .skip-btn, .lock-btn, .hls-quality, .hls-audio, .hls-sub, #nextCountdown, #nextPreview')) return;
// ๋ ๋ฒ์งธ ์๊ฐ๋ฝ์ด ๋ฟ๋ ์๊ฐ โ ํ์น ์์. hold/๋๋ธํญ ์ํ ์ ๋ฆฌํ๊ณ ์ฐ๋ฆฌ๊ฐ ์ง์ ์ฒ๋ฆฌ.
// (์ค๋ฒ๋ ์ด๊ฐ video๋ฅผ ๋ฎ๊ณ ์์ด video์ native ํ์น ํธ๋ค๋ฌ๊น์ง ์ด๋ฒคํธ๊ฐ ์ ๊ฐ)
if (e.touches.length >= 2) {
_cancelHoldTimer();
_exitHoldFast();
_lastTapAt = 0;
pinchStart = { dist: tdist(e.touches[0], e.touches[1]), zoom };
return;
}
// ๋จ์ผ ํฐ์น: ์ผ์ฑ์ธํฐ๋ทยท์ผ๋ถ ์๋ ๋ธ๋ผ์ฐ์ ๊ฐ touchstart ์งํ long-press gesture๋ก
// ๊ฐ๋ก์ฑ๋ฉฐ ์ฆ์ touchend๋ฅผ ๋ฐํ โ preventDefault๋ก ์ฐจ๋จ.
try { e.preventDefault(); } catch {}
// ๋๋ธํญ ๊ฐ์ง โ preventDefault๋ก ์ธํด native dblclick์ด ์ ์ค๋ฏ๋ก ์ฌ๊ธฐ์ ์ง์ .
const now = Date.now();
if (now - _lastTapAt < DBL_TAP_MS &&
Math.abs(t.clientX - _lastTapX) < DBL_TAP_TOL &&
Math.abs(t.clientY - _lastTapY) < DBL_TAP_TOL) {
_handleDoubleTap(t.clientX, t.clientY);
_lastTapAt = 0; // ํธ๋ฆฌํํญ ๋ฐฉ์ง
return; // hold ํ์ด๋จธ ์์ ์ ํจ
}
_lastTapAt = now;
_lastTapX = t.clientX;
_lastTapY = t.clientY;
_holdStart(t.clientX, t.clientY);
}, { passive: false, capture: true });
wrap.addEventListener('touchmove', (e) => {
// ํ์น โ ๋ ์๊ฐ๋ฝ ๊ฑฐ๋ฆฌ ๋ณํ๋ก ์ค ์กฐ์
if (e.touches.length >= 2 && pinchStart) {
const d = tdist(e.touches[0], e.touches[1]);
setZoom(pinchStart.zoom * (d / pinchStart.dist));
return;
}
const t = e.touches[0];
if (!t) return;
_holdMove(t.clientX, t.clientY);
}, { passive: true, capture: true });
wrap.addEventListener('touchend', (e) => {
if (e.touches.length < 2) pinchStart = null;
_holdEnd();
}, true);
wrap.addEventListener('touchcancel', () => { pinchStart = null; _holdEnd(); }, true);
// ๋ง์ฐ์ค(๋ฐ์คํฌํ)์ฉ โ pointerdown๋ง, leave๋ ๋ฑ๋ก ์ ํจ
wrap.addEventListener('pointerdown', (e) => {
if (e.pointerType !== 'mouse') return; // ํฐ์น๋ ์์์ ์ฒ๋ฆฌ
if (e.button !== 0) return;
if (e.target.closest('#zoomCtrl, #moreMenu, #btnFsZoom, #btnSideToggle, #pauseOverlay, .skip-btn, .lock-btn, .hls-quality, .hls-audio, .hls-sub, #nextCountdown, #nextPreview')) return;
_holdStart(e.clientX, e.clientY);
}, true);
wrap.addEventListener('pointermove', (e) => {
if (e.pointerType !== 'mouse') return;
_holdMove(e.clientX, e.clientY);
}, true);
wrap.addEventListener('pointerup', (e) => {
if (e.pointerType !== 'mouse') return;
_holdEnd();
}, true);
// ๋ฐ์คํฌํ ๋๋ธํด๋ฆญ โ ์ข/์ฐ 1/3 ยฑ5์ด, ์ค์ ํ์คํฌ๋ฆฐ ํ ๊ธ.
// #holdOverlay(z-index:2)๊ฐ video๋ฅผ ๋ฎ์ด video์ dblclick ํธ๋ค๋ฌ์ ์ด๋ฒคํธ๊ฐ ์ ๋ฟ์ผ๋ฏ๋ก
// wrap ์บก์ฒ ๋จ๊ณ์์ ์ง์ ์ฒ๋ฆฌ(๋ชจ๋ฐ์ผ _handleDoubleTap๊ณผ ๋์ผ ๋ก์ง + ์ค์ ํ์คํฌ๋ฆฐ).
wrap.addEventListener('dblclick', (e) => {
if (e.pointerType === 'touch') return; // ํฐ์น ๋๋ธํญ์ touchstart์์ ์ฒ๋ฆฌ
if (e.target.closest('#zoomCtrl, #moreMenu, #btnFsZoom, #btnSideToggle, #pauseOverlay, .skip-btn, .lock-btn, .hls-quality, .hls-audio, .hls-sub, #nextCountdown, #nextPreview')) return;
if (!isFinite(v.duration)) return;
const rect = v.getBoundingClientRect();
const lx = e.clientX - rect.left;
const w = rect.width;
if (lx < w / 3) {
v.currentTime = Math.max(0, v.currentTime - 5);
if (typeof showToast === 'function') showToast('โช -5์ด');
} else if (lx > w * 2 / 3) {
v.currentTime = Math.min(v.duration, v.currentTime + 5);
if (typeof showToast === 'function') showToast('+5์ด โฉ');
} else {
$('#btnFsZoom')?.click();
}
}, true);
wrap.addEventListener('contextmenu', (e) => {
e.preventDefault();
_holdEnd();
}, true);
// ํ์คํฌ๋ฆฐ ์ง์
/ํ์ถ ์ โ ์ค ์ค๋ฒ๋ ์ด ์ปจํธ๋กค ํ ๊ธ
const zoomCtrl = $('#zoomCtrl');
let hideTimer = null;
function showControls() {
// ์ ๊ธ ์ํ์์๋ ์ผ๋ฐ ์ปจํธ๋กค(zoomCtrl ๋ฑ)์ ๋์ฐ๋ฉด ์ ๋จ โ ๋จ์ skip.
// ์๋ฌผ์ ํํธ๋ ์ ๊ธ ์ฐจ๋จ ํธ๋ค๋ฌ(touchstart/click/pointerdown)์์๋ง pingLockHint๋ก ํธ๋ฆฌ๊ฑฐ.
if (wrap.classList.contains('locked')) return;
wrap.classList.add('show-controls');
wrap.classList.remove('hide-cursor');
clearTimeout(hideTimer);
if (isFullscreen()) {
hideTimer = setTimeout(hideControls, 3000);
}
}
function hideControls() {
if (!isFullscreen()) return;
// ๋ง์ฐ์ค ํฌ์ธํฐ๊ฐ zoom-ctrl ์์ ์์ผ๋ฉด ์ ์จ๊น
if (zoomCtrl.matches(':hover')) {
hideTimer = setTimeout(hideControls, 2000);
return;
}
wrap.classList.remove('show-controls');
wrap.classList.add('hide-cursor');
}
function onFsChange() {
if (isFullscreen()) {
// zoomCtrl์ ํญ์ ํ์๋จ (์ผ๋ฐยทํ์คํฌ๋ฆฐ ๊ณต์ฉ). ํ์คํฌ๋ฆฐ๋ง ์ถ๊ฐ ์ฒ๋ฆฌ.
showControls();
// ์ ์ฅ๋ ์ค์ด ์์ผ๋ฉด ์๋ ๋ณต์
restoreSavedZoom();
// ๋ชจ๋ฐ์ผ: ํ์คํฌ๋ฆฐ ์ง์
์ ๊ฐ๋ก ์ ๊ธ (์์ ์์ฒญ์ ์ต์ ํ)
// Chrome Android ์ง์, iOS Safari ๋ฏธ์ง์(๊ถํ ์์) โ ์คํจํด๋ ๋ฌด์
if (isMobile() && screen.orientation && typeof screen.orientation.lock === 'function') {
screen.orientation.lock('landscape').catch(() => {});
}
} else {
wrap.classList.remove('show-controls', 'hide-cursor');
clearTimeout(hideTimer);
zoom = 1; tx = 0; ty = 0; apply();
// ํ์คํฌ๋ฆฐ ์ข
๋ฃ ์ ํ์ ์ ๊ธ ํด์
if (screen.orientation && typeof screen.orientation.unlock === 'function') {
try { screen.orientation.unlock(); } catch {}
}
}
}
document.addEventListener('fullscreenchange', onFsChange);
document.addEventListener('webkitfullscreenchange', onFsChange);
// ํ์คํฌ๋ฆฐ์ผ ๋ ๋ง์ฐ์ค ์์ง์/ํฐ์น๋ก ์ปจํธ๋กค ์๋ ํ์
wrap.addEventListener('mousemove', () => { if (isFullscreen()) showControls(); });
// ๋ชจ๋ฐ์ผ/ํฐ์น: ์ผ๋ฐ ๋ชจ๋์์๋ ์์ ์์ญ ํญํ๋ฉด ์ปจํธ๋กค 4์ด๊ฐ ํ์ (PC๋ CSS :hover๋ก ์๋)
let _inlineHideTimer = null;
wrap.addEventListener('touchstart', () => {
if (isFullscreen()) { showControls(); return; }
wrap.classList.add('show-controls');
clearTimeout(_inlineHideTimer);
_inlineHideTimer = setTimeout(() => wrap.classList.remove('show-controls'), 4000);
}, { passive: true });
// ์ปจํธ๋กค๋ฐ์ ๋ง์ฐ์ค ์ฌ๋ผ๊ฐ์์ผ๋ฉด ํญ์ ๋ณด์ด๊ฒ
zoomCtrl.addEventListener('mouseenter', () => { clearTimeout(hideTimer); });
zoomCtrl.addEventListener('mouseleave', () => {
if (isFullscreen()) hideTimer = setTimeout(hideControls, 1500);
});
// ์ค๋ฒ๋ ์ด ์ปจํธ๋กค ํธ๋ค๋ฌ
$('#zcPlay')?.addEventListener('click', () => {
if (v.paused) v.play(); else v.pause();
});
$('#zcReset')?.addEventListener('click', () => { setZoom(1); });
$('#zcExit')?.addEventListener('click', () => {
(document.exitFullscreen || document.webkitExitFullscreen).call(document);
});
// ์งํ๋ฐ โ ์ฌ์ฉ์๊ฐ ๋๋๊ทธ ์ค์๋ ์๋ ๊ฐฑ์ ๋ฉ์ถค
let seeking = false;
$('#zcBar')?.addEventListener('input', () => { seeking = true; });
$('#zcBar')?.addEventListener('change', () => {
if (!v.duration) return;
v.currentTime = (parseFloat($('#zcBar').value) / 1000) * v.duration;
seeking = false;
});
v.addEventListener('timeupdate', () => {
if (!zoomCtrl.hidden && v.duration) {
if (!seeking) $('#zcBar').value = (v.currentTime / v.duration) * 1000;
const fmt = (s) => `${Math.floor(s/60)}:${String(Math.floor(s%60)).padStart(2,'0')}`;
$('#zcTime').textContent = `${fmt(v.currentTime)} / ${fmt(v.duration)}`;
}
});
v.addEventListener('play', () => { $('#zcPlay').textContent = 'โโ'; });
v.addEventListener('pause', () => { $('#zcPlay').textContent = 'โถ'; });
// ๋ณผ๋ฅจ ์ปจํธ๋กค + ๋ก์ปฌ(๋๋ฐ์ด์ค)๋ณ ๋ณผ๋ฅจ ์ ์ฅ/๋ณต์.
// ํ๋กํ ๋ฌด๊ด ์ ์ญ ํค(tvchak.volume/tvchak.muted) โ ์ด ๋ธ๋ผ์ฐ์ ์์๋ง ์ ์ง๋๋ฉด ๋๋ฏ๋ก.
// ์๋ก๊ณ ์นจ ์ <video>๋ ๊ธฐ๋ณธ๊ฐ volume=1๋ก ์ด๊ธฐํ๋๋๋ฐ, ์ ์ฅ๊ฐ์ด ์์ผ๋ฉด ๊ทธ๊ฑธ๋ก ๋ณต์.
const LS_VOLUME = 'tvchak.volume';
const LS_MUTED = 'tvchak.muted';
function saveVol() {
try {
localStorage.setItem(LS_VOLUME, String(v.volume));
localStorage.setItem(LS_MUTED, v.muted ? '1' : '0');
} catch {}
}
function restoreVol() {
try {
const sv = localStorage.getItem(LS_VOLUME);
if (sv !== null) {
const n = parseFloat(sv);
if (!isNaN(n) && n >= 0 && n <= 1) v.volume = n;
}
// muted๋ ์ ์ฅ๊ฐ ์ฐ์ . ๋จ, ๋ธ๋ผ์ฐ์ ์๋์ฌ์ ์ ์ฑ
์ผ๋ก muted๊ฐ ๊ฐ์ ๋ ์ ์์ผ๋ ๊ฐ๋ง ๋ฐ์.
const sm = localStorage.getItem(LS_MUTED);
if (sm !== null) v.muted = sm === '1';
} catch {}
}
function syncVolUI() {
const vol = v.muted ? 0 : v.volume;
$('#zcVol').value = Math.round(vol * 100);
$('#zcMute').textContent = (v.muted || v.volume === 0) ? '๐' : (v.volume < 0.5 ? '๐' : '๐');
}
$('#zcVol')?.addEventListener('input', (e) => {
const v2 = parseInt(e.target.value, 10) / 100;
v.volume = v2;
v.muted = v2 === 0;
syncVolUI();
});
$('#zcMute')?.addEventListener('click', () => {
v.muted = !v.muted;
syncVolUI();
});
v.addEventListener('volumechange', () => { syncVolUI(); saveVol(); });
// ์ ์ฅ๋ ๋ณผ๋ฅจ ๋ณต์ ํ ์ด๊ธฐ ๋๊ธฐํ. (์ <video> src ๋ก๋ ์์๋ volume์ ์ ์ง๋์ง๋ง,
// ์ ์ฒด ์๋ก๊ณ ์นจ์์ ์ด๊ธฐํ๋๋ฏ๋ก loadstart์์๋ ํ ๋ฒ ๋ ๋ณต์.)
restoreVol();
v.addEventListener('loadstart', restoreVol);
syncVolUI();
window.addEventListener('mousemove', (e) => {
if (!dragStart) return;
tx = e.clientX - dragStart.x;
ty = e.clientY - dragStart.y;
clampPan();
apply();
});
window.addEventListener('mouseup', () => {
if (dragStart) { dragStart = null; apply(); }
});
// ํ์น ์ค (๋ชจ๋ฐ์ผ)
v.addEventListener('touchstart', (e) => {
if (e.touches.length === 2) {
pinchStart = { dist: tdist(e.touches[0], e.touches[1]), zoom };
} else if (e.touches.length === 1 && zoom > 1) {
dragStart = { x: e.touches[0].clientX - tx, y: e.touches[0].clientY - ty };
}
}, { passive: true });
v.addEventListener('touchmove', (e) => {
if (e.touches.length === 2 && pinchStart) {
const d = tdist(e.touches[0], e.touches[1]);
setZoom(pinchStart.zoom * (d / pinchStart.dist));
} else if (e.touches.length === 1 && dragStart && zoom > 1) {
tx = e.touches[0].clientX - dragStart.x;
ty = e.touches[0].clientY - dragStart.y;
clampPan();
apply();
}
}, { passive: true });
v.addEventListener('touchend', (e) => {
if (e.touches.length < 2) pinchStart = null;
if (e.touches.length === 0) dragStart = null;
});
function tdist(a, b) {
const dx = a.clientX - b.clientX, dy = a.clientY - b.clientY;
return Math.sqrt(dx * dx + dy * dy);
}
// src ๋ฐ๋๋ฉด ๋ฆฌ์
โ ๋จ, ํ์คํฌ๋ฆฐ ์ ์ง ์ค์ด๋ฉด ์ ์ฅ๋ zoom์ ๋ค์ ๋ณต์ (HLS ๋ฆฌ๋ก๋/์๋ฌ ๋ณต๊ตฌ/์๋ ๋ค์ํ ๋ฑ)
const obs = new MutationObserver(() => {
zoom = 1; tx = 0; ty = 0; apply();
if (isFullscreen()) restoreSavedZoom();
});
obs.observe(v, { attributes: true, attributeFilter: ['src'] });
// HLS๋ src ์์ฑ์ด ์ ๋ฐ๋๊ณ MediaSource๋ก attach๋๋ฏ๋ก, loadedmetadata์์๋ ํ ๋ฒ ๋ ๋ณต์ ์๋
v.addEventListener('loadedmetadata', () => {
if (isFullscreen() && zoom === 1) restoreSavedZoom();
});
// ๋จ์ถํค ํธ๋ค๋ฌ์์ ์ฌ์ฉ ๊ฐ๋ฅํ๋๋ก ์ ์ญ ๋
ธ์ถ
window._videoZoom = {
getZoom: () => zoom,
setZoom,
isFullscreen,
};
})();
// โโโ ์๋ ๋ค์ ํ โโโ
$('#player').addEventListener('error', async () => {
const v = $('#player');
// src ๋น์๊ฑฐ๋(stop ๋ฑ) ์๋๋ ์ํ๋ฉด ๋ฌด์
if (!v.src || v.src === location.href) return;
console.warn('video error', v.error);
$('#videoEmpty').textContent = '์ด ํ์ฐจ์ ์์์ด ์์ต๋๋ค. ๋ค๋ฅธ ํ์ฐจ๋ฅผ ์ ํํด๋ณด์ธ์.';
$('#videoEmpty').classList.remove('hide');
$('#videoLoading').style.display = 'none';
// ํ ๋ฒ๋ง ์ต์ ํ๋ก ์๋ ๋ณต๊ตฌ
if (!playEpisode._fallback && currentEpList.length && currentEpIdx >= 0) {
const latest = [...currentEpList].sort((a, b) => a.sid - b.sid || a.nid - b.nid)[0];
const cur = currentEpList[currentEpIdx];
if (latest && (latest.sid !== cur.sid || latest.nid !== cur.nid)) {
playEpisode._fallback = true;
try { await playEpisode(currentFavId, latest.sid, latest.nid); }
finally { playEpisode._fallback = false; }
}
}
});
// โโโ ์์ฒญ ์ง๋ ์๋ ์ ์ฅ โโโ
// src ๊ต์ฒด ํ ์ ์์ ๋ฐ์ดํฐ๊ฐ ๋์ฐฉํ๋ฉด ์คํต ์๋ ์ฒ๋ฆฌ ์ฌ๊ฐ
$('#player').addEventListener('loadeddata', () => { playEpisode._skipsLoading = false; });
$('#player').addEventListener('emptied', () => { playEpisode._skipsLoading = true; });
$('#player').addEventListener('timeupdate', () => {
const v = $('#player');
if (!v.duration || isNaN(v.duration)) return;
// src ๊ต์ฒด ์งํ ์์กด timeupdate์์ ์๋ฉ ์๋ ํธ๋ฆฌ๊ฑฐ๊ฐ ์ฌ๋ฐ์ฌ๋๋ ์ฌ๊ณ ์ฐจ๋จ
if (playEpisode._skipsLoading) return;
// edFromEnd ์๋ ๋ชจ๋: ์์ ๋ฉํ๋ฐ์ดํฐ ๋์ฐฉ ํ(_currentSkips.ed ๋ฏธ์ค์ ์ํ) 1ํ ๋น๋
if (currentFavId && !_currentSkips?.ed) {
const fav = favs.find(f => f.id === currentFavId && (f.source || 'tvchak') === (currentFavSource || 'tvchak'));
if (fav?.skip?.edFromEnd) rebuildCurrentSkips(fav);
}
// ์คํต ์๋ ์ฒ๋ฆฌ:
// - ์คํ๋: ๊ตฌ๊ฐ ์ง์
์ฆ์ ์๋ ์ ํ (ํ์ฐจ๋น 1ํ). ์ฌ์ฉ์๊ฐ ๋๋๊ทธ๋ก ๋ค์ ๋ค์ด๊ฐ๋ ์ฌ์คํ ์ ํจ.
// - ์๋ฉ: ๋ค์ ํ ์์ผ๋ฉด 5์ด ์นด์ดํธ๋ค์ด ํ ์๋ ๋ค์ ํ (์ด๋ฏธ ํ์ ์ค์ด๋ฉด ์ฌํธ๋ฆฌ๊ฑฐ X). ๋ค์ ํ ์์ผ๋ฉด ๋ฒํผ ํ์.
const skipBtn = $('#btnSkip');
const cur = v.currentTime;
let skipLabel = null, jumpTo = null, action = 'seek';
if (_currentSkips?.op && cur >= _currentSkips.op.start && cur < _currentSkips.op.end - 1) {
// ์คํ๋: ํ์ฐจ๋น 1๋ฒ๋ง ์๋ ์คํต (์ด์ค ์คํ ๋ฐฉ์ง)
if (!playEpisode._opAutoSkipped) {
playEpisode._opAutoSkipped = true;
try { v.currentTime = _currentSkips.op.end; } catch {}
if (typeof showMediaToast === 'function') showMediaToast('์คํ๋ ์คํต โญ', 1200);
} else {
// ์ด๋ฏธ ์๋ ์ฒ๋ฆฌ๋๋๋ฐ๋ ์ฌ์ฉ์๊ฐ ๋ค์ ๊ทธ ๊ตฌ๊ฐ์ ์๋ค = ์ฌ์ฉ์ ์๋. ์๋ ๋ฒํผ๋ง ํ์
skipLabel = '์คํ๋ ์คํต โญ'; jumpTo = _currentSkips.op.end;
}
} else if (_currentSkips?.ed) {
const edEnd = isFinite(_currentSkips.ed.end) ? _currentSkips.ed.end : v.duration;
if (cur >= _currentSkips.ed.start && cur < edEnd - 1) {
// ๋ค์ ํ = ๋ ์ต์ (์ฌ์ดํธ nid๋ 1์ด ์ต์ , ํฐ nid๊ฐ ์๋ ). sortedAsc๋ nid asc ์ ๋ ฌ์ด๋ผ idx-1์ด ๋ ์ต์ .
const sortedAsc = [...currentEpList].sort((a, b) => a.sid - b.sid || a.nid - b.nid);
const idx = sortedAsc.findIndex(e => e.sid === currentEpList[currentEpIdx]?.sid && e.nid === currentEpList[currentEpIdx]?.nid);
const hasNext = idx > 0;
if (hasNext) {
// ์๋ฉ: ๋ค์ ํ๋ก 5์ด ์นด์ดํธ๋ค์ด ์๋ ์์ (ํ์ฐจ๋น 1ํ)
if (!playEpisode._edAutoTriggered) {
playEpisode._edAutoTriggered = true;
const nextEp = sortedAsc[idx - 1];
startNextCountdown(nextEp);
}
// ์นด์ดํธ๋ค์ด ๋์๋ ์ํ์์๋ btnSkip ๋ฐ๋ก ์ ๋์ (UI ์ค๋ณต ๋ฐฉ์ง)
} else {
// ๋ค์ ํ ์์ผ๋ฉด ์ฌ์ฉ์๊ฐ ์ง์ ํด๋ฆญ (์์ ๋์ผ๋ก ์ ํ๋ง)
skipLabel = '์๋ฉ ์คํต โญ'; jumpTo = edEnd;
}
}
}
if (skipBtn) {
if (skipLabel) {
const stamp = action + '|' + (jumpTo || '');
if (skipBtn.dataset.stamp !== stamp) {
skipBtn.textContent = skipLabel;
skipBtn.dataset.stamp = stamp;
skipBtn.dataset.action = action;
skipBtn.dataset.jump = jumpTo || '';
}
skipBtn.hidden = false;
skipBtn.classList.add('show');
} else {
skipBtn.classList.remove('show');
}
}
if (!currentFavId || currentEpIdx < 0) return;
// throttle: 10์ด (์ด์ด๋ณด๊ธฐ ์ ํ๋ vs NAS ํธ์ ๋ถํ ๊ท ํ).
// - 5์ด๋ autossh tunnel polluting โ SOCKS5 stall ์ฌ๋ฐ ์ํ.
// - 30์ด๋ ๋ง์ง๋ง ๋ณธ ์์ ์ด ์ต๋ 30์ด ์ ์ผ๋ก ์ ์ฅ โ ๋ณต์ ๋ฐฑ์คํ์ ๊ณฑํด์ ธ ์ด์ด๋ณด๊ธฐ๊ฐ ํ์ฐธ ๋ค๋ก ๊ฐ.
// - 10์ด + pause/hidden/beforeunload ์ฆ์ flush ์กฐํฉ์ผ๋ก ์์ชฝ ๊ท ํ.
const now = Date.now();
if ((playEpisode._lastSave || 0) + 10000 > now) return;
saveProgressNow();
});
// pause/ํญ ์ดํ/ํ์ด์ง ์ข
๋ฃ ์ ์ฆ์ ์ ์ฅ (throttle ๋ฌด์).
// timeupdate ๋ง์ง๋ง ๋ฐํ ์ดํ ~10์ด ์์ค์ ๋ฐฉ์ง.
function saveProgressNow() {
const v = $('#player');
if (!v || !v.duration || isNaN(v.duration)) return;
if (!currentFavId || currentEpIdx < 0) return;
const fav = favs.find(f => f.id === currentFavId);
if (!fav) return;
const ep = currentEpList[currentEpIdx];
if (!ep) return;
const label = ep.label || `${ep.nid}ํ`;
playEpisode._lastSave = Date.now();
fav.progress = fav.progress || {};
fav.progress[label] = fav.progress[label] || {};
fav.progress[label].time = v.currentTime;
if (isFinite(v.duration) && v.duration > 0) fav.progress[label].duration = v.duration;
if (!fav.progress[label].finished && v.duration - v.currentTime < 180) {
fav.progress[label].finished = true;
fav.lastFinishedLabel = label;
fav.lastSeenLabel = label;
if (fav.knownCount != null) fav.lastSeenCount = fav.knownCount;
markCaughtUpIfNeeded(fav);
renderFavs();
renderEpisodes();
}
saveFavs();
}
// ์ค์ ์ฌ์ ์์ โ clickedAt ๊ฐฑ์ . ๋ค๋ฅธ ๋๋ฐ์ด์ค๊ฐ ์ฐ์ ์ clickedAt์ด
// pull๋ก ๋ด๋ ค์์ "10์๊ฐ ์ "์ฒ๋ผ ๋ณด์ด๋ ๋ฌธ์ ๋ฐฉ์ง. ํ ๋ฒ ์ฐ์ผ๋ฉด ๊ทธ ์ธ์
๋์ ์ฌ๋ฐํ ๋ฌด์.
$('#player').addEventListener('play', () => {
if (!currentFavId) return;
if (playEpisode._clickedAtBumpedForCurrent) return;
const fav = favs.find(f => f.id === currentFavId);
if (!fav) return;
fav.clickedAt = Date.now();
playEpisode._clickedAtBumpedForCurrent = true;
saveFavs();
renderFavs();
});
$('#player').addEventListener('pause', () => { saveProgressNow(); });
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'hidden') {
saveProgressNow();
// ๋ฐฑ๊ทธ๋ผ์ด๋ ์ง์
์ ์ฌ์ ์ค์ธ ์์์ PIP๋ก (Chrome/TWA. autopictureinpicture ์์ฑ ๋ณด๊ฐ).
const v = $('#player');
if (v && !v.paused && !v.ended && v.readyState >= 2 && document.pictureInPictureEnabled && !document.pictureInPictureElement) {
v.requestPictureInPicture().catch(() => { /* ๊ถํยท์ฌ์ฉ์ ์ ์ค์ฒ ์์ผ๋ฉด ๋ฌด์ */ });
}
}
});
window.addEventListener('beforeunload', () => { saveProgressNow(); });
window.addEventListener('pagehide', () => { saveProgressNow(); });
$('#player').addEventListener('ended', () => {
if (!currentFavId || currentEpIdx < 0 || !currentEpList.length) return;
// ๋น์ ์ ์ข
๋ฃ(๋คํธ์ํฌ ๋๊น์ผ๋ก video๊ฐ ended ๋ฐํํ๋ ์ผ์ด์ค) ๊ฐ๋:
// - duration์ด ์ ํจํ์ง ์๊ฑฐ๋
// - ๋๊น์ง ๊ฐ์ง ์๊ณ ended๊ฐ ๋ฐํํ ๊ฒฝ์ฐ (2์ด ์ด์ ๋จ์๋๋ฐ ended)
// - ๋๋ navigator.onLine === false
// ์ธ ๊ฒฝ์ฐ ๋ค์ ํ ์๋ ์นด์ดํธ๋ค์ด์ ์์ํ์ง ์์. stall ๋ณต๊ตฌ ๋ก์ง์ ๋งก๊น.
const vEl = document.getElementById('player');
const dur = vEl?.duration;
if (!isFinite(dur) || dur <= 0) return;
if (vEl && (dur - vEl.currentTime) > 2) return;
if (typeof navigator !== 'undefined' && navigator.onLine === false) return;
const fav = currentFavSource
? favs.find(f => f.id === currentFavId && (f.source || 'tvchak') === currentFavSource)
: favs.find(f => f.id === currentFavId);
const ep = currentEpList[currentEpIdx];
if (!fav || !ep) return;
const label = ep.label || `${ep.nid}ํ`;
fav.progress = fav.progress || {};
fav.progress[label] = { time: 0, finished: true };
fav.lastFinishedLabel = label;
fav.lastSeenLabel = label;
if (fav.knownCount != null) fav.lastSeenCount = fav.knownCount;
markCaughtUpIfNeeded(fav);
saveFavs();
renderFavs();
renderEpisodes();
// ๋ค์ ํ = ๋ ์ต์ (nid ๋ ์์ ๊ฒ)
const sortedAsc = [...currentEpList].sort((a, b) => a.sid - b.sid || a.nid - b.nid);
const idx = sortedAsc.findIndex(e => e.sid === ep.sid && e.nid === ep.nid);
if (idx > 0) {
const next = sortedAsc[idx - 1];
// C5: 5์ด ์นด์ดํธ๋ค์ด ํ ์๋์ฌ์ (์ฌ์ฉ์๊ฐ ์ทจ์/์ฆ์ ์์ฒญ ๊ฐ๋ฅ)
startNextCountdown(next);
}
});
// C5: ๋ค์ ํ ์นด์ดํธ๋ค์ด
let _ncTimer = null;
function cancelNextCountdown() {
if (_ncTimer) { clearInterval(_ncTimer); _ncTimer = null; }
const el = document.getElementById('nextCountdown');
if (el) el.classList.remove('show');
}
function startNextCountdown(nextEp) {
cancelNextCountdown();
_ncPaused = false;
const el = document.getElementById('nextCountdown');
const secEl = document.getElementById('ncSec');
const barEl = document.getElementById('ncBar');
const titleEl = document.getElementById('ncTitle');
if (!el || !nextEp) return;
let secLeft = 5;
const label = nextEp.label || `${nextEp.nid}ํ`;
if (titleEl) titleEl.textContent = label;
if (secEl) secEl.textContent = secLeft;
if (barEl) { barEl.style.width = '100%'; }
el.classList.add('show');
requestAnimationFrame(() => { if (barEl) barEl.style.width = '0%'; });
_ncTimer = setInterval(() => {
if (_ncPaused) return;
secLeft--;
if (secEl) secEl.textContent = Math.max(0, secLeft);
if (secLeft <= 0) {
cancelNextCountdown();
playEpisode(currentFavId, nextEp.sid, nextEp.nid, { userInitiated: true }).then(() => {
$('#player').play().catch(() => {});
});
}
}, 1000);
}
// โโโ ์ด๋ฒคํธ ๋ฐ์ธ๋ฉ โโโ
$('#btnAdd')?.addEventListener('click', openAddModal);
$('#btnAddDt')?.addEventListener('click', openAddModal);
$('#addCancel').addEventListener('click', closeAddModal);
$('#addOk').addEventListener('click', async () => {
const v = $('#addUrl').value;
if (!v.trim()) return;
closeAddModal();
await addFav(v);
});
$('#addUrl').addEventListener('keydown', e => { if (e.key === 'Enter') $('#addOk').click(); });
$('#addModal').addEventListener('click', e => { if (e.target.id === 'addModal') closeAddModal(); });
async function refreshAll() {
for (const f of favs) {
try {
const src = f.source || 'tvchak';
const titleQ = f.title ? `&title=${encodeURIComponent(f.title)}` : '';
const ep = await api(`/api/episodes?id=${f.id}&nocache=1&source=${src}${titleQ}`);
if (ep.error || !ep.episodes) continue;
if (!f.title) f.title = ep.title;
f.knownCount = ep.count;
// ์ฌ์ดํธ ์ต์ ํ์ฐจ ๋ผ๋ฒจ (NEW ํ์ ์ฉ)
const latest = ep.episodes.find(e => e.sid === 1 && e.nid === 1) || ep.episodes[0];
f.latestLabel = latest?.label || null;
// ์ ํ์ฐจ ์ฌ๋ผ์ค๋ฉด์ nid๊ฐ ๋ฐ๋ฆฐ ๊ฒฝ์ฐ, ์ฌ์ฉ์๊ฐ ๋ณธ ํ์ฐจ(lastLabel)์ nid ์ฌ๋ฐฐ์น
if (f.lastLabel) {
const m = ep.episodes.find(e => e.label === f.lastLabel);
if (m && (m.sid !== f.lastSid || m.nid !== f.lastNid)) {
f.lastSid = m.sid; f.lastNid = m.nid;
}
}
// ์ฒ์ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ง๋ค๊ณ ํ ๋ฒ๋ ๋ณธ ์ ์์ผ๋ฉด ๊ทธ ์์ ์ต์ ํ ๊ธฐ์ค์ผ๋ก (NEW ์ ๋จ๋๋ก)
if (f.lastSeenLabel == null) {
f.lastSeenLabel = f.latestLabel;
f.lastSeenCount = ep.count;
}
markCaughtUpIfNeeded(f);
} catch {}
}
saveFavs(); renderFavs();
// ํ์ฌ ๋ณด๊ณ ์๋ ์ฆ๊ฒจ์ฐพ๊ธฐ๋ ํ์ฐจ ๋ชฉ๋ก๋ ๋ค์ ๋ก๋
if (currentFavId) {
const fav = currentFavSource
? favs.find(f => f.id === currentFavId && (f.source || 'tvchak') === currentFavSource)
: favs.find(f => f.id === currentFavId);
if (fav) {
const src = fav.source || 'tvchak';
const titleQ = fav.title ? `&title=${encodeURIComponent(fav.title)}` : '';
const ep = await api(`/api/episodes?id=${fav.id}&nocache=1&source=${src}${titleQ}`);
if (!ep.error) {
currentEpList = ep.episodes || [];
if (fav.lastSid != null) {
currentEpIdx = currentEpList.findIndex(e => e.sid === fav.lastSid && e.nid === fav.lastNid);
}
renderEpisodes();
}
}
}
}
// ๋ณด๊ดํจ NEW ์๋ ๊ฐ์ง โ ๋ถํ
+ ์ฃผ๊ธฐ ํด๋ง + ํญ visibility ๋ณต๊ท ์ ํธ์ถ.
// /api/latest-labels๋ ์บ์๋ episodes์์ ์ต์ ๋ผ๋ฒจ๋ง ๋ฝ์ ์ฆ์ ๋ฐํ.
// ์บ์ miss์ธ ํญ๋ชฉ์ ์๋ฒ๊ฐ ๋ฐฑ๊ทธ๋ผ์ด๋๋ก fetchEpisodes ํธ๋ฆฌ๊ฑฐ โ ๋ค์ ํธ์ถ ๋ hit.
let _lastLatestLabelsAt = 0;
const LATEST_LABELS_MIN_INTERVAL = 2 * 60 * 1000; // visibility ํธ๋ฆฌ๊ฑฐ ์ต์ 2๋ถ ๊ฐ๊ฒฉ (ํญ ์ ํ ํญ์ฃผ ๋ฐฉ์ง)
const LATEST_LABELS_POLL_INTERVAL = 5 * 60 * 1000; // ์ฃผ๊ธฐ ํด๋ง 5๋ถ
// pending ์ฌํธ์ถ ์ง์ ๋ฐฑ์คํ โ 20โ40โ80โ160์ด, ์ต๋ 3ํ.
// Why: ํ saturated๋ก ์๋ฒ fetch๊ฐ ๊ณ์ ์คํจํ๋ฉด ๊ฐ์ 20์ด ๊ฐ๊ฒฉ์ผ๋ก ๋ฌดํ ์ฌํธ์ถ๋์ด
// ๋ฐฑ๊ทธ๋ผ์ด๋ task๊ฐ ๋์ ํญ์ฃผ(2026-05-25 ์ฌ๊ณ ). ์ง์ ๋ฐฑ์คํ + ์ต๋ ํ์๋ก ์ฐจ๋จ.
const LATEST_LABELS_RETRY_MAX = 3;
const LATEST_LABELS_RETRY_BASE_MS = 20000;
async function refreshLatestLabels(retryCount = 0) {
if (!favs.length) return;
const ids = favs.map(f => f.id).join(',');
const sources = favs.map(f => f.source || 'tvchak').join(',');
try {
const r = await api(`/api/latest-labels?ids=${ids}&sources=${sources}`, { timeout: 15000 });
if (!r || !r.items) return;
let changed = false;
for (const it of r.items) {
const f = favs.find(x => x.id === it.id && (x.source || 'tvchak') === it.source);
if (!f) continue;
if (it.latestLabel && f.latestLabel !== it.latestLabel) {
f.latestLabel = it.latestLabel;
changed = true;
}
if (it.count && f.knownCount !== it.count) {
f.knownCount = it.count;
changed = true;
}
}
if (changed) { saveFavs(); renderFavs(); }
_lastLatestLabelsAt = Date.now();
// pending์ด ์์ผ๋ฉด ์๋ฒ๊ฐ ๋ฐฑ๊ทธ๋ผ์ด๋ ๊ฐฑ์ ์ค โ ์ง์ ๋ฐฑ์คํ๋ก ์ฌํธ์ถ.
// ๋ค์ ์ฃผ๊ธฐ ํด๋ง(5๋ถ)์ด ์์ผ๋ฏ๋ก ๋ฌดํ ์ฌ์๋๋ ๋ถํ์.
if (r.pending && r.pending.length && retryCount < LATEST_LABELS_RETRY_MAX) {
const delay = LATEST_LABELS_RETRY_BASE_MS * Math.pow(2, retryCount);
setTimeout(() => refreshLatestLabels(retryCount + 1).catch(() => {}), delay);
}
} catch (e) {
console.warn('refreshLatestLabels:', e.message);
}
}
// ๋ค๋ฅธ ๋๋ฐ์ด์ค์ ๋ณ๊ฒฝ(clickedAt, lastFavId ๋ฑ)์ ๋ฐ์ ์ ๋ ฌยทํ์ฑํ์ ๋๊ธฐํ.
// pull ํ lastFavId๊ฐ ๋ฐ๋์์ผ๋ฉด ํ์ฑ ์๋ฆฌ์ฆ๋ก ์๋ ์ ํ(์์ฒญ ํ๋ฉด์ ์ ์งํ์ง ์๊ณ ๋ชฉ๋ก ๊ฐ์กฐ๋ง).
async function syncFavsFromOtherDevices() {
const prevLast = lastFavId;
await pullFavsFromServer();
renderFavs();
// ๋ค๋ฅธ ๋๋ฐ์ด์ค๊ฐ ํ์ฑ ์๋ฆฌ์ฆ๋ฅผ ๋ฐ๊ฟจ์ ๋ โ ํ์ฌ ์์ฒญ ์ค์ธ ์๋ฆฌ์ฆ๊ฐ ๋ฐ๋ก ์์ ๋๋ง ์๋ ๋ฐ๋ผ๊ฐ
// (์ด๋ฏธ ๋ค๋ฅธ ๊ฑธ ๋ณด๊ณ ์๋๋ฐ ๊ฐ์ ๋ก ํ๋ฉด ๊ฐ์์น์ฐ๋ ๊ฒ ๋ฐฉ์ง)
if (lastFavId && lastFavId !== prevLast && !currentFavId && favs.find(f => f.id == lastFavId)) {
selectFav(+lastFavId, { silent: true }).catch(() => {});
}
}
// 15๋ถ๋ง๋ค ์ฃผ๊ธฐ ํด๋ง โ ํ์ด์ง๊ฐ visible์ผ ๋๋ง (hidden ํญ์์ ๋ถํ์ํ ํธ์ถ ์ ์ฝ)
setInterval(() => {
if (document.visibilityState !== 'visible') return;
refreshLatestLabels().catch(() => {});
syncFavsFromOtherDevices().catch(() => {});
}, LATEST_LABELS_POLL_INTERVAL);
// ํญ ์ ํยท์ฑ ๋ฐฑ๊ทธ๋ผ์ด๋ ๋ณต๊ท ์ ์ฆ์ ๊ฒ์ฌ (๋จ ๋ง์ง๋ง ํธ์ถ ํ 5๋ถ ์ด์ ์ง๋ฌ์ ๋๋ง)
document.addEventListener('visibilitychange', () => {
if (document.visibilityState !== 'visible') return;
if (Date.now() - _lastLatestLabelsAt < LATEST_LABELS_MIN_INTERVAL) return;
refreshLatestLabels().catch(() => {});
syncFavsFromOtherDevices().catch(() => {});
});
// ๋ก๊ณ ("OTT โ PLAYER") ํด๋ฆญ โ ํ์ด์ง ์๋ก๊ณ ์นจ
document.querySelectorAll('.brand').forEach(el => {
el.addEventListener('click', () => location.reload());
});
// ์คํ๋/์๋ฉ ์คํต ๋ฒํผ (action='seek'๋ฉด ์ ํ, action='next'๋ฉด ๋ค์ ํ)
$('#btnSkip')?.addEventListener('click', (e) => {
e.stopPropagation();
const action = $('#btnSkip').dataset.action;
if (action === 'next') {
$('#btnSkip').classList.remove('show');
gotoEpisode(1);
return;
}
const v = $('#player');
const jumpTo = parseFloat($('#btnSkip').dataset.jump);
if (v && isFinite(jumpTo)) {
v.currentTime = jumpTo;
$('#btnSkip').classList.remove('show');
}
});
// ์ด์ ํ / ๋ค์ ํ โ currentEpList ๊ธฐ์ค (nid ์์์๋ก ์ต์ , ํฐ ๊ฒ ์ค๋)
// "๋ค์ ํ"๋ ๋ ์ต์ ํ์ฐจ = nid ๋ ์์ ํ์ฐจ
function gotoEpisode(direction) {
if (!currentFavId || !currentEpList.length) return;
const sortedAsc = [...currentEpList].sort((a, b) => a.sid - b.sid || a.nid - b.nid);
const idx = sortedAsc.findIndex((e, i) => i === currentEpIdx) >= 0
? sortedAsc.findIndex(e => e.sid === currentEpList[currentEpIdx]?.sid && e.nid === currentEpList[currentEpIdx]?.nid)
: -1;
if (idx < 0) return;
// direction=1: ๋ค์ ํ (์ต์ ๋ฐฉํฅ, idx-1), -1: ์ด์ ํ (์ค๋๋ ๋ฐฉํฅ, idx+1)
const target = sortedAsc[idx - direction];
if (!target) return;
playEpisode(currentFavId, target.sid, target.nid, { userInitiated: true })
.then(() => $('#player').play().catch(() => {}));
}
$('#filter')?.addEventListener('input', renderFavs);
$('#filterMob')?.addEventListener('input', renderFavs);
// ๋ชจ๋ฐ์ผ ๊ฒ์
$('#btnSearchToggle').addEventListener('click', () => {
if ($('#searchBar').style.display === 'none') openMobileSearch();
else closeMobileSearch();
});
$('#searchClose').addEventListener('click', closeMobileSearch);
$('#btnSearchMob').addEventListener('click', () => doSearch($('#searchInputMob').value, 'searchResultsMob'));
$('#searchInputMob').addEventListener('keydown', e => {
if (e.key === 'Enter') doSearch($('#searchInputMob').value, 'searchResultsMob');
});
// ๋ฐ์คํฌํ ๊ฒ์
$('#btnSearch')?.addEventListener('click', () => doSearch($('#searchInput').value, 'searchResults'));
$('#searchCloseDt')?.addEventListener('click', () => {
$('#searchResultsWrap').style.display = 'none';
$('#searchInput').value = '';
$('#searchResults').innerHTML = '';
});
$('#searchInput')?.addEventListener('keydown', e => {
if (e.key === 'Enter') doSearch($('#searchInput').value, 'searchResults');
});
// โโโ ํค๋
ธ๋ผ์ด์ธ ๋ญํน โโโ
let currentRankingPeriod = 'daily';
const rankingCache = {};
async function loadRanking(period) {
currentRankingPeriod = period;
renderRanking({ loading: true });
try {
if (rankingCache[period]) {
renderRanking({ data: rankingCache[period] });
return;
}
// pending ์๋ต โ 5์ด ๊ฐ๊ฒฉ์ผ๋ก ์ต๋ 6ํ ์ฌ์๋ (์๋ฒ๊ฐ fetch ์ค)
let r = await api(`/api/ranking?period=${period}`, { timeout: 90000 });
for (let i = 0; i < 6 && (!r.items || !r.items.length) && r.pending; i++) {
renderRanking({ loading: true, message: '๋ญํน ๊ฐ์ ธ์ค๋ ์คโฆ' });
await new Promise(rs => setTimeout(rs, 5000));
r = await api(`/api/ranking?period=${period}`, { timeout: 90000 });
}
if (r.error) { renderRanking({ error: r.error }); return; }
if (!r.items || !r.items.length) { renderRanking({ error: '๋ญํน ๋ฐ์ดํฐ ์์' }); return; }
rankingCache[period] = r;
renderRanking({ data: r });
} catch (e) {
renderRanking({ error: e.message });
}
}
function renderRankingDetail(host, d, title) {
const meta = [];
if (d.genre) meta.push(`<span>์ฅ๋ฅด<b>${esc(d.genre)}</b></span>`);
if (d.airDate) meta.push(`<span>๋ฐฉ์<b>${esc(d.airDate)}</b></span>`);
if (d.episodes) meta.push(`<span>ํ์ฐจ<b>${esc(d.episodes)}</b></span>`);
if (d.rating) meta.push(`<span>๋ฑ๊ธ<b>${esc(d.rating)}</b></span>`);
if (d.country) meta.push(`<span>๊ตญ๊ฐ<b>${esc(d.country)}</b></span>`);
if (d.score) meta.push(`<span>ํ์ <b style="color:#6ee7a8">${esc(d.score)}</b></span>`);
host.innerHTML = `
${d.synopsis ? `<div class="syn">${esc(d.synopsis)}</div>` : ''}
${meta.length ? `<div class="meta-row">${meta.join('')}</div>` : ''}
${(d.cast && d.cast.length) ? `<div class="cast"><b>์ถ์ฐ:</b> ${d.cast.map(esc).join(', ')}</div>` : ''}
${d.ott ? `<div class="cast"><b>OTT:</b> ${esc(d.ott)}</div>` : ''}
<div class="trailer-wrap" data-trailer-title="${esc(title || '')}">
<div class="trailer-loading">์๊ณ ํธ ๋ถ๋ฌ์ค๋ ์คโฆ</div>
</div>
`;
// ์๊ณ ํธ ๋น๋๊ธฐ ๋ก๋
loadTrailer(host.querySelector('.trailer-wrap'), title);
}
async function loadTrailer(host, title) {
if (!host || !title) return;
try {
const r = await api(`/api/yt-trailer?title=${encodeURIComponent(title)}`);
if (r.error || !r.embed) { host.innerHTML = ''; return; }
host.innerHTML = `
<div class="trailer-label">์๊ณ ํธ</div>
<div class="trailer-frame">
<iframe src="${esc(r.embed)}" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen referrerpolicy="strict-origin-when-cross-origin"></iframe>
</div>
`;
} catch { host.innerHTML = ''; }
}
function renderRanking(state) {
const hosts = [$('#rankingBoxDt'), $('#rankingBoxMob')].filter(Boolean);
const tabs = ['daily', 'weekly', 'monthly'];
const tabLabel = { daily: '์ผ๊ฐ', weekly: '์ฃผ๊ฐ', monthly: '์๊ฐ' };
let body = '';
if (state.loading) body = `<div style="padding:10px;color:var(--muted);font-size:12px">๋ถ๋ฌ์ค๋ ์คโฆ</div>`;
else if (state.error) body = `<div style="padding:10px;color:#ff7b7b;font-size:12px">${esc(state.error)}</div>`;
else if (state.data) {
body = '<div class="ranking-list">' + state.data.items.map((it, i) => {
const kinoId = (it.href || '').match(/\/title\/(\d+)/)?.[1];
return `
<div class="rk-item" data-search="${esc(it.title)}" data-kid="${kinoId || ''}">
<div class="rk-rank">${i + 1}</div>
${it.poster
? `<img class="rk-poster" src="${esc(viaProxy(it.poster))}" loading="lazy" referrerpolicy="no-referrer" />`
: `<div class="rk-poster placeholder">?</div>`}
<div class="rk-title">
<b>${esc(it.title)}</b>
<div class="rk-meta">${esc(it.category || '')}${it.year ? ' ยท ' + it.year : ''}</div>
</div>
${kinoId ? `<button class="rk-more" data-more="${kinoId}" title="์์ธํ">์์ธํ</button>` : ''}
</div>
${kinoId ? `<div class="rk-detail" data-detail="${kinoId}"></div>` : ''}
`;}).join('') + '</div>';
}
for (const host of hosts) {
host.innerHTML = `
<div class="ranking-head">
<h3>OTT TOP 10</h3>
<div class="ranking-tabs">
${tabs.map(t => `<button data-period="${t}" class="${currentRankingPeriod === t ? 'active' : ''}">${tabLabel[t]}</button>`).join('')}
</div>
</div>
${body}
`;
// ํญ ์ด๋ฒคํธ
host.querySelectorAll('.ranking-tabs button').forEach(b => {
b.addEventListener('click', () => loadRanking(b.dataset.period));
});
// ํญ๋ชฉ ํด๋ฆญ โ ์๋ ๊ฒ์ (G-15: 1ํญ ๊ฒ์ + ํ ์คํธ ํผ๋๋ฐฑ). ๊ฒ์ ๊ฒฐ๊ณผ๋ก ์๋ ์คํฌ๋กค
host.querySelectorAll('.rk-item').forEach(it => {
it.addEventListener('click', (e) => {
if (e.target.closest('.rk-more')) return; // ์์ธํ ๋ฒํผ์ ๋ณ๋ ๋์
const title = it.dataset.search;
if (isMobile()) {
openMobileSearch();
$('#searchInputMob').value = title;
doSearch(title, 'searchResultsMob');
// ๋ชจ๋ฐ์ผ์ ๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ๋ณด๊ดํจ ์์ชฝ์ด๋ผ ๊ทธ์ชฝ์ผ๋ก ์คํฌ๋กค
setTimeout(() => {
$('#searchResultsMob')?.scrollIntoView({ behavior: 'smooth', block: 'start' });
}, 50);
} else {
$('#searchInput').value = title;
doSearch(title, 'searchResults');
// ๋ฐ์คํฌํ: ์ฌ์ด๋ ํจ๋ #searchResultsWrap์ด ํ์๋ ํ ๊ทธ๋ฆฌ๋ก ์คํฌ๋กค
setTimeout(() => {
$('#searchResultsWrap')?.scrollIntoView({ behavior: 'smooth', block: 'start' });
}, 50);
}
showMediaToast?.(`๊ฒ์: ${title}`);
});
});
// "์์ธํ" ๋ฒํผ โ ์์ธ ํผ์นจ
host.querySelectorAll('.rk-more').forEach(btn => {
btn.addEventListener('click', async (e) => {
e.stopPropagation();
const kid = btn.dataset.more;
const detail = host.querySelector(`.rk-detail[data-detail="${kid}"]`);
if (!detail) return;
const isOpen = detail.classList.contains('open');
// ๋ค๋ฅธ ํผ์น ๊ฑฐ ๋ค ๋ซ๊ธฐ + ๊ทธ ๋ฒํผ ํ
์คํธ๋ "์์ธํ"๋ก ๋๋๋ฆฌ๊ธฐ (ํ ๋ฒ์ ํ๋๋ง)
host.querySelectorAll('.rk-detail.open').forEach(d => {
d.classList.remove('open');
const otherKid = d.dataset.detail;
const otherBtn = host.querySelector(`.rk-more[data-more="${otherKid}"]`);
if (otherBtn) otherBtn.textContent = '์์ธํ';
});
if (isOpen) { btn.textContent = '์์ธํ'; return; }
btn.textContent = '์ ๊ธฐ';
detail.classList.add('open');
if (!detail.dataset.loaded) {
detail.innerHTML = '<div class="loading">๋ถ๋ฌ์ค๋ ์คโฆ</div>';
try {
const r = await api(`/api/ranking-detail?id=${kid}`);
if (r.error) throw new Error(r.error);
const card = btn.closest('.rk-item');
renderRankingDetail(detail, r, card?.dataset.search || '');
detail.dataset.loaded = '1';
} catch (err) {
detail.innerHTML = `<div class="loading">๋ก๋ ์คํจ: ${esc(err.message)}</div>`;
}
}
});
});
}
}
// โโโ ๋ถํธ โโโ
// โโโ ์ผ์์ ์ง ์ค๋ฒ๋ ์ด (๊ฐ์ด๋ฐ ํฐ ์ฌ์ ๋ฒํผ) โโโ
(function setupPauseOverlay() {
const v = $('#player');
const overlay = $('#pauseOverlay');
if (!v || !overlay) return;
function update() {
// ์์ ๋ก๋ ์ ๋๊ฑฐ๋(src ์์/empty ๋ฉ์์ง ํ์ ์ค) ended ์ํ๋ ํ์ ์ ํจ
if (!v.src || v.ended) { overlay.hidden = true; return; }
overlay.hidden = !v.paused;
}
v.addEventListener('play', update);
v.addEventListener('pause', update);
v.addEventListener('ended', update);
v.addEventListener('loadedmetadata', update);
v.addEventListener('emptied', () => { overlay.hidden = true; });
// ์ค๋ฒ๋ ์ด ํด๋ฆญ โ ์ฌ์
overlay.addEventListener('click', () => v.play().catch(() => {}));
})();
// โโโ ์ข์ธก ํจ๋ ํ ๊ธ/๋ฆฌ์ฌ์ด์ฆ (๋ฐ์คํฌํ) โโโ
function toggleSidePanel() {
// ํ ๊ธ ์ ๋๋ฉ์ด์
๋ง transition ์ผ๊ณ , ๋๋๋ฉด ๋๊ธฐ (๋๋๊ทธ ์ ๋๊น ๋ฐฉ์ง)
document.body.classList.add('with-transition');
const next = !document.body.classList.contains('left-collapsed');
document.body.classList.toggle('left-collapsed', next);
localStorage.setItem('tvchak.leftCollapsed', next ? '1' : '0');
setTimeout(() => document.body.classList.remove('with-transition'), 250);
}
(function setupSideToggle() {
const collapsed = localStorage.getItem('tvchak.leftCollapsed') === '1';
if (collapsed) document.body.classList.add('left-collapsed');
// ์ ์ฅ๋ ๋๋น ์ ์ฉ
const savedW = parseInt(localStorage.getItem('tvchak.leftWidth') || '0', 10);
if (savedW >= 200 && savedW <= 600) document.body.style.setProperty('--left-w', savedW + 'px');
$('#btnSideToggle')?.addEventListener('click', toggleSidePanel);
// ๋๋๊ทธ ๋ฆฌ์ฌ์ด์ฆ
const handle = $('#resizeHandle');
if (handle) {
let dragging = false;
handle.addEventListener('mousedown', (e) => {
e.preventDefault();
dragging = true;
handle.classList.add('dragging');
document.body.style.cursor = 'ew-resize';
document.body.style.userSelect = 'none';
});
window.addEventListener('mousemove', (e) => {
if (!dragging) return;
const w = Math.max(200, Math.min(600, e.clientX));
document.body.style.setProperty('--left-w', w + 'px');
});
window.addEventListener('mouseup', () => {
if (!dragging) return;
dragging = false;
handle.classList.remove('dragging');
document.body.style.cursor = '';
document.body.style.userSelect = '';
const w = parseInt(getComputedStyle(document.body).getPropertyValue('--left-w'), 10);
if (w >= 200 && w <= 600) localStorage.setItem('tvchak.leftWidth', String(w));
});
// ๋๋ธํด๋ฆญ โ ๊ธฐ๋ณธ ๋๋น ๋ฆฌ์
handle.addEventListener('dblclick', () => {
document.body.style.setProperty('--left-w', '340px');
localStorage.setItem('tvchak.leftWidth', '340');
});
}
})();
// โโโ ํค๋ณด๋ ๋จ์ถํค โโโ
// ํ๋ฉด ์ ๊ธ (๋ชจ๋ฐ์ผ ํ์คํฌ๋ฆฐ)
(function setupLock() {
const wrap = $('#videoWrap');
const btn = $('#btnLock');
if (!wrap || !btn) return;
// ์ ๊ธด ์๋ฌผ์ (๋ซํ ๊ณ ๋ฆฌ) / ์ด๋ฆฐ ์๋ฌผ์ (๊ณ ๋ฆฌ ๋ถ๋ฆฌ)
const SVG_LOCKED = '<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="11" width="16" height="10" rx="2"></rect><path d="M8 11V8a4 4 0 0 1 8 0v3"></path></svg>';
const SVG_UNLOCKED = '<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="11" width="16" height="10" rx="2"></rect><path d="M8 11V8a4 4 0 0 1 8 0v3M16 5v3"></path></svg>';
function setLocked(on) {
wrap.classList.toggle('locked', on);
btn.innerHTML = on ? SVG_LOCKED : SVG_UNLOCKED;
btn.title = on ? 'ํ๋ฉด ์ ๊ธ ํด์ ' : 'ํ๋ฉด ์ ๊ธ';
}
btn.addEventListener('click', (e) => {
e.stopPropagation();
setLocked(!wrap.classList.contains('locked'));
// ์ ๊ธ ์งํ ์๋ฌผ์ ๊ฐ ์ ์ ํฌ๋ฏธํ๊ฒ ๋ณด์๋ค ์ฌ๋ผ์ง๋๋ก (show-controls 3์ด ์ ์ง)
if (wrap.classList.contains('locked')) pingLockHint();
});
// ํ์คํฌ๋ฆฐ ๋๊ฐ๋ฉด ์๋ ํด์
document.addEventListener('fullscreenchange', () => {
if (!document.fullscreenElement) setLocked(false);
});
document.addEventListener('webkitfullscreenchange', () => {
if (!document.webkitFullscreenElement) setLocked(false);
});
// ์ ๊ธ ์ํ์์ wrap ๋ด ๋ค๋ฅธ ์ด๋ฒคํธ(ํด๋ฆญ/ํฐ์น/๋๋ธํด๋ฆญ/ํ )๋ฅผ ์บก์ฒ ๋จ๊ณ์์ ์ฐจ๋จ
// ๋จ, ํฐ์น ์ ํธ๋ ์ ๊ธ ๋ฒํผ๋ง ์ ๊น ๋
ธ์ถ์ํค๊ธฐ ์ํ ํธ๋ฆฌ๊ฑฐ๋ก๋ ์ฌ์ฉ (3์ด ํ ์๋ ์จ๊น)
let _lockHintTimer = null;
let _lockHintLast = 0;
function pingLockHint() {
const now = Date.now();
// ๋๋ฐ์ด์ค: 300ms ๋ด ์ค๋ณต ํธ์ถ์ ํ์ด๋จธ๋ง ๊ฐฑ์ (๋ฏธ์ธ ํฐ์น ๋ฌดํ ํธ์ถ ์ฌ๊ณ ๋ฐฉ์ง)
if (now - _lockHintLast < 300 && wrap.classList.contains('show-controls')) {
clearTimeout(_lockHintTimer);
_lockHintTimer = setTimeout(() => {
if (wrap.classList.contains('locked')) wrap.classList.remove('show-controls');
}, 3000);
return;
}
_lockHintLast = now;
wrap.classList.add('show-controls');
clearTimeout(_lockHintTimer);
_lockHintTimer = setTimeout(() => {
if (wrap.classList.contains('locked')) wrap.classList.remove('show-controls');
}, 3000);
}
// ๋ค๋ฅธ IIFE์ showControls๊ฐ ์ ๊ธ ์ํ์ผ ๋ ์์ํ ์ ์๋๋ก ๋
ธ์ถ
window.__pingLockHint = pingLockHint;
const blockedTypes = ['click', 'dblclick', 'touchstart', 'touchend', 'touchmove', 'wheel', 'mousedown', 'pointerdown'];
// ์๋ฌผ์ hint ์ฌ๋
ธ์ถ์ ๋ช
์์ ์๋๊ฐ ๋ณด์ด๋ ์ด๋ฒคํธ(touchstart/pointerdown/mousedown/click)์๋ง.
// touchmove/wheel์ ๋ฏธ์ธ ์
๋ ฅ์ด๋ผ ping ํธ์ถ ์ ํจ.
const hintTypes = new Set(['touchstart', 'pointerdown', 'mousedown', 'click']);
for (const type of blockedTypes) {
wrap.addEventListener(type, (e) => {
if (!wrap.classList.contains('locked')) return;
// ์ ๊ธ ๋ฒํผ ์์ฒด๋ ํต๊ณผ
if (e.target.closest('#btnLock')) return;
// ์ ๊ธ ์ค wrap ํฐ์น/ํด๋ฆญ์ ์ฐจ๋จ + ์๋ฌผ์ hint ์ฌ๋
ธ์ถ (๋๋ฐ์ด์ค๋ก ๋ฌดํ ํธ์ถ ๋ฐฉ์ง)
if (hintTypes.has(type)) pingLockHint();
e.stopPropagation();
e.preventDefault?.();
}, true);
}
})();
// F: ํ์คํฌ๋ฆฐ(ํ๋ ๊ฐ๋ฅ) ํ ๊ธ / S: ์ข์ธก ํจ๋ ์ ๊ธฐยทํผ์น๊ธฐ
(function setupShortcuts() {
document.addEventListener('keydown', (e) => {
// ์
๋ ฅ ํ๋์ ํฌ์ปค์ค๋์ด ์์ผ๋ฉด ๋ฌด์
const t = e.target;
if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable)) return;
if (e.ctrlKey || e.metaKey || e.altKey) return;
const k = e.key.toLowerCase();
if (k === 'f') {
e.preventDefault();
$('#btnFsZoom')?.click();
} else if (k === 's') {
e.preventDefault();
toggleSidePanel();
} else if (k === 'd') {
e.preventDefault();
togglePip();
} else if (e.key === '+' || e.key === '=' || e.key === '-' || e.key === '_') {
e.preventDefault();
const isPlus = e.key === '+' || e.key === '=';
if (e.shiftKey) {
// Shift + +/- : ์ฌ์์๋ ์กฐ์
adjustPlaybackRate(isPlus ? 0.25 : -0.25);
} else {
// +/- : ํ์คํฌ๋ฆฐ์ผ ๋๋ง ์์ ํ๋/์ถ์
const vz = window._videoZoom;
if (vz?.isFullscreen()) {
vz.setZoom(vz.getZoom() + (isPlus ? 0.25 : -0.25));
}
}
} else if (e.key === ' ' || k === 'k') {
// ์คํ์ด์ค / K : ์ฌ์ยท์ ์ง
e.preventDefault();
const v = $('#player');
if (v && v.src) {
if (v.paused) v.play().catch(() => {});
else v.pause();
}
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
// โ/โ : ์ฌ์ ์์น ์ด๋ (๊ธฐ๋ณธ 5์ด, Shift+ 10์ด)
const v = $('#player');
if (!v || !v.src || !isFinite(v.duration)) return;
e.preventDefault();
const step = e.shiftKey ? 10 : 5;
const dir = e.key === 'ArrowLeft' ? -1 : 1;
v.currentTime = Math.max(0, Math.min(v.duration, v.currentTime + dir * step));
} else if (e.key === '[' || e.key === ']' || e.key === ';' || e.key === "'") {
// ๋จ์ถํค: [ ์คํ๋ ์์(๊ณ ๊ธ, 0์ด ๊ธฐ๋ณธ) / ] ์คํ๋ ๋(์์=0์ด ์๋) / ; ์๋ฉ(ํ์ฌ ์์น) / ' ์ด๊ธฐํ
const map = { '[': 'opStart', ']': 'opEnd', ';': 'edFromEnd', "'": 'clear' };
e.preventDefault();
applySkipMark(map[e.key]);
} else if (k === 'm') {
// ์์๊ฑฐ ํ ๊ธ
e.preventDefault();
const v = $('#player');
if (v) {
v.muted = !v.muted;
if (typeof showMediaToast === 'function') showMediaToast(v.muted ? '์์๊ฑฐ' : '๐');
}
} else if (k === 'n') {
// ๋ค์ ํ (๋ ์ต์ ํ์ฐจ)
e.preventDefault();
gotoEpisode(1);
} else if (k === 'p') {
// ์ด์ ํ (๋ ์ค๋๋ ํ์ฐจ)
e.preventDefault();
gotoEpisode(-1);
}
});
})();
function adjustPlaybackRate(delta) {
const v = $('#player');
if (!v) return;
const next = Math.max(0.25, Math.min(3, Math.round((v.playbackRate + delta) * 100) / 100));
v.playbackRate = next;
showRateToast(next);
}
function showRateToast(rate) {
showToast(`${rate}x`);
}
function showToast(text) {
let toast = $('#rateToast');
if (!toast) {
toast = document.createElement('div');
toast.id = 'rateToast';
toast.className = 'rate-toast';
document.getElementById('videoWrap').appendChild(toast);
}
toast.textContent = text;
toast.classList.add('show');
clearTimeout(showToast._t);
showToast._t = setTimeout(() => toast.classList.remove('show'), 1500);
}
async function togglePip() {
const v = $('#player');
if (!v || !v.src) return;
try {
if (document.pictureInPictureElement) {
await document.exitPictureInPicture();
} else if (document.pictureInPictureEnabled && !v.disablePictureInPicture) {
await v.requestPictureInPicture();
}
} catch (e) {
console.warn('PiP failed', e);
}
}
// โฎ ๋๋ณด๊ธฐ ๋ฉ๋ด โ ์ฌ์์๋/PIP/๋ค์ด๋ก๋ ํตํฉ
(function setupMoreMenu() {
const btn = document.getElementById('zcMore');
const menu = document.getElementById('moreMenu');
const v = document.getElementById('player');
if (!btn || !menu || !v) return;
function updateActive() {
const rate = v.playbackRate || 1;
for (const b of menu.querySelectorAll('.more-rates button')) {
b.classList.toggle('active', Math.abs(parseFloat(b.dataset.rate) - rate) < 0.001);
}
const dl = document.getElementById('mmDownload');
if (dl) dl.hidden = !window._currentDownload;
}
function openMenu() {
updateActive();
if (typeof updateSkipMenuLabels === 'function') updateSkipMenuLabels();
menu.hidden = false;
}
function closeMenu() { menu.hidden = true; }
btn.addEventListener('click', (e) => {
e.stopPropagation();
if (menu.hidden) openMenu(); else closeMenu();
});
// ๋ฐ๊นฅ ํด๋ฆญ / Esc๋ก ๋ซ๊ธฐ
document.addEventListener('click', (e) => {
if (!menu.hidden && !e.target.closest('#moreMenu, #zcMore')) closeMenu();
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && !menu.hidden) closeMenu();
});
// ์ฌ์์๋ ๋ฒํผ
menu.querySelectorAll('.more-rates button').forEach(b => {
b.addEventListener('click', () => {
const rate = parseFloat(b.dataset.rate);
if (isFinite(rate) && rate > 0) {
try {
v.playbackRate = rate;
// ์๋ฆฌ์ฆ๋ณ ๊ธฐ์ต โ ๊ธฐ์กด lastPlaybackRate ํ๋ ํ์ฉ
const fav = currentFavId ? favs.find(f => f.id === currentFavId) : null;
if (fav) { fav.lastPlaybackRate = rate; saveFavs(); }
updateActive();
if (typeof showMediaToast === 'function') showMediaToast(`์ฌ์ ์๋ ${rate}ร`);
} catch {}
}
});
});
// PIP
document.getElementById('mmPip')?.addEventListener('click', () => { togglePip(); closeMenu(); });
// ์คํต ๋งํน (moreMenu ๋ด๋ถ)
menu.querySelectorAll('.more-skip button[data-skip]').forEach(b => {
b.addEventListener('click', (e) => {
e.stopPropagation();
if (typeof applySkipMark === 'function') applySkipMark(b.dataset.skip);
closeMenu();
});
});
// ๋ค์ด๋ก๋
document.getElementById('mmDownload')?.addEventListener('click', () => {
const d = window._currentDownload;
if (!d) return;
const a = document.createElement('a');
a.href = d.url; a.download = d.name; a.rel = 'noopener';
document.body.appendChild(a); a.click(); a.remove();
closeMenu();
});
// playbackRate ์ธ๋ถ ๋ณ๊ฒฝ ๊ฐ์ง(ํค๋ณด๋ Shift+/- ๋ฑ)๋ ๋ฉ๋ด active ๋๊ธฐํ
v.addEventListener('ratechange', () => { if (!menu.hidden) updateActive(); });
})();
// โโโ A1: ๊ฒ์ ์๋์์ฑ (์ต๊ทผ ๊ฒ์์ด + ๋ณด๊ดํจ ๋ถ๋ถ์ผ์น) โโโ
function setupSearchAutocomplete(inputId, listId, searchFn) {
const inp = document.getElementById(inputId);
const list = document.getElementById(listId);
if (!inp || !list) return;
let focusedIdx = -1;
function render() {
const q = inp.value.trim().toLowerCase();
const recent = loadRecentSearches();
const favHits = q
? favs.filter(f => (f.title || '').toLowerCase().includes(q)).slice(0, 6)
: [];
const recentHits = q
? recent.filter(w => w.toLowerCase().includes(q) && w.toLowerCase() !== q).slice(0, 6)
: recent.slice(0, 8);
const items = [];
for (const f of favHits) items.push({ type: 'fav', value: f.title, sub: '๋ณด๊ดํจ' });
for (const w of recentHits) items.push({ type: 'recent', value: w, sub: '์ต๊ทผ ๊ฒ์' });
if (!items.length) { list.classList.remove('show'); list.innerHTML = ''; return; }
list.innerHTML = '';
items.forEach((it, i) => {
const div = document.createElement('div');
div.className = 'ac-item' + (i === focusedIdx ? ' focused' : '');
div.innerHTML = `<span class="ac-icon">${it.type === 'fav' ? 'โ
' : 'โ'}</span>`
+ `<span class="ac-label">${esc(it.value)}</span>`
+ (it.type === 'recent' ? `<button class="ac-del" data-del="${esc(it.value)}" title="์ญ์ ">โ</button>` : '');
div.addEventListener('mousedown', (e) => {
if (e.target.dataset.del !== undefined) {
removeRecentSearch(e.target.dataset.del);
render();
return;
}
inp.value = it.value;
list.classList.remove('show');
searchFn(it.value);
});
list.appendChild(div);
});
list.classList.add('show');
}
inp.addEventListener('focus', render);
inp.addEventListener('input', () => { focusedIdx = -1; render(); });
inp.addEventListener('keydown', (e) => {
if (!list.classList.contains('show')) return;
const items = list.querySelectorAll('.ac-item');
if (e.key === 'ArrowDown') { e.preventDefault(); focusedIdx = Math.min(items.length - 1, focusedIdx + 1); render(); }
else if (e.key === 'ArrowUp') { e.preventDefault(); focusedIdx = Math.max(-1, focusedIdx - 1); render(); }
else if (e.key === 'Enter' && focusedIdx >= 0) {
e.preventDefault();
const el = items[focusedIdx];
const label = el?.querySelector('.ac-label')?.textContent;
if (label) { inp.value = label; list.classList.remove('show'); searchFn(label); }
}
else if (e.key === 'Escape') { list.classList.remove('show'); }
});
// ์ธ๋ถ ํด๋ฆญ ์ ๋ซ๊ธฐ
document.addEventListener('mousedown', (e) => {
if (!list.contains(e.target) && e.target !== inp) list.classList.remove('show');
});
}
// โโโ D2: ์ ๋ ฌ ์
๋ ํธ ๋ฐ์ธ๋ฉ โโโ
function setupSortSelects() {
const cur = localStorage.getItem(LS_SORT()) || 'default';
for (const id of ['sortSelDt', 'sortSelMob']) {
const el = document.getElementById(id);
if (!el) continue;
el.value = cur;
el.addEventListener('change', () => {
localStorage.setItem(LS_SORT(), el.value);
// ๋ค๋ฅธ select๋ ๋๊ธฐํ
for (const otherId of ['sortSelDt', 'sortSelMob']) {
if (otherId !== id) { const o = document.getElementById(otherId); if (o) o.value = el.value; }
}
renderFavs();
});
}
}
// โโโ D14: ์์ฒญ ํต๊ณ โโโ
function setupStats() {
function fmtH(sec) {
if (!sec || sec < 60) return Math.round(sec || 0) + '์ด';
const m = Math.floor(sec / 60);
if (m < 60) return m + '๋ถ';
const h = Math.floor(m / 60);
return h + '์๊ฐ ' + (m % 60) + '๋ถ';
}
function buildStats() {
// progress.time ํฉ๊ณ (์๋ฆฌ์ฆ๋ณ), finished ํ์ฐจ ์, ์ต๊ทผ 1์ฃผ/1๋ฌ ์ถ์
// ์ต๊ทผ 1์ฃผ: clickedAt ๊ธฐ์ค
const now = Date.now();
const W = 7 * 86400000, M = 30 * 86400000;
let totalSec = 0, finishedEps = 0, weekSec = 0, monthSec = 0;
const top = [];
for (const f of favs) {
let favSec = 0, favFin = 0;
const prog = f.progress || {};
for (const lab of Object.keys(prog)) {
const p = prog[lab];
if (p?.finished && p?.duration) favSec += p.duration;
else if (p?.time) favSec += p.time;
if (p?.finished) favFin++;
}
totalSec += favSec;
finishedEps += favFin;
if (f.clickedAt) {
if (now - f.clickedAt < W) weekSec += favSec;
if (now - f.clickedAt < M) monthSec += favSec;
}
if (favSec > 0) top.push({ title: f.title, sec: favSec, fin: favFin });
}
top.sort((a, b) => b.sec - a.sec);
return { totalSec, finishedEps, weekSec, monthSec, top: top.slice(0, 5) };
}
function open() {
const s = buildStats();
const body = document.getElementById('statsBody');
if (!body) return;
body.innerHTML = `
<div class="stat-row"><span>์ด ์์ฒญ ์ถ์ </span><b>${fmtH(s.totalSec)}</b></div>
<div class="stat-row"><span>์ด๋ฒ ์ฃผ ์ถ์ </span><b>${fmtH(s.weekSec)}</b></div>
<div class="stat-row"><span>์ด๋ฒ ๋ฌ ์ถ์ </span><b>${fmtH(s.monthSec)}</b></div>
<div class="stat-row"><span>๋ค ๋ณธ ํ์ฐจ ์</span><b>${s.finishedEps}</b></div>
<div style="margin-top:14px;font-size:11px;color:var(--muted)">๋ง์ด ๋ณธ ์๋ฆฌ์ฆ Top 5</div>
${s.top.map(t => `<div class="stat-row"><span>${esc(t.title || '')}</span><b>${fmtH(t.sec)} ยท ${t.fin}ํ ์๋ฃ</b></div>`).join('') || '<div class="stat-row" style="color:var(--muted)">๋ฐ์ดํฐ ์์</div>'}
<div style="margin-top:10px;font-size:10px;color:var(--muted)">* ์์ฒญ ์๊ฐ์ ์งํ๋ฅ (time) ๋๋ finishedรduration ํฉ์ผ๋ก ์ถ์ ํ ๊ฐ์
๋๋ค.</div>
`;
document.getElementById('statsModal').classList.add('show');
}
for (const id of ['btnStatsDt', 'btnStatsMob']) {
document.getElementById(id)?.addEventListener('click', open);
}
document.getElementById('statsClose')?.addEventListener('click', () => {
document.getElementById('statsModal').classList.remove('show');
});
document.getElementById('statsModal')?.addEventListener('click', (e) => {
if (e.target.id === 'statsModal') document.getElementById('statsModal').classList.remove('show');
});
}
// โโโ B11: ๋ถํ
์ ์ด์ด๋ณด๊ธฐ ๋น
๋ฐฐ๋ โโโ
function showResumeHero() {
// ๊ฐ์ฅ ์ต๊ทผ ํด๋ฆญํ fav ์ค ์ด์ด๋ณด๊ธฐ ๊ฐ๋ฅํ ๊ฒ
const candidates = favs
.filter(f => f.progress && f.lastLabel && f.progress[f.lastLabel]?.time > 5 && !f.progress[f.lastLabel]?.finished)
.sort((a, b) => (b.clickedAt || 0) - (a.clickedAt || 0));
if (!candidates.length) return;
const f = candidates[0];
const dismissKey = `${f.id}@${f.lastLabel}@${Math.floor((f.progress[f.lastLabel].time || 0))}`;
if (localStorage.getItem(LS_RESUME_HERO_DISMISS()) === dismissKey) return;
const hero = document.getElementById('resumeHero');
const title = document.getElementById('rhTitle');
const meta = document.getElementById('rhMeta');
if (!hero) return;
const t = f.progress[f.lastLabel].time;
const mm = String(Math.floor(t / 60)).padStart(2, '0');
const ss = String(Math.floor(t % 60)).padStart(2, '0');
title.textContent = `${f.title || '(์ ๋ชฉ)'} ยท ${f.lastLabel}`;
meta.textContent = `${mm}:${ss} ๋ถํฐ ์ด์ด๋ณด๊ธฐ`;
hero.style.display = 'flex';
hero.onclick = (e) => {
if (e.target.id === 'rhClose') return;
hero.style.display = 'none';
selectFav(f.id, { source: f.source || 'tvchak', sid: f.lastSid, nid: f.lastNid });
};
document.getElementById('rhClose').onclick = (e) => {
e.stopPropagation();
localStorage.setItem(LS_RESUME_HERO_DISMISS(), dismissKey);
hero.style.display = 'none';
};
}
// โโโ B6: ๋ชจ๋ฐ์ผ ์ค์์ดํ (์ข/์ฐ = ์ด์ /๋ค์ ํ) โโโ
function setupSwipe() {
const wrap = document.getElementById('videoWrap');
if (!wrap) return;
let sx = 0, sy = 0, st = 0;
wrap.addEventListener('touchstart', (e) => {
if (wrap.classList.contains('locked')) return;
// ๋ ์๊ฐ๋ฝ(ํ์น) ๋ฟ์ผ๋ฉด ์ค์์ดํ ํ๋ณด ํ๊ธฐ. ์ ๊ทธ๋ฌ๋ฉด ํ์น ํ ์ ๋ผ๋ ์ขํ ์ฐจ์ด๋ก ๋ค์ํ ์ค์ธ.
if (e.touches.length >= 2) { sx = 0; return; }
if (e.touches.length !== 1) return;
sx = e.touches[0].clientX; sy = e.touches[0].clientY; st = Date.now();
}, { passive: true });
wrap.addEventListener('touchmove', (e) => {
// ์ค๊ฐ์ ๋ ์๊ฐ๋ฝ์ผ๋ก ๋์ด๋๋ฉด๋ ํ๊ธฐ
if (e.touches.length >= 2) sx = 0;
}, { passive: true });
wrap.addEventListener('touchend', (e) => {
if (wrap.classList.contains('locked')) return;
if (!sx) return;
// touchend ์์ ์ ์ฌ์ ํ ์๊ฐ๋ฝ 1๊ฐ ์ด์ ๋จ์์์ผ๋ฉด(๋ฉํฐํฐ์น ์ผ๋ถ๋ง ๋) ์ค์์ดํ X
if (e.touches.length > 0) { sx = 0; return; }
const t = e.changedTouches[0];
const dx = t.clientX - sx, dy = t.clientY - sy, dt = Date.now() - st;
sx = 0;
if (dt > 500) return; // ๋๋ฌด ๋๋ฆฐ ๋์์ ๋ฌด์
if (Math.abs(dx) < 60 || Math.abs(dx) < Math.abs(dy) * 1.5) return;
// ์ข์ธก ์ค์์ดํ โ ๋ค์ ํ (์ฌ์ฉ์ ์ง๊ด: ์ขโ์ฐ ๋๊ธฐ๊ธฐ)
if (dx < 0) gotoEpisode(1);
else gotoEpisode(-1);
}, { passive: true });
}
// โโโ C7: ์๋ฆฌ์ฆ๋ณ ์ฌ์์๋ ๊ธฐ์ต โโโ
function setupRateMemory() {
const v = document.getElementById('player');
if (!v) return;
v.addEventListener('ratechange', () => {
if (!currentFavId) return;
const fav = favs.find(f => f.id === currentFavId);
if (!fav) return;
if (fav.lastPlaybackRate !== v.playbackRate) {
fav.lastPlaybackRate = v.playbackRate;
saveFavs();
}
});
// ์ ์์ loadedmetadata ์ ์๋ฆฌ์ฆ ๊ธฐ์ต ์๋ ์ ์ฉ
v.addEventListener('loadedmetadata', () => {
const fav = favs.find(f => f.id === currentFavId);
if (fav && typeof fav.lastPlaybackRate === 'number' && fav.lastPlaybackRate > 0) {
try { v.playbackRate = fav.lastPlaybackRate; } catch {}
}
});
}
// โโโ C8: ์ฌ์ ์คํจ ์๋ ์ฌ์๋ + ํ ์คํธ โโโ
function showMediaToast(msg, ms = 1500) {
const el = document.getElementById('mediaToast');
if (!el) return;
el.textContent = msg;
el.classList.add('show');
clearTimeout(el._t);
el._t = setTimeout(() => el.classList.remove('show'), ms);
}
function setupVideoErrorRetry() {
const v = document.getElementById('player');
if (!v) return;
let retried = false;
let reloadedForStall = false;
// ๋ณต๊ตฌ ๊ธฐ์ค ์ค๋
์ท: refreshAll/syncFavsFromOtherDevices๊ฐ currentEpList/currentEpIdx๋ฅผ
// ๊ฐ์๋ผ์ฐ๋ ์ฌ์ด stall ๋ณต๊ตฌ๊ฐ ํธ๋ฆฌ๊ฑฐ๋๋ฉด currentEpList[currentEpIdx]๊ฐ ๋ค๋ฅธ ํ์ฐจ๋ก ๋ฐ๋๋
// ์ฌ๊ณ (2026-06-08)๊ฐ ์์์. loadstart ์์ ์ sid/nid/favId๋ฅผ ๋ฐ์ ๋๊ณ ๊ทธ ๊ฐ์ผ๋ก๋ง ๋ณต๊ตฌ.
let snap = { favId: null, favSource: null, sid: null, nid: null };
v.addEventListener('loadstart', () => {
retried = false; reloadedForStall = false;
if (currentFavId && currentEpIdx >= 0 && currentEpList[currentEpIdx]) {
const ep = currentEpList[currentEpIdx];
snap = { favId: currentFavId, favSource: currentFavSource || null, sid: ep.sid, nid: ep.nid };
}
});
v.addEventListener('error', () => {
if (retried) { showMediaToast('์ฌ์ ์คํจ. ์ ์ ํ ๋ค์ ์๋ํด์ฃผ์ธ์.', 3000); return; }
if (!snap.favId || snap.sid == null) return;
retried = true;
showMediaToast('์๋ ์ฌ์๋ ์คโฆ', 2500);
setTimeout(() => {
playEpisode(snap.favId, snap.sid, snap.nid, { userInitiated: false }).catch(() => {});
}, 3000);
});
// stalled ์๋ ์ฌ๊ฐ:
// <video>๊ฐ ์ฌ์ ์ค ๋คํธ์ํฌ ๋๊นยท์๋ฒ RST(HF push ์ ๋ฑ)๋ก ๋ฉ์ถ๋ฉด error ์ด๋ฒคํธ ์์ด stalled/waiting๋ง ๋ฐ์.
// currentTime์ด 8์ด ๋์ ์งํ ์ ๋๋ฉด ์๋ ๋ณต๊ตฌ: โ ์งง์ seek๋ก buffer ๋ค์ ์ฑ์ โ โก ์ ๋๋ฉด ์ stream URL๋ก reload.
let lastTime = 0;
let lastTimeAt = Date.now();
let stallCheckInterval = null;
// ์ผ์์ ์ง ์๊ฐ ๊ธฐ๋ก โ ์ค๋ ๋ฉ์ท๋ค ์ฌ์ํ๋ฉด mp4 progressive ์ปค๋ฅ์
์ด ์ฃฝ์ด
// ์ฌ๊ฐ ์ buffer ์ฌ์ถฉ์ ์ ์คํจ(waitingโstalled ๋ฌดํ)ํ๋ ์ฌ๊ณ ๋ฐฉ์ง์ฉ.
// (2026-07-17 ์ง๋จ: 31๋ถ ์ผ์์ ์ง ํ ์ฌ์ โ waiting/stalled โ seek๋ณต๊ตฌ ์คํจ โ ์ฌ๋ก๋.
// seek ๋ณต๊ตฌ๋ mp4์์ ์ด๋ฏธ ๋ฒํผ์ ์๋ ๊ตฌ๊ฐ ๋๊ฐ๊ธฐ๋ผ ๋ฌด์๋ฏธ. ์ค๋ ๋ฉ์ท์ผ๋ฉด ์ ์ ์ฌ๋ก๋๊ฐ ์ ๋ต.)
let pausedAt = 0;
const LONG_PAUSE_MS = 60000; // ์ด ์ด์ ๋ฉ์ท๋ค ์ฌ์ํ๋ฉด ์ ์ ์ฌ๋ก๋
// ๊ฐ์ ํ์ฐจ๋ฅผ ์ stream URL๋ก ์ฌ๋ก๋ ํ resumeTime ์์น์์ ์ด์ด๋ณด๊ธฐ.
// stall 2์ฐจ ๋ณต๊ตฌ์ "์ค๋ ์ผ์์ ์ง ํ ์ ์ ์ฌ๋ก๋" ๋ ๋ค ์ด ํจ์๋ฅผ ์.
function reconnectStream(resumeTime, toastMsg) {
if (!snap.favId || snap.sid == null) return;
reloadedForStall = true;
// ์ฌ๋ก๋ ์ง์ zoom ์ํ ๋ณด์กด โ ๋ชจ๋ฐ์ผ ์ผ๋ถ ๋ธ๋ผ์ฐ์ ๋ src ๊ต์ฒด ์ fullscreen auto-exitํ๋ฉฐ zoom์ด ๋ฆฌ์
๋จ
const savedZoom = window._videoZoom?.getZoom?.() ?? 1;
const wasFullscreen = window._videoZoom?.isFullscreen?.() ?? false;
showMediaToast(toastMsg || '์คํธ๋ฆผ ์ฌ์ฐ๊ฒฐ ์คโฆ', 2500);
playEpisode(snap.favId, snap.sid, snap.nid, { userInitiated: false }).then(() => {
// ๋๊ธด ์์น์์ ์ฌ๊ฐ
const onCanPlay = () => {
try { if (resumeTime > 0) v.currentTime = resumeTime; v.play().catch(() => {}); } catch {}
v.removeEventListener('canplay', onCanPlay);
// zoom ๋ณต์ โ fullscreen์ด ์๋ ์ข
๋ฃ๋๋ค๋ฉด ๋ค์ ์ง์
ํ ๋ค์ ์ ์ฉ
if (savedZoom > 1) {
const restoreZoom = () => {
try { window._videoZoom?.setZoom?.(savedZoom); } catch {}
};
if (wasFullscreen && !window._videoZoom?.isFullscreen?.()) {
// ์๋ ํ์คํฌ๋ฆฐ ์ฌ์ง์
์๋. ์คํจํด๋ ๋ค์ ์ฌ์ฉ์ ์ง์
์ restoreSavedZoom์ด fav ์ ์ฅ๊ฐ์ผ๋ก ๋ณต์.
const wrap = document.getElementById('videoWrap');
(wrap?.requestFullscreen?.call(wrap) || wrap?.webkitRequestFullscreen?.call(wrap) || Promise.resolve())
.then(restoreZoom).catch(restoreZoom);
} else if (window._videoZoom?.isFullscreen?.()) {
restoreZoom();
}
}
};
v.addEventListener('canplay', onCanPlay);
}).catch(() => {});
}
v.addEventListener('playing', () => {
reloadedForStall = false;
if (stallCheckInterval) clearInterval(stallCheckInterval);
// โโ ์ค๋ ์ผ์์ ์ง ํ ์ฌ๊ฐ = mp4 progressive ์ปค๋ฅ์
์ด ์ฃฝ์ด buffer ์ฌ์ถฉ์ ์คํจํ๋ ์ผ์ด์ค.
// stall(8์ด+seek์คํจ+5์ด) ์ ๊ธฐ๋ค๋ฆฌ๋ฉฐ "๋ค์ ์ฐ๊ฒฐํฉ๋๋ค"๊ฐ ๋ฐ๋ณต๋๊ธฐ ์ ์, ์ฌ๊ฐ ์ฆ์ ์ ์ ์ฌ๋ก๋.
// (2026-07-17 ๋ก๊ทธ๋ก ํ์ธ: 31๋ถ ์ผ์์ ์ง ํ ์ฌ์ โ waiting/stalled โ seek ๋ฌด์๋ฏธ โ ๊ฒฐ๊ตญ ์ฌ๋ก๋๋ก๋ง ๋ณต๊ตฌ๋จ.)
if (pausedAt && Date.now() - pausedAt > LONG_PAUSE_MS && !reloadedForStall) {
const resumeTime = v.currentTime;
pausedAt = 0;
reconnectStream(resumeTime, '์ค๋ ๋ฉ์ถฐ ์์ด ๋ค์ ์ฐ๊ฒฐํฉ๋๋คโฆ');
return; // ์ฌ๋ก๋๊ฐ ์ playing์ ๋ค์ ๋ฐ์์ํค๋ฏ๋ก ์ด๋ฒ interval์ ์ ๊ฑธ์ด๋ ๋จ
}
pausedAt = 0;
// ์ฌ์(์ฌ)๊ฐ ์์ ๊ธฐ์ค์ผ๋ก stall ๊ธฐ์ค๊ฐ ๋ฆฌ์
.
// Why: ์ผ์์ ์ง๋ก interval์ด ๋ฉ์ถ ๋์ lastTimeAt์ด ์ ์๊ฐ์ ๊ณ ์ ๋ผ ์๋๋ฐ,
// ์ด๊ฑธ ๋ฆฌ์
์ ํ๋ฉด ์ฌ์ ์ฌ๊ฐ ์งํ ์ฒซ ์ฒดํฌ์์ stalledMs = (์ง๊ธ - ๋ฉ์ถ๊ธฐ์ )์ด
// ๊ทธ๋๋ก 8์ด๋ฅผ ๋๊ฒจ ์ฆ์ "์คํธ๋ฆผ ์ฌ์ฐ๊ฒฐ"์ด ์ค๋ฐ๋ํ๋ค (์ผ์์ ์งํ ๋๋ง๋ค ๋๊น์ ์์ธ).
lastTime = v.currentTime;
lastTimeAt = Date.now();
stallCheckInterval = setInterval(() => {
if (v.paused || v.ended || v.seeking) { lastTime = v.currentTime; lastTimeAt = Date.now(); return; }
// ์งํ ์ค์ธ๋ฐ currentTime์ด ์ ์์ง์ โ stall
if (Math.abs(v.currentTime - lastTime) > 0.05) {
lastTime = v.currentTime;
lastTimeAt = Date.now();
return;
}
const stalledMs = Date.now() - lastTimeAt;
if (stalledMs < 8000) return; // 8์ด ๊ทธ๋ ์ด์ค
if (reloadedForStall) return; // ์ด๋ฏธ ์๋ํจ
// 1์ฐจ ๋ณต๊ตฌ: ์งง์ seek (buffer reset). mp4 direct์๋ ํจ๊ณผ ์์
try {
const t = v.currentTime;
v.currentTime = Math.max(0, t - 0.5);
v.play().catch(() => {});
showMediaToast('๋คํธ์ํฌ ๋๊น ๊ฐ์ง, ์ฌ๊ฐ ์๋โฆ', 2000);
lastTimeAt = Date.now() + 4000; // 4์ด ์ถ๊ฐ ๊ทธ๋ ์ด์ค
} catch {}
// 2์ฐจ ๋ณต๊ตฌ: seek ํ 4์ด ๋ ๊ธฐ๋ค๋ ค๋ ์ ํ๋ฆฌ๋ฉด ๊ฐ์ ํ์ฐจ reload (์ stream URL ๋ฐ๊ธ)
setTimeout(() => {
if (!v.paused && Math.abs(v.currentTime - lastTime) < 0.05 && !reloadedForStall) {
// currentEpIdx ๋์ loadstart ์์ ์ ๋ฐ์ ๋ snap.sid/nid๋ก ๋ณต๊ตฌ (๋ค๋ฅธ ํ ์ฌ๊ณ ๋ฐฉ์ง)
reconnectStream(v.currentTime);
}
}, 5000);
}, 2000);
});
v.addEventListener('pause', () => {
if (stallCheckInterval) { clearInterval(stallCheckInterval); stallCheckInterval = null; }
// ended๊ฐ ์๋ ์ค์ ์ผ์์ ์ง์ผ ๋๋ง ์๊ฐ ๊ธฐ๋ก (์ฌ์ ๋๋์ pause๋ ๊ฑด ์ ์ธ)
if (!v.ended) pausedAt = Date.now();
});
v.addEventListener('ended', () => {
if (stallCheckInterval) { clearInterval(stallCheckInterval); stallCheckInterval = null; }
pausedAt = 0;
});
}
// โโโ D12: ์๋/์ฌ์์๋ ์ธ๋์ผ์ดํฐ โโโ
function setupMediaIndicators() {
const v = document.getElementById('player');
if (!v) return;
let lastVol = v.volume;
v.addEventListener('volumechange', () => {
if (Math.abs(v.volume - lastVol) > 0.001 || v.muted !== undefined) {
lastVol = v.volume;
showMediaToast(v.muted ? '๐ ์์๊ฑฐ' : `๐ ${Math.round(v.volume * 100)}%`);
}
});
v.addEventListener('ratechange', () => {
showMediaToast(`โถ ${v.playbackRate.toFixed(2).replace(/0$/, '')}ร`);
});
}
// โโโ C5: ์นด์ดํธ๋ค์ด ๋ฒํผ + G-6: ํค๋ณด๋ ๋จ์ถํค โโโ
let _ncPaused = false;
function setupNextCountdownButtons() {
// ๋ชจ๋ฐ์ผ์์ wrap capture ๋จ๊ณ ํธ๋ค๋ฌ๋ click ํฉ์ฑ ์ง์ฐ์ผ๋ก ์ทจ์/์ง๊ธ์์ฒญ์ด ์ ๋จน๋ ์ฌ๊ณ ๊ฐ
// ๋ฐ๋ณต๋ผ์, pointerup์ผ๋ก ์ง์ ๋ฐ๊ณ wrap ์ชฝ ํธ๋ค๋ฌ๋ก ์์ด๋๊ฐ์ง ์๊ฒ stopPropagation๊น์ง ๋ฐ๋๋ค.
// click๋ ์ด๋ ค๋์ด ๋ฐ์คํฌํยทํค๋ณด๋(Enter ํฉ์ฑ) ํธํ.
const ncBox = document.getElementById('nextCountdown');
const doCancel = (e) => { e?.stopPropagation?.(); e?.preventDefault?.(); cancelNextCountdown(); };
const doGo = (e) => {
e?.stopPropagation?.(); e?.preventDefault?.();
const titleEl = document.getElementById('ncTitle');
if (!titleEl) return;
const label = titleEl.textContent;
cancelNextCountdown();
const sortedAsc = [...currentEpList].sort((a, b) => a.sid - b.sid || a.nid - b.nid);
const next = sortedAsc.find(e => (e.label || `${e.nid}ํ`) === label);
if (next) {
playEpisode(currentFavId, next.sid, next.nid, { userInitiated: true }).then(() => {
$('#player').play().catch(() => {});
});
}
};
// pointerup์ด click๋ณด๋ค ๋จผ์ ๋ฐํ + ๋ชจ๋ ์
๋ ฅํ์
(ํฐ์น/๋ง์ฐ์ค/ํ) ํตํฉ.
// ๊ฐ์ ํญ์์ click์ด ๋ ๋ฐํํด๋ ์นด์ดํธ๋ค์ด์ด ์ด๋ฏธ ๋ซํ์ ๋ ๋ฒ์งธ ํธ์ถ์ no-op.
const ncCancelBtn = document.getElementById('ncCancel');
const ncGoBtn = document.getElementById('ncGo');
ncCancelBtn?.addEventListener('pointerup', doCancel);
ncCancelBtn?.addEventListener('click', doCancel);
ncGoBtn?.addEventListener('pointerup', doGo);
ncGoBtn?.addEventListener('click', doGo);
// ๋ฐ์ค ์ ์ฒด์ touch/pointer ์ด๋ฒคํธ๊ฐ wrap์ ๋๋ธํญยทhold ํธ๋ค๋ฌ๋ก ์์ด๋๊ฐ์ง ์๊ฒ ์ฐจ๋จ.
// closest ๊ฐ๋(2518/2565ํ)์ ๋ํด ์ด์ค ์์ ๋ง โ capture ๋จ๊ณ์์ wrap์ด ์ด๋ฏธ ๋ณด๊ณ ๋์ด๊ฐ๋
// ์ดํ ๋จ๊ณ์์ ๋ค๋ฅธ ํธ๋ค๋ฌ๊ฐ ๋๋ธํญ์ผ๋ก ์ค์ธํ์ง ์๋๋ก.
if (ncBox) {
for (const t of ['touchstart','touchend','pointerdown','pointerup','click']) {
ncBox.addEventListener(t, (e) => e.stopPropagation(), true);
}
}
// G-6: Enter=์ง๊ธ์์ฒญ, Esc=์ทจ์, Space=์ผ์์ ์ง (์นด์ดํธ๋ค์ด ํ์ ์ค์ผ ๋๋ง)
document.addEventListener('keydown', (e) => {
const el = document.getElementById('nextCountdown');
if (!el || !el.classList.contains('show')) return;
// ์
๋ ฅ์ฐฝ ํฌ์ปค์ค๋์ด ์์ผ๋ฉด ๋ฌด์
const t = e.target;
if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable)) return;
if (e.key === 'Enter') { e.preventDefault(); document.getElementById('ncGo')?.click(); }
else if (e.key === 'Escape') { e.preventDefault(); cancelNextCountdown(); }
else if (e.key === ' ') {
e.preventDefault();
_ncPaused = !_ncPaused;
const label = document.querySelector('#nextCountdown .nc-label');
if (label) label.style.opacity = _ncPaused ? '0.5' : '1';
}
});
}
// โโโ G-10: ๋จ์ถํค ์๋ด ๋ชจ๋ฌ โโโ
function setupShortcutsHelp() {
const open = () => document.getElementById('shortcutsModal').classList.add('show');
const close = () => document.getElementById('shortcutsModal').classList.remove('show');
document.getElementById('shortcutsClose')?.addEventListener('click', close);
document.getElementById('shortcutsModal')?.addEventListener('click', (e) => {
if (e.target.id === 'shortcutsModal') close();
});
document.addEventListener('keydown', (e) => {
const t = e.target;
if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable)) return;
if (e.key === '?' || (e.key === '/' && e.shiftKey)) {
e.preventDefault();
const modal = document.getElementById('shortcutsModal');
if (modal.classList.contains('show')) close(); else open();
}
});
}
// F-13: โ/โถ nav ๋ฒํผ ์ ๊ฑฐ๋จ โ ์ค์์ดํ(B6)์ ํ์ฐจ ์นฉ ํด๋ฆญ์ผ๋ก ๋์ฒด
function setupEpNavButtons() {}
function updateEpNavButtons() {}
// โโโ F-8: ๋ค์ ํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ (์์ hover ์ ์ ๊น) โโโ
function setupNextPreview() {
const wrap = document.getElementById('videoWrap');
const btn = document.getElementById('nextPreview');
if (!wrap || !btn) return;
let hideT = null;
function findNext() {
if (!currentEpList.length || currentEpIdx < 0) return null;
const sortedAsc = [...currentEpList].sort((a, b) => a.sid - b.sid || a.nid - b.nid);
const idx = sortedAsc.findIndex(e => e.sid === currentEpList[currentEpIdx].sid && e.nid === currentEpList[currentEpIdx].nid);
if (idx <= 0) return null;
return sortedAsc[idx - 1];
}
function show() {
const next = findNext();
if (!next) { btn.classList.remove('show'); return; }
btn.textContent = `๋ค์ โถ ${next.label || (next.nid + 'ํ')}`;
btn.classList.add('show');
clearTimeout(hideT);
// ๋ชจ๋ฐ์ผ์์ ํ์โ์๊ฐ๋ฝ ์ด๋โํญ์ ์๊ฐ์ด ํ์ํด 2.5์ด๋ ์งง์. 4์ด๋ก ์ฌ์ .
hideT = setTimeout(() => btn.classList.remove('show'), 4000);
}
// ๋ง์ฐ์ค ์์ง์ or ํฐ์น
wrap.addEventListener('mousemove', show);
wrap.addEventListener('touchstart', show, { passive: true });
// ๋ฒํผ์ ์๊ฐ๋ฝ์ด ๋ฟ๋ ์๊ฐ์ ์ฌ๋ผ์ง์ง ์๋๋ก ํ์ด๋จธ ํด์ โ ์ฌ์ฉ์๊ฐ ๋๋ฅด๋ ค๋ ์๋ ๋ช
ํ.
btn.addEventListener('touchstart', (e) => {
e.stopPropagation();
clearTimeout(hideT);
}, { passive: true });
btn.addEventListener('click', (e) => {
e.stopPropagation();
const next = findNext();
if (next) {
btn.classList.remove('show');
playEpisode(currentFavId, next.sid, next.nid, { userInitiated: true }).then(() => {
$('#player').play().catch(() => {});
});
}
});
}
// โโโ B15: PWA service worker ๋ฑ๋ก + ์๋ ์
๋ฐ์ดํธ โโโ
function setupPWA() {
if (!('serviceWorker' in navigator)) return;
navigator.serviceWorker.register('/sw.js', { scope: '/' })
.then(reg => {
// 1์๊ฐ๋ง๋ค ์
๋ฐ์ดํธ ์ฒดํฌ
setInterval(() => reg.update().catch(() => {}), 60 * 60 * 1000);
})
.catch((e) => console.warn('SW reg failed:', e));
// ์ SW๊ฐ ํ์ฑํ๋๋ฉด ์๋ reload (ํ ๋ฒ๋ง).
// ๋จ ์์ ์ฌ์ ์ค์ด๋ฉด ๋ณด๋ฅ โ ์ฌ์ฉ์๊ฐ ์ผ์์ ์งํ๊ฑฐ๋ ๋ค์ ํญ ์ ํ ์ ๊ฐฑ์ .
let _reloading = false;
let _pendingReload = false;
const tryReload = (reason) => {
if (_reloading) return;
const v = document.getElementById('player');
const playing = v && !v.paused && !v.ended && v.currentTime > 0;
if (playing) {
_pendingReload = true;
console.log(`[sw] ${reason} โ defer reload (playing)`);
return;
}
_reloading = true;
console.log(`[sw] ${reason} โ reloading`);
setTimeout(() => location.reload(), 200);
};
navigator.serviceWorker.addEventListener('message', (e) => {
if (e.data?.type === 'sw-updated') tryReload('new version activated');
});
// controllerchange๋ reload (๋ค๋ฅธ ํญ์์ update ํธ๋ฆฌ๊ฑฐ๋์์ ๋)
navigator.serviceWorker.addEventListener('controllerchange', () => tryReload('controllerchange'));
// ์์์ด ์ผ์์ ์ง/์ข
๋ฃ๋ ๋ ๋ณด๋ฅ๋ reload ์ฌ์๋
document.addEventListener('pause', (e) => {
if (_pendingReload && e.target?.id === 'player') tryReload('pending after pause');
}, true);
// ํญ์ด hidden์ผ๋ก ๊ฐ ๋๋ ๊ธฐํ โ ์ฌ์ฉ์๊ฐ ๋ค๋ฅธ ์์
์ค์ด๋ผ ์ ๋ณด์
document.addEventListener('visibilitychange', () => {
if (_pendingReload && document.visibilityState === 'hidden') tryReload('pending on hidden');
});
}
(async function boot() {
// ์ด๋ ๋จ๊ณ๊ฐ ์คํจํด๋ UI๋ ๋ฌด์กฐ๊ฑด ๊ทธ๋ ค์ง๋๋ก try/catch ๋ณดํธ.
setupSortSelects();
renderProfileTabs();
loadProfileLabels(); // E1: ๋ณ์นญ ์ผ๊ด ์กฐํ (๋น๋๊ธฐ, ๋์ฐฉํ๋ฉด ์๋ ์ฌ๋ ๋)
renderFavs();
setupStats();
setupSwipe();
setupRateMemory();
setupVideoErrorRetry();
setupMediaIndicators();
setupNextCountdownButtons();
setupShortcutsHelp();
setupEpNavButtons();
setupNextPreview();
// ๊ฒ์ ์๋์์ฑ: ๋ฐ์คํฌํ(searchInputโacListDt), ๋ชจ๋ฐ์ผ(searchInputMobโacListMob)
setupSearchAutocomplete('searchInput', 'acListDt', (wd) => {
document.getElementById('searchInput').value = wd;
pushRecentSearch(wd);
doSearch(wd, 'searchResults');
});
setupSearchAutocomplete('searchInputMob', 'acListMob', (wd) => {
document.getElementById('searchInputMob').value = wd;
pushRecentSearch(wd);
doSearch(wd, 'searchResultsMob');
});
setupPWA();
loadDomain().catch(e => console.warn('boot loadDomain:', e));
loadRanking('daily');
// ๋ถํ
์ ๋ณด๊ดํจ NEW ์๋ ๊ฐ์ง โ ์ฌ์ฉ์ ํด๋ฆญ ์์ด๋ latestLabel ๊ฐฑ์
refreshLatestLabels().catch(e => console.warn('boot latest-labels:', e));
// ๋ถํ
์ progress ๋๊ธฐํ: ์๋ฒ pull์ selectFav๋ณด๋ค ๋จผ์ ๋๋ด์ผ ํจ.
// Why: localStorage์ ๋ค๋ฅธ ๋๋ฐ์ด์ค๊ฐ ๊ฐฑ์ ํ ์ต์ progress๊ฐ ์์ง ์์ ์ ์๋๋ฐ,
// selectFav๊ฐ ์ progress๋ก currentTime์ ๋ณต์ํ๋ฉด ๊ณง์ฅ timeupdate๊ฐ ๋ฐํํด
// _pendingPut=true๋ฅผ ์ผ ๋ค. ๊ทธ ๋ค๋ก๋ pullFavsFromServer๊ฐ if(_pendingPut) return
// ๊ฐ๋์ ๋งํ ์๋ฒ ์ต์ ๊ฐ์ ์์ ๋ชป ๊ฐ์ ธ์ค๊ณ ์ ์์ ์ด ๊ตณ์ด์ง๋ค (๋ค๋ฅธ ๋๋ฐ์ด์ค์์
// "์ด์ด๋ณด๊ธฐ๊ฐ ํ์ฐธ ์ ์์ ๋ถํฐ ์์" ์ฆ์์ ์ง์ง ์์ธ).
// ์๋ฒ๊ฐ ์ฃฝ์๊ฑฐ๋ ๋๋ฆฌ๋ฉด 1.5์ด ํ์์์ ํ ๊ทธ๋ฅ ์งํ โ ๋ถํ
๋ฉ์ถค ๋ฐฉ์ง.
await Promise.race([
pullFavsFromServer().catch(e => console.warn('boot pullFavs:', e)),
new Promise(resolve => setTimeout(resolve, 1500)),
]);
renderFavs();
const bootedLastFavId = lastFavId;
try {
if (bootedLastFavId && favs.find(f => f.id == bootedLastFavId)) {
await selectFav(+bootedLastFavId, { silent: true });
} else {
// ๋ถํ
์๋ ์ ํ ์ ํ์ ๋๋ง ์ด์ด๋ณด๊ธฐ ๋น
๋ฐฐ๋ ํ์
showResumeHero();
}
} catch (e) { console.warn('boot selectFav:', e); }
})();
</script>
</body>
</html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover" />
<meta name="theme-color" content="#0f1115" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<title>OTT Player</title>
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="manifest" href="/manifest.webmanifest">
<meta name="theme-color" content="#0f1115">
<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin>
<link rel="preload" href="https://cdn.jsdelivr.net/npm/hls.js@1.5.15/dist/hls.min.js" as="script" crossorigin>
<script src="https://cdn.jsdelivr.net/npm/hls.js@1.5.15/dist/hls.min.js" defer></script>
<link rel="apple-touch-icon" href="/favicon.svg" />
<style>
:root {
--bg: #0f1115;
--panel: #161a22;
--panel2: #1d222c;
--border: #2a313d;
--text: #e6e8ec;
--muted: #8a93a6;
--accent: #ff5b6a;
--accent2: #4ea1ff;
--new: #ffb020;
--safe-top: env(safe-area-inset-top, 0px);
--safe-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
overscroll-behavior: none; }
body { min-height: 100dvh; }
button { font-family: inherit; }
input { font-family: inherit; font-size: 16px; /* iOS ์ค ๋ฐฉ์ง */ }
/* โโโโโ ๊ณตํต ํผ/๋ฒํผ โโโโโ */
.btn { background: var(--panel2); border: 1px solid var(--border); color: var(--text);
border-radius: 8px; padding: 8px 12px; font-size: 13px; cursor: pointer; }
.btn:active { background: #2a313d; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: #e34758; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 8px 10px; min-width: 38px; }
input.text { background: var(--panel2); border: 1px solid var(--border); color: var(--text);
border-radius: 8px; padding: 8px 12px; outline: none; width: 100%; }
input.text:focus { border-color: var(--accent2); }
/* โโโโโ ์๋จ ์ฑ๋ฐ โโโโโ */
.appbar { position: sticky; top: 0; z-index: 30; background: var(--panel);
border-bottom: 1px solid var(--border);
padding: calc(8px + var(--safe-top)) 10px 8px;
display: flex; align-items: center; gap: 8px; }
.appbar h1 { margin: 0; font-size: 15px; flex: 1; min-width: 0; overflow: hidden;
text-overflow: ellipsis; white-space: nowrap; }
.appbar h1 small { color: var(--muted); font-weight: normal; font-size: 11px; margin-left: 6px; }
.appbar .domain { font-size: 10px; color: #6ee7a8; }
.appbar .domain.bad { color: #ff7b7b; }
/* โโโโโ ๋น๋์ค โโโโโ */
.video-wrap { position: relative; background: #000; width: 100%; aspect-ratio: 16/9; }
.video-wrap.fill { aspect-ratio: auto; height: 100%; flex: 1; }
video { width: 100%; height: 100%; background: #000; display: block; }
.video-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
color: var(--muted); font-size: 13px; padding: 16px; text-align: center; pointer-events: none; }
.video-empty.hide { display: none; }
.video-loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
color: var(--accent2); font-size: 13px; background: rgba(0,0,0,0.6); padding: 8px 12px; border-radius: 6px; }
/* ์๋จ ํ์ด์ง ๋ก๋ฉ ๋ฐ โ ๋ณด๊ดํจ ํด๋ฆญ ํ episodes/play ๋ก๋ ํ
์ ํ์ */
#topLoader { position: fixed; top: 0; left: 0; right: 0; height: 3px;
background: transparent; z-index: 9999; pointer-events: none;
opacity: 0; transition: opacity 0.2s; }
#topLoader.show { opacity: 1; }
#topLoader::before { content: ''; display: block; height: 100%;
background: linear-gradient(90deg, transparent, var(--accent), var(--accent), transparent);
background-size: 50% 100%; background-repeat: no-repeat;
animation: topLoaderSlide 1s linear infinite;
box-shadow: 0 0 8px var(--accent); }
@keyframes topLoaderSlide {
0% { background-position: -50% 0; }
100% { background-position: 150% 0; }
}
.rate-toast { position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
background: rgba(0,0,0,0.75); color: #fff; padding: 8px 18px; border-radius: 999px;
font-size: 20px; font-weight: 800; font-family: "Bebas Neue", sans-serif;
letter-spacing: 0.05em; opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 6; }
.rate-toast.show { opacity: 1; }
/* ์ผ์์ ์ง ์ค๋ฒ๋ ์ด โ ๊ฐ์ด๋ฐ ํฐ ์ฌ์๋ฒํผ */
.pause-overlay {
position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
width: 96px; height: 96px; border-radius: 50%;
background: rgba(0,0,0,0.6); border: 2px solid rgba(255,255,255,0.3);
color: #fff; font-size: 40px; padding-left: 6px;
display: flex; align-items: center; justify-content: center;
cursor: pointer; z-index: 4; backdrop-filter: blur(6px);
transition: transform 0.15s, background 0.15s;
animation: pauseAppear 0.25s ease-out;