initial commit for test

This commit is contained in:
seanland committed 2026-11-24 13:22:37 -05:00
commit 8d256d259d
56 files changed
+2355

No files matched your search

+468
View File
@@ -0,0 +1,468 @@
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0f0f12;
--surface: #1a1a21;
--surface-2: #23232c;
--border: #2c2c36;
--text: #ececf1;
--muted: #9b9ba8;
--accent: #ff5252;
--accent-hover: #ff6a6a;
--green: #4ade80;
--header-bg: rgba(15, 15, 18, 0.92);
--toast-bg: #23232c;
--chip-active-bg: #ffffff;
--chip-active-text: #111111;
}
[data-theme="light"] {
--bg: #f6f6fa;
--surface: #ffffff;
--surface-2: #ececf3;
--border: #e0e0e9;
--text: #1d1d24;
--muted: #63636f;
--accent: #e03131;
--accent-hover: #c92a2a;
--green: #16a34a;
--header-bg: rgba(246, 246, 250, 0.92);
--toast-bg: #ffffff;
--chip-active-bg: #1d1d24;
--chip-active-text: #ffffff;
}
html, body { height: 100%; }
body {
background: var(--bg);
color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
line-height: 1.5;
}
header {
position: sticky; top: 0; z-index: 50;
display: flex; align-items: center; gap: 20px;
padding: 12px 24px;
background: var(--header-bg);
backdrop-filter: blur(10px);
border-bottom: 1px solid var(--border);
}
.logo {
display: flex; align-items: center; gap: 10px;
font-size: 20px; font-weight: 800; letter-spacing: -0.5px;
color: var(--text); text-decoration: none; white-space: nowrap;
}
.logo .mark {
width: 34px; height: 34px; border-radius: 9px;
background: linear-gradient(135deg, var(--accent), #b91c1c);
display: grid; place-items: center;
font-size: 17px; color: #fff;
}
.search {
flex: 1; max-width: 560px;
position: relative;
}
.search input {
width: 100%; padding: 9px 14px 9px 38px;
background: var(--surface); border: 1px solid var(--border);
border-radius: 999px; color: var(--text); font-size: 14px;
outline: none; transition: border-color .15s;
}
.search input:focus { border-color: var(--accent); }
.search input::placeholder { color: var(--muted); }
.search .icon {
position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
color: var(--muted); pointer-events: none; font-size: 15px;
}
nav { display: flex; align-items: center; gap: 6px; }
nav a, .btn {
color: var(--text); text-decoration: none; font-size: 14px; font-weight: 600;
padding: 8px 14px; border-radius: 999px; border: none; cursor: pointer;
background: transparent; transition: background .15s;
}
nav a:hover, .btn:hover { background: var(--surface-2); }
nav a.active { background: var(--surface-2); color: #fff; }
.btn.icon-btn { padding: 8px 10px; font-size: 16px; }
main { max-width: 1440px; margin: 0 auto; padding: 24px; }
h2.section-title {
font-size: 18px; font-weight: 700; margin: 8px 0 16px;
display: flex; align-items: center; gap: 10px;
}
h2.section-title .count { color: var(--muted); font-size: 13px; font-weight: 500; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
white-space: nowrap; padding: 7px 16px; border-radius: 999px;
background: var(--surface); border: 1px solid var(--border);
color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--chip-active-bg); border-color: var(--chip-active-bg); color: var(--chip-active-text); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.toolbar .result-count { color: var(--muted); font-size: 13px; }
select.sort {
background: var(--surface); color: var(--text); border: 1px solid var(--border);
border-radius: 8px; padding: 7px 10px; font-size: 13px; cursor: pointer; outline: none;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.card { cursor: pointer; text-decoration: none; color: inherit; display: block; }
.thumb {
position: relative; aspect-ratio: 16/9; border-radius: 12px; overflow: hidden;
background: var(--surface-2); border: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .placeholder {
width: 100%; height: 100%;
background: linear-gradient(135deg, #2a2a35, #1d1d26);
display: grid; place-items: center; color: var(--muted); font-size: 34px;
}
.thumb .play-overlay {
position: absolute; inset: 0; display: grid; place-items: center;
background: rgba(0,0,0,0.35); opacity: 0; transition: opacity .15s;
}
.card:hover .play-overlay { opacity: 1; }
.thumb .play-overlay .circle {
width: 52px; height: 52px; border-radius: 50%; background: rgba(255,82,82,0.95);
display: grid; place-items: center; color: #fff; font-size: 18px; padding-left: 3px;
}
.thumb .badge {
position: absolute; top: 8px; right: 8px;
background: rgba(0,0,0,0.75); color: #fff; font-size: 11px; font-weight: 700;
padding: 2px 7px; border-radius: 6px;
}
.thumb .progress {
position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: rgba(0,0,0,0.55);
}
.thumb .progress .fill { height: 100%; background: var(--accent); }
.thumb .progress .fill.done { background: var(--green); }
.fav-star {
position: absolute; top: 8px; left: 8px; font-size: 18px; color: #ffd54a;
filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6)); pointer-events: none;
}
.card .title {
margin-top: 9px; font-size: 14px; font-weight: 600; line-height: 1.35;
display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .meta { margin-top: 3px; font-size: 12px; color: var(--muted); }
.continue-strip { display: flex; gap: 14px; overflow-x: auto; padding: 4px 2px 16px; scrollbar-width: thin; margin-bottom: 8px; }
.continue-card { min-width: 250px; max-width: 250px; cursor: pointer; }
.watch-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: start; }
@media (max-width: 1100px) { .watch-layout { grid-template-columns: 1fr; } }
.player-wrap { border-radius: 14px; overflow: hidden; background: #000; border: 1px solid var(--border); }
.player-wrap video { width: 100%; display: block; max-height: 72vh; background: #000; }
.player-error { padding: 48px 24px; text-align: center; color: var(--muted); }
.watch-title { font-size: 22px; font-weight: 700; margin: 18px 0 6px; letter-spacing: -0.3px; }
.watch-meta { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.watch-meta a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--muted); }
.watch-meta a:hover { color: #fff; }
.watch-actions { display: flex; gap: 10px; margin-top: 14px; }
.btn.primary { background: var(--accent); color: #fff; padding: 9px 18px; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: var(--surface); border: 1px solid var(--border); }
.related h3 { font-size: 15px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 12px; }
.related-item { display: flex; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; color: inherit; text-decoration: none; }
.related-item:hover { background: var(--surface); }
.related-item img, .related-item .ph {
width: 96px; height: 54px; border-radius: 8px; object-fit: cover; flex-shrink: 0;
background: linear-gradient(135deg, #2a2a35, #1d1d26); display: grid; place-items: center; color: var(--muted);
}
.related-item .t { font-size: 13px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.related-item .m { font-size: 11px; color: var(--muted); margin-top: 4px; }
.history-row { display: flex; gap: 16px; padding: 12px; border-radius: 12px; cursor: pointer; color: inherit; text-decoration: none; border: 1px solid transparent; align-items: center; }
.history-row:hover { background: var(--surface); border-color: var(--border); }
.history-row .thumb { width: 180px; flex-shrink: 0; aspect-ratio: 16/9; }
.history-row .info { flex: 1; min-width: 0; }
.history-row .title { font-size: 14px; font-weight: 600; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-row .meta { font-size: 12px; color: var(--muted); }
.history-row .bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.history-row .bar .fill { height: 100%; background: var(--accent); }
.history-row .bar .fill.done { background: var(--green); }
.history-row .time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.load-more { display: block; margin: 28px auto; padding: 11px 30px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer; }
.load-more:hover { background: var(--surface-2); }
.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty .big { font-size: 42px; margin-bottom: 12px; }
.empty p { max-width: 420px; margin: 0 auto; }
.toast {
position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
background: var(--toast-bg); color: var(--text); border: 1px solid var(--border);
padding: 10px 22px; border-radius: 999px; font-size: 13px; z-index: 100;
box-shadow: 0 8px 24px rgba(0,0,0,0.4); opacity: 0; transition: opacity .25s; pointer-events: none;
}
.toast.show { opacity: 1; }
@media (max-width: 720px) {
header { padding: 10px 12px; gap: 10px; flex-wrap: wrap; }
main { padding: 14px; }
.grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.history-row .thumb { width: 120px; }
.continue-card { min-width: 190px; max-width: 190px; }
}
body.logged-out header { display: none; }
#user-area { display: flex; align-items: center; gap: 8px; }
#user-area .avatar {
width: 32px; height: 32px; border-radius: 50%;
background: linear-gradient(135deg, var(--accent), #b91c1c);
display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff;
}
#user-area .uname { font-size: 13px; font-weight: 600; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-btn {
position: absolute; top: 8px; left: 8px; z-index: 2;
width: 34px; height: 34px; border-radius: 50%;
background: rgba(0,0,0,0.55); color: #ffd54a; font-size: 17px; line-height: 1;
border: none; cursor: pointer; display: grid; place-items: center;
transition: transform .12s, background .12s;
}
.fav-btn:hover { transform: scale(1.15); background: rgba(0,0,0,0.75); }
.fav-btn.off { color: rgba(255,255,255,0.55); }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 50% -10%, #1d1d26, var(--bg)); }
.login-card {
width: min(400px, 100%); background: var(--surface);
border: 1px solid var(--border); border-radius: 18px; padding: 30px 28px;
box-shadow: 0 24px 60px rgba(0,0,0,0.45);
}
.login-card .logo { justify-content: center; margin-bottom: 18px; font-size: 22px; }
.login-card h1 { font-size: 20px; text-align: center; letter-spacing: -0.3px; }
.login-sub { color: var(--muted); font-size: 13px; text-align: center; margin: 6px 0 18px; }
.mode-toggle { display: flex; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.mode-toggle button {
flex: 1; padding: 8px; border: none; border-radius: 7px; cursor: pointer;
background: transparent; color: var(--muted); font-size: 13px; font-weight: 700;
}
.mode-toggle button.active { background: var(--chip-active-bg); color: var(--chip-active-text); }
.login-card input[type=text], .login-card input[type=password] {
width: 100%; padding: 11px 14px; margin-bottom: 10px;
background: var(--bg); border: 1px solid var(--border); border-radius: 9px;
color: var(--text); font-size: 14px; outline: none; transition: border-color .15s;
}
.login-card input:focus { border-color: var(--accent); }
.login-error { color: #ff7b7b; font-size: 13px; min-height: 18px; margin: 2px 0 8px; text-align: center; }
.login-submit { width: 100%; padding: 12px; font-size: 15px; border-radius: 10px; background: var(--accent); color: #fff; border: none; cursor: pointer; font-weight: 700; }
.login-submit:hover { background: var(--accent-hover); }
.login-submit:disabled { opacity: .6; cursor: default; }
[data-theme="light"] .thumb .placeholder,
[data-theme="light"] .related-item img,
[data-theme="light"] .related-item .ph {
background: linear-gradient(135deg, #e8e8f0, #d8d8e4);
color: #9a9aa8;
}
[data-theme="light"] .login-screen {
background: radial-gradient(1200px 600px at 50% -10%, #e3e3ee, var(--bg));
}
[data-theme="light"] .card:hover .play-overlay { background: rgba(0,0,0,0.25); }
[data-theme="light"] .player-wrap video { background: #000; }
#theme-toggle { font-size: 16px; padding: 8px 10px; }
.seg { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: none; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 13px; border-radius: 999px; cursor: pointer; transition: all .15s; }
.seg button.active { background: var(--chip-active-bg); color: var(--chip-active-text); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.stat-card .num { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; color: var(--text); }
.stat-card .lbl { font-size: 12px; color: var(--muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.6px; }
.chart-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin-bottom: 22px; }
.chart-wrap h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.7px; margin-bottom: 14px; }
.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 130px; }
.chart-bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; min-width: 0; }
.chart-bar .fill { width: 100%; max-width: 34px; background: linear-gradient(180deg, var(--accent), #b91c1c); border-radius: 6px 6px 3px 3px; min-height: 4px; }
.chart-bar .day { font-size: 10px; color: var(--muted); white-space: nowrap; }
.stats-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.stats-list { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.stats-list h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.7px; margin-bottom: 10px; }
.stats-item { display: flex; align-items: center; gap: 12px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.stats-item:last-child { border-bottom: none; }
.stats-item .rank { width: 22px; color: var(--muted); font-weight: 700; font-size: 13px; text-align: center; flex-shrink: 0; }
.stats-item .body { flex: 1; min-width: 0; }
.stats-item .t { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats-item .m { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stats-item .bar { height: 5px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.stats-item .bar .fill { height: 100%; background: var(--accent); border-radius: 999px; }
.stats-item .secs { font-size: 12px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.playlist-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; cursor: pointer; position: relative; transition: transform .12s, border-color .12s; }
.playlist-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.playlist-card .name { font-size: 15px; font-weight: 700; word-break: break-word; padding-right: 28px; }
.playlist-card .meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.playlist-card .del-btn { position: absolute; top: 10px; right: 10px; border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; padding: 4px 7px; border-radius: 7px; }
.playlist-card .del-btn:hover { color: var(--accent); background: var(--surface-2); }
.pl-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; }
.pl-row .num { width: 24px; color: var(--muted); font-weight: 700; text-align: center; flex-shrink: 0; }
.pl-row img, .pl-row .ph { width: 84px; height: 48px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: linear-gradient(135deg, #2a2a35, #1d1d26); display: grid; place-items: center; color: var(--muted); }
.pl-row .body { flex: 1; min-width: 0; cursor: pointer; }
.pl-row .t { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-row .m { font-size: 11px; color: var(--muted); margin-top: 3px; }
.pl-row .actions { display: flex; gap: 4px; flex-shrink: 0; }
.pl-row .actions button { border: none; background: var(--surface-2); color: var(--muted); width: 28px; height: 28px; border-radius: 7px; cursor: pointer; font-size: 12px; }
.pl-row .actions button:hover { color: var(--text); background: var(--border); }
.new-playlist-bar { display: flex; gap: 10px; margin-bottom: 18px; }
.new-playlist-bar input { flex: 1; padding: 11px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 14px; outline: none; }
.new-playlist-bar input:focus { border-color: var(--accent); }
.channel-stats { display: flex; gap: 22px; flex-wrap: wrap; margin: 10px 0 18px; font-size: 13px; color: var(--muted); }
.channel-stats .cs b { color: var(--text); font-weight: 700; }
.add-playlist-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-top: 12px; max-width: 420px; }
.add-playlist-panel .pl-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; margin-bottom: 10px; }
.add-playlist-panel .pl-item { display: flex; align-items: center; justify-content: space-between; padding: 7px 10px; border-radius: 8px; cursor: pointer; background: var(--surface-2); font-size: 13px; }
.add-playlist-panel .pl-item:hover { background: var(--border); }
.add-playlist-panel .pl-item .check { color: var(--green); font-weight: 700; }
.add-playlist-panel .new-pl { display: flex; gap: 8px; }
.add-playlist-panel .new-pl input { flex: 1; padding: 9px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; outline: none; }
.add-playlist-panel .new-pl button { border: none; background: var(--accent); color: #fff; padding: 9px 16px; border-radius: 8px; font-weight: 700; cursor: pointer; font-size: 13px; }
[data-theme="classic"] {
--bg: #c0c0c0;
--surface: #d4d4d4;
--surface-2: #ececec;
--border: #808080;
--text: #000000;
--muted: #333333;
--accent: #000080;
--accent-hover: #0000aa;
--green: #008000;
--header-bg: linear-gradient(180deg, #000080 0%, #1084d0 100%);
--toast-bg: #ffffe1;
--chip-active-bg: #000080;
--chip-active-text: #ffffff;
}
[data-theme="classic"] body { font-family: Arial, Helvetica, sans-serif; background: var(--bg); color: var(--text); }
[data-theme="classic"] * { border-radius: 0 !important; }
[data-theme="classic"] .play-overlay .circle,
[data-theme="classic"] .fav-btn { border-radius: 50% !important; }
[data-theme="classic"] header {
background: var(--header-bg);
border-bottom: 2px solid #ffffff;
box-shadow: none;
padding: 8px 16px;
}
[data-theme="classic"] .logo { color: #ffffff; font-weight: 900; text-transform: uppercase; letter-spacing: 1px; }
[data-theme="classic"] .logo .mark { background: #ffffff; color: #000080; border-radius: 0 !important; font-size: 16px; }
[data-theme="classic"] .search input {
background: #ffffff; color: #000000; border: 2px solid; border-color: #808080 #ffffff #ffffff #808080;
padding-left: 36px; font-family: "Courier New", monospace;
}
[data-theme="classic"] .search input::placeholder { color: #666666; }
[data-theme="classic"] .search .icon { color: #000080; font-size: 16px; }
[data-theme="classic"] nav a, [data-theme="classic"] .btn {
color: #ffffff; border: 2px solid; border-color: #ffffff #000080 #000080 #ffffff;
background: #c0c0c0; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; font-size: 12px;
}
[data-theme="classic"] nav a { padding: 6px 14px; }
[data-theme="classic"] nav a:hover, [data-theme="classic"] .btn:hover { background: #d4d4d4; color: #000080; }
[data-theme="classic"] nav a.active { background: #ffffff; border-color: #808080 #ffffff #ffffff #808080; color: #000080; }
[data-theme="classic"] .btn.icon-btn { padding: 6px 10px; font-size: 15px; }
[data-theme="classic"] .btn.primary { background: #000080; border-color: #ffffff #000040 #000040 #ffffff; color: #ffffff; }
[data-theme="classic"] .btn.primary:hover { background: #0000aa; }
[data-theme="classic"] .btn.ghost { background: #c0c0c0; border-color: #ffffff #808080 #808080 #ffffff; color: #000000; }
[data-theme="classic"] .btn:active { border-color: #808080 #ffffff #ffffff #808080; background: #b0b0b0; }
[data-theme="classic"] h2.section-title { color: #000080; text-transform: uppercase; letter-spacing: 1px; font-size: 17px; border-bottom: 2px solid #808080; padding-bottom: 6px; }
[data-theme="classic"] h2.section-title .count { color: #333333; }
[data-theme="classic"] .chip {
background: #c0c0c0; border: 2px solid; border-color: #ffffff #808080 #808080 #ffffff;
color: #000000; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; font-size: 11px; padding: 6px 14px;
}
[data-theme="classic"] .chip:hover { background: #d4d4d4; }
[data-theme="classic"] .chip.active { background: #000080; border-color: #808080 #ffffff #ffffff #808080; color: #ffffff; }
[data-theme="classic"] select.sort, [data-theme="classic"] .new-playlist-bar input,
[data-theme="classic"] .add-playlist-panel .new-pl input {
background: #ffffff; color: #000000; border: 2px solid; border-color: #808080 #ffffff #ffffff #808080; font-family: "Courier New", monospace;
}
[data-theme="classic"] .result-count { color: #000000; font-family: "Courier New", monospace; }
[data-theme="classic"] .card .title { color: #0000ee; text-decoration: underline; }
[data-theme="classic"] .card .meta, [data-theme="classic"] .related-item .m,
[data-theme="classic"] .history-row .meta, [data-theme="classic"] .stats-item .m { color: #333333; font-family: "Courier New", monospace; }
[data-theme="classic"] .thumb { border: 2px solid #808080; background: #ffffff; }
[data-theme="classic"] .thumb .placeholder { background: repeating-linear-gradient(45deg, #ececec 0 8px, #d4d4d4 8px 16px); color: #000080; }
[data-theme="classic"] .thumb .badge { background: #000080; color: #ffffff; border-radius: 0 !important; border: 1px solid #ffffff; font-family: "Courier New", monospace; }
[data-theme="classic"] .thumb .progress { height: 8px; background: #808080; border-top: 1px solid #000000; }
[data-theme="classic"] .thumb .progress .fill { background: #000080; border-right: 2px solid #ffffff; }
[data-theme="classic"] .thumb .progress .fill.done { background: #008000; }
[data-theme="classic"] .play-overlay { background: rgba(0,0,0,0.35); }
[data-theme="classic"] .play-overlay .circle { background: #000080; border: 2px solid #ffffff; }
[data-theme="classic"] .stat-card, [data-theme="classic"] .chart-wrap, [data-theme="classic"] .stats-list,
[data-theme="classic"] .playlist-card, [data-theme="classic"] .pl-row, [data-theme="classic"] .history-row,
[data-theme="classic"] .login-card, [data-theme="classic"] .add-playlist-panel, [data-theme="classic"] .watch-actions {
background: #d4d4d4; border: 2px solid; border-color: #ffffff #808080 #808080 #ffffff; color: #000000; box-shadow: none;
}
[data-theme="classic"] .stat-card .num { color: #000080; }
[data-theme="classic"] .stat-card .lbl, [data-theme="classic"] .chart-wrap h3, [data-theme="classic"] .stats-list h3 { color: #000080; text-transform: uppercase; letter-spacing: 0.8px; }
[data-theme="classic"] .chart-bar .fill { background: repeating-linear-gradient(180deg, #000080 0 6px, #1084d0 6px 12px); border: 1px solid #000000; }
[data-theme="classic"] .stats-item .bar { height: 8px; background: #ffffff; border: 1px solid #808080; }
[data-theme="classic"] .stats-item .bar .fill { background: #000080; }
[data-theme="classic"] .playlist-card .name, [data-theme="classic"] .pl-row .t, [data-theme="classic"] .history-row .title { color: #0000ee; text-decoration: underline; }
[data-theme="classic"] .playlist-card .meta, [data-theme="classic"] .pl-row .m, [data-theme="classic"] .history-row .time,
[data-theme="classic"] .stats-item .secs, [data-theme="classic"] .channel-stats { color: #333333; font-family: "Courier New", monospace; }
[data-theme="classic"] .pl-row .actions button, [data-theme="classic"] .playlist-card .del-btn { background: #c0c0c0; border: 2px solid; border-color: #ffffff #808080 #808080 #ffffff; color: #000000; }
[data-theme="classic"] .pl-row .actions button:hover { background: #d4d4d4; }
[data-theme="classic"] .new-playlist-bar input, [data-theme="classic"] .add-playlist-panel .new-pl input { color: #000000; }
[data-theme="classic"] .login-card .logo { color: #000080; font-weight: 900; text-transform: uppercase; letter-spacing: 1px; }
[data-theme="classic"] .login-card h1 { color: #000000; }
[data-theme="classic"] .mode-toggle { background: #c0c0c0; border: 2px solid; border-color: #808080 #ffffff #ffffff #808080; padding: 4px; }
[data-theme="classic"] .mode-toggle button.active { background: #000080; color: #ffffff; }
[data-theme="classic"] .login-card input[type=text], [data-theme="classic"] .login-card input[type=password] {
background: #ffffff; color: #000000; border: 2px solid; border-color: #808080 #ffffff #ffffff #808080; font-family: "Courier New", monospace;
}
[data-theme="classic"] .login-submit { background: #000080; color: #ffffff; border: 2px solid; border-color: #ffffff #000040 #000040 #ffffff; text-transform: uppercase; letter-spacing: 1px; }
[data-theme="classic"] .login-submit:hover { background: #0000aa; }
[data-theme="classic"] .login-error { color: #b00000; font-family: "Courier New", monospace; }
[data-theme="classic"] .history-row .bar, [data-theme="classic"] .pl-row .body { background: transparent; }
[data-theme="classic"] .history-row .bar { height: 8px; background: #ffffff; border: 1px solid #808080; }
[data-theme="classic"] .history-row .bar .fill { background: #000080; }
[data-theme="classic"] .history-row .bar .fill.done { background: #008000; }
[data-theme="classic"] .history-row:hover, [data-theme="classic"] .pl-row:hover, [data-theme="classic"] .related-item:hover { background: #ececec; border-color: #000080; }
[data-theme="classic"] .continue-card .title { color: #0000ee; text-decoration: underline; }
[data-theme="classic"] .watch-meta a { color: #0000ee; text-decoration: underline; }
[data-theme="classic"] .watch-title { color: #000080; font-weight: 900; text-transform: uppercase; letter-spacing: 0.5px; }
[data-theme="classic"] .related h3 { color: #000080; }
[data-theme="classic"] .seg { background: #c0c0c0; border: 2px solid; border-color: #808080 #ffffff #ffffff #808080; padding: 4px; }
[data-theme="classic"] .seg button { color: #000000; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; font-size: 11px; }
[data-theme="classic"] .seg button.active { background: #000080; color: #ffffff; }
[data-theme="classic"] .channel-stats b { color: #000080; }
[data-theme="classic"] #user-area .uname { color: #ffffff; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
[data-theme="classic"] #user-area .avatar { background: #ffffff; color: #000080; border: 2px solid #ffffff; border-radius: 0 !important; }
[data-theme="classic"] .toast { background: #ffffe1; color: #000000; border: 2px solid; border-color: #808080 #ffffff #ffffff #808080; font-family: "Courier New", monospace; }
[data-theme="classic"] .load-more { background: #c0c0c0; border: 2px solid; border-color: #ffffff #808080 #808080 #ffffff; color: #000000; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
[data-theme="classic"] .empty { color: #333333; }
[data-theme="classic"] .empty .big { filter: none; }
[data-theme="classic"] .player-wrap video { background: #000000; border: 3px solid #808080; }
[data-theme="classic"] .watch-actions { gap: 10px; padding: 12px; }
+35
View File
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Seantube — Local Video Library</title>
<script>try{var t=localStorage.getItem('vidhive_theme');if(!t){t=window.matchMedia&&window.matchMedia('(prefers-color-scheme: light)').matches?'light':'dark'}document.documentElement.setAttribute('data-theme',t)}catch(e){}</script>
<link rel="stylesheet" href="/css/styles.css">
</head>
<body class="logged-out">
<header id="app-header" style="display:none">
<a class="logo" href="#/">
<span class="mark">▶</span>
Seantube
</a>
<div class="search">
<span class="icon">⌕</span>
<input id="search-input" type="search" placeholder="Search videos or channels…" autocomplete="off" spellcheck="false">
</div>
<nav>
<a href="#/" data-nav="home">Home</a>
<a href="#/playlists" data-nav="playlists">Playlists</a>
<a href="#/favorites" data-nav="favorites">Favorites</a>
<a href="#/history" data-nav="history">History</a>
<a href="#/stats" data-nav="stats">Stats</a>
</nav>
<button class="btn icon-btn" id="rescan-btn" title="Rescan video folder">⟳</button>
<button class="btn icon-btn" id="theme-toggle" title="Toggle light/dark mode">🌙</button>
<div id="user-area"></div>
</header>
<main id="app"><div class="empty"><div class="big">…</div>Loading…</div></main>
<div class="toast" id="toast"></div>
<script src="/js/app.js"></script>
</body>
</html>
+830
View File
@@ -0,0 +1,830 @@
const app = document.getElementById('app');
const toastEl = document.getElementById('toast');
const searchInput = document.getElementById('search-input');
const body = document.body;
let toastTimer = null;
let currentUser = null;
let currentRoute = 'home';
let autoplayMode = localStorage.getItem('vidhive_autoplay') || 'off';
function setAutoplayMode(m) { autoplayMode = m; localStorage.setItem('vidhive_autoplay', m); }
let autoplayIntent = false;
const THEME_ORDER = ['dark', 'light', 'classic'];
const THEME_ICONS = { dark: '🌙', light: '☀️', classic: '🖥' };
const themeBtn = document.getElementById('theme-toggle');
function applyTheme(t) {
document.documentElement.setAttribute('data-theme', t);
if (themeBtn) {
themeBtn.textContent = THEME_ICONS[t] || '🌙';
const next = THEME_ORDER[(THEME_ORDER.indexOf(t) + 1) % THEME_ORDER.length];
themeBtn.title = `Theme: ${t} — click for ${next}`;
}
}
function initTheme() {
const stored = localStorage.getItem('vidhive_theme');
const prefersLight = window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches;
applyTheme(stored || (prefersLight ? 'light' : 'dark'));
}
if (themeBtn) themeBtn.addEventListener('click', () => {
const current = document.documentElement.getAttribute('data-theme') || 'dark';
const next = THEME_ORDER[(THEME_ORDER.indexOf(current) + 1) % THEME_ORDER.length];
localStorage.setItem('vidhive_theme', next);
applyTheme(next);
});
initTheme();
const state = {
q: '',
channel: null,
sort: 'newest',
offset: 0,
limit: 24,
total: 0,
};
function esc(s) {
return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
}
function fmtDur(sec) {
if (!sec || !isFinite(sec)) return '0:00';
sec = Math.floor(sec);
const h = Math.floor(sec / 3600), m = Math.floor((sec % 3600) / 60), s = sec % 60;
if (h > 0) return `${h}:${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`;
return `${m}:${String(s).padStart(2, '0')}`;
}
function fmtTime(sec) {
sec = Math.floor(sec || 0);
const h = Math.floor(sec / 3600), m = Math.floor((sec % 3600) / 60);
if (h > 0) return `${h}h ${m}m`;
if (m > 0) return `${m} min`;
return `${sec}s`;
}
function fmtDate(ts) {
if (!ts) return '';
const d = new Date(ts * 1000);
const diff = (Date.now() - d.getTime()) / 1000;
if (diff < 60) return 'just now';
if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;
if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`;
if (diff < 2592000) return `${Math.floor(diff / 86400)}d ago`;
return d.toLocaleDateString();
}
function fmtViews(n) {
if (!n) return '0 views';
if (n < 1000) return `${n} views`;
if (n < 1e6) return `${(n / 1000).toFixed(1).replace(/\.0$/, '')}k views`;
return `${(n / 1e6).toFixed(1)}M views`;
}
async function api(path, opts) {
const res = await fetch(path, opts);
if (res.status === 401) {
showLoginScreen();
throw new Error('Unauthorized');
}
if (!res.ok) {
let msg = `HTTP ${res.status}`;
try { const j = await res.json(); if (j && j.error) msg = j.error; } catch {}
throw new Error(msg);
}
return res.json();
}
function toast(msg) {
toastEl.textContent = msg;
toastEl.classList.add('show');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toastEl.classList.remove('show'), 2600);
}
async function getMe() {
const r = await fetch('/api/auth/me');
if (!r.ok) return null;
try { const j = await r.json(); return j.user || null; } catch { return null; }
}
function showLoginScreen() {
currentUser = null;
body.classList.add('logged-out');
document.getElementById('app-header').style.display = 'none';
app.innerHTML = `
<div class="login-screen">
<form class="login-card" id="login-form">
<div class="logo" style="justify-content:center;margin-bottom:18px"><span class="mark">▶</span> Seantube</div>
<h1 id="login-title">Welcome back</h1>
<p class="login-sub" id="login-sub">Sign in to your account</p>
<div class="mode-toggle">
<button type="button" id="mode-login" class="active">Log in</button>
<button type="button" id="mode-register">Create account</button>
</div>
<input type="text" id="login-username" placeholder="Username" autocomplete="username" autocapitalize="none" spellcheck="false" required>
<input type="password" id="login-password" placeholder="Password" autocomplete="current-password" required>
<p class="login-error" id="login-error"></p>
<button type="submit" class="login-submit" id="login-submit">Log in</button>
</form>
</div>`;
let authMode = 'login';
const titleEl = document.getElementById('login-title');
const subEl = document.getElementById('login-sub');
const submitEl = document.getElementById('login-submit');
const errEl = document.getElementById('login-error');
const setMode = (mode) => {
authMode = mode;
document.getElementById('mode-login').classList.toggle('active', mode === 'login');
document.getElementById('mode-register').classList.toggle('active', mode === 'register');
if (mode === 'login') {
titleEl.textContent = 'Welcome back'; subEl.textContent = 'Sign in to your account'; submitEl.textContent = 'Log in';
document.getElementById('login-password').autocomplete = 'current-password';
} else {
titleEl.textContent = 'Create account'; subEl.textContent = 'Pick a username and password (min 6 characters)'; submitEl.textContent = 'Create account';
document.getElementById('login-password').autocomplete = 'new-password';
}
errEl.textContent = '';
};
document.getElementById('mode-login').addEventListener('click', () => setMode('login'));
document.getElementById('mode-register').addEventListener('click', () => setMode('register'));
document.getElementById('login-form').addEventListener('submit', async (e) => {
e.preventDefault();
const username = document.getElementById('login-username').value.trim();
const password = document.getElementById('login-password').value;
errEl.textContent = '';
submitEl.disabled = true;
try {
const res = await fetch(`/api/auth/${authMode === 'login' ? 'login' : 'register'}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password }),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) { errEl.textContent = data.error || 'Something went wrong'; submitEl.disabled = false; return; }
currentUser = data.user;
if (location.hash !== '#/') { location.hash = '#/'; return; }
render();
} catch (err) {
errEl.textContent = 'Network error — is the server running?';
submitEl.disabled = false;
}
});
}
async function showApp(user) {
currentUser = user;
body.classList.remove('logged-out');
document.getElementById('app-header').style.display = '';
const initial = esc((user.username || '?').charAt(0).toUpperCase());
document.getElementById('user-area').innerHTML = `
<span class="avatar">${initial}</span>
<span class="uname" title="${esc(user.username)}">${esc(user.username)}</span>
<button id="logout-btn" class="btn icon-btn" title="Log out">⏻</button>`;
document.getElementById('logout-btn').addEventListener('click', async () => {
try { await fetch('/api/auth/logout', { method: 'POST' }); } catch {}
currentUser = null;
render();
});
const status = await api('/api/status').catch(() => null);
if (status && status.lastRescanAt) {
document.getElementById('rescan-btn').title = `Rescan video folder (last: ${fmtDate(Math.floor(new Date(status.lastRescanAt).getTime() / 1000))})`;
}
}
function cardHtml(v) {
const dur = fmtDur(v.duration);
const progress = v.watched_position > 0 && v.duration > 0 ? Math.min(1, v.watched_position / v.duration) : 0;
const done = v.watch_completed || (progress >= 0.9);
return `
<div class="card" data-href="#/watch/${v.id}">
<div class="thumb">
<img src="/thumb/${v.id}" alt="" loading="lazy" onerror="this.outerHTML='<div class=placeholder>▶</div>'">
<button class="fav-btn ${v.favorite ? '' : 'off'}" data-video-id="${v.id}" title="Toggle favorite">${v.favorite ? '★' : '☆'}</button>
<span class="badge">${dur}</span>
<div class="play-overlay"><div class="circle">▶</div></div>
${progress > 0 ? `<div class="progress"><div class="fill${done ? ' done' : ''}" style="width:${(progress * 100).toFixed(1)}%"></div></div>` : ''}
</div>
<div class="title">${esc(v.title)}</div>
<div class="meta">${esc(v.channel)} · ${fmtViews(v.views)}</div>
</div>`;
}
async function loadGrid() {
let url, noun;
if (currentRoute === 'favorites') {
url = `/api/favorites?limit=${state.limit}&offset=${state.offset}`;
noun = 'videos';
} else {
const q = state.q ? `&q=${encodeURIComponent(state.q)}` : '';
const ch = state.channel ? `&channel=${encodeURIComponent(state.channel)}` : '';
url = `/api/videos?limit=${state.limit}&offset=${state.offset}&sort=${encodeURIComponent(state.sort)}${q}${ch}`;
noun = state.q ? 'results' : 'videos';
}
try {
const data = await api(url);
state.total = data.total;
const grid = document.getElementById('video-grid');
const empty = document.getElementById('empty-msg');
if (state.offset === 0) {
if (data.videos.length === 0) {
grid.innerHTML = '';
empty.style.display = 'block';
} else {
empty.style.display = 'none';
grid.innerHTML = data.videos.map(cardHtml).join('');
}
} else {
data.videos.forEach(v => grid.insertAdjacentHTML('beforeend', cardHtml(v)));
}
const loadMoreBtn = document.getElementById('load-more');
if (loadMoreBtn) {
loadMoreBtn.style.display = state.offset + data.videos.length < state.total ? 'block' : 'none';
}
const countEl = document.getElementById('result-count');
if (countEl) countEl.textContent = `${state.total} ${noun}`;
} catch (err) {
if (err.message !== 'Unauthorized') toast('Failed to load videos: ' + err.message);
}
}
function wireGridControls() {
const sortSelect = document.getElementById('sort-select');
if (sortSelect) {
sortSelect.value = state.sort;
sortSelect.addEventListener('change', () => { state.sort = sortSelect.value; state.offset = 0; loadGrid(); });
}
const loadMoreBtn = document.getElementById('load-more');
if (loadMoreBtn) {
loadMoreBtn.addEventListener('click', () => { state.offset += state.limit; loadGrid(); });
}
}
async function renderHome() {
currentRoute = 'home';
const channels = await api('/api/channels').catch(() => []);
const historyItems = await api('/api/history?limit=8').catch(() => []);
const continueWatching = historyItems.filter(h => !h.completed && h.position > 0 && (h.duration || h.watch_duration) > 0 && h.position < (h.duration || h.watch_duration) * 0.95).slice(0, 8);
app.innerHTML = `
${continueWatching.length ? `
<h2 class="section-title">Continue watching</h2>
<div class="continue-strip">
${continueWatching.map(v => {
const dur = v.duration || v.watch_duration || 0;
const p = dur > 0 ? Math.min(1, v.position / dur) : 0;
return `<div class="card continue-card" data-href="#/watch/${v.id}">
<div class="thumb">
<img src="/thumb/${v.id}" alt="" loading="lazy" onerror="this.outerHTML='<div class=placeholder>▶</div>'">
<span class="badge">${fmtDur(v.duration)}</span>
<div class="progress"><div class="fill" style="width:${(p * 100).toFixed(1)}%"></div></div>
</div>
<div class="title">${esc(v.title)}</div>
<div class="meta">${fmtDate(v.watched_at)} · ${Math.round(p * 100)}% watched</div>
</div>`;
}).join('')}
</div>` : ''}
<h2 class="section-title">${state.q ? 'Search results' : 'All videos'}</h2>
<div class="toolbar">
<span class="result-count" id="result-count"></span>
<select class="sort" id="sort-select">
<option value="newest">Newest first</option>
<option value="oldest">Oldest first</option>
<option value="views">Most viewed</option>
<option value="recent">Recently watched</option>
<option value="az">Title A–Z</option>
</select>
</div>
<div class="chips" id="channel-chips">
<button class="chip ${!state.channel ? 'active' : ''}" data-channel="">All channels</button>
${channels.map(c => `<button class="chip ${state.channel === c.name ? 'active' : ''}" data-channel="${esc(c.name)}">${esc(c.name)} <span style="opacity:.55;font-weight:500">${c.count}</span></button>`).join('')}
</div>
<div class="grid" id="video-grid"></div>
<div class="empty" id="empty-msg" style="display:none">
<div class="big">🎬</div>
<p>${state.q ? 'No videos match your search.' : 'No videos found. Drop video files into the video folder and click ⟳ to rescan.'}</p>
</div>
<button class="load-more" id="load-more" style="display:none">Load more</button>`;
wireGridControls();
document.getElementById('channel-chips').addEventListener('click', (e) => {
const btn = e.target.closest('.chip');
if (!btn) return;
state.channel = btn.dataset.channel || null;
state.offset = 0;
renderHome();
});
await loadGrid();
}
async function renderChannel(name) {
currentRoute = 'channel';
const channels = await api('/api/channels').catch(() => []);
const channel = channels.find(c => c.name === name);
const stats = await api(`/api/channel/${encodeURIComponent(name)}/stats`).catch(() => null);
searchInput.value = '';
app.innerHTML = `
<div class="toolbar">
<h2 class="section-title" style="margin:0">${esc(name)}</h2>
<select class="sort" id="sort-select">
<option value="newest">Newest first</option>
<option value="oldest">Oldest first</option>
<option value="views">Most viewed</option>
<option value="recent">Recently watched</option>
<option value="az">Title A–Z</option>
</select>
</div>
${stats ? `<div class="channel-stats">
<span class="cs"><b>${stats.videos}</b> videos</span>
<span class="cs"><b>${fmtTime(stats.totalSeconds)}</b> total</span>
<span class="cs"><b>${fmtTime(stats.watchedSeconds)}</b> watched by you</span>
<span class="cs"><b>${stats.completedCount}</b> completed</span>
</div>` : ''}
<div class="grid" id="video-grid"></div>
<div class="empty" id="empty-msg" style="display:none">
<div class="big">📺</div><p>No videos in this channel yet.</p>
</div>
<button class="load-more" id="load-more" style="display:none">Load more</button>`;
state.channel = name;
state.q = '';
state.offset = 0;
wireGridControls();
await loadGrid();
}
async function renderFavorites() {
currentRoute = 'favorites';
searchInput.value = '';
app.innerHTML = `
<h2 class="section-title">Favorites <span class="count" id="result-count"></span></h2>
<div class="grid" id="video-grid"></div>
<div class="empty" id="empty-msg" style="display:none">
<div class="big">★</div><p>No favorites yet. Click the star on any video to add it here.</p>
</div>
<button class="load-more" id="load-more" style="display:none">Load more</button>`;
state.offset = 0;
wireGridControls();
await loadGrid();
}
async function renderHistory() {
currentRoute = 'history';
const items = await api('/api/history?limit=50').catch(() => []);
app.innerHTML = `
<h2 class="section-title">Watch history <span class="count">${items.length} videos</span></h2>
${items.length ? items.map(v => {
const p = v.duration > 0 ? Math.min(1, v.position / v.duration) : 0;
return `<a class="history-row" href="#/watch/${v.id}">
<div class="thumb">
<img src="/thumb/${v.id}" alt="" loading="lazy" onerror="this.outerHTML='<div class=placeholder>▶</div>'">
</div>
<div class="info">
<div class="title">${esc(v.title)}</div>
<div class="meta">${esc(v.channel)} · ${fmtDate(v.watched_at)}</div>
<div class="bar"><div class="fill${v.completed ? ' done' : ''}" style="width:${(p * 100).toFixed(1)}%"></div></div>
</div>
<div class="time">${v.completed ? '✓ Watched' : fmtDur(v.position) + ' / ' + fmtDur(v.duration || 0)}</div>
</a>`;
}).join('') : `<div class="empty"><div class="big">🕘</div><p>Nothing watched yet. Play something and it will show up here.</p></div>`}`;
}
async function renderPlaylists() {
currentRoute = 'playlists';
searchInput.value = '';
const playlists = await api('/api/playlists').catch(() => []);
app.innerHTML = `
<h2 class="section-title">Playlists <span class="count">${playlists.length}</span></h2>
<form class="new-playlist-bar" id="new-playlist-form">
<input id="new-playlist-name" type="text" placeholder="New playlist name…" maxlength="80" required>
<button class="btn primary" type="submit">Create</button>
</form>
<div class="grid" id="playlist-grid" style="grid-template-columns:repeat(auto-fill,minmax(240px,1fr))">
${playlists.map(p => `<div class="playlist-card" data-href="#/playlists/${p.id}">
<button class="del-btn" data-delete-playlist="${p.id}" title="Delete playlist">✕</button>
<div class="name">${esc(p.name)}</div>
<div class="meta">${p.count} video${p.count === 1 ? '' : 's'} · ${fmtDate(p.created_at)}</div>
</div>`).join('') || `<div class="empty" style="grid-column:1/-1;padding:44px"><div class="big">📋</div><p>No playlists yet. Create one above, then add videos from the watch page.</p></div>`}
</div>`;
document.getElementById('new-playlist-form').addEventListener('submit', async (e) => {
e.preventDefault();
const name = document.getElementById('new-playlist-name').value.trim();
if (!name) return;
try {
await api('/api/playlists', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name }) });
toast(`Created "${name}"`);
renderPlaylists();
} catch (err) { toast(err.message); }
});
app.querySelectorAll('[data-delete-playlist]').forEach(btn => btn.addEventListener('click', async (e) => {
e.stopPropagation();
if (!confirm('Delete this playlist? Videos are not deleted.')) return;
try {
await api(`/api/playlists/${btn.dataset.deletePlaylist}`, { method: 'DELETE' });
renderPlaylists();
} catch (err) { toast(err.message); }
}));
}
async function renderPlaylistDetail(id) {
currentRoute = 'playlists';
const data = await api(`/api/playlists/${id}`).catch(() => null);
if (!data) {
app.innerHTML = `<div class="empty"><div class="big">🚫</div><p>Playlist not found.</p></div>`;
return;
}
const { playlist, videos } = data;
app.innerHTML = `
<a href="#/playlists" style="color:var(--muted);text-decoration:none;font-size:13px">← All playlists</a>
<h2 class="section-title" style="margin-top:10px">${esc(playlist.name)} <span class="count">${videos.length} videos</span></h2>
${videos.length ? videos.map((v, i) => `<div class="pl-row" data-id="${v.id}">
<span class="num">${i + 1}</span>
<img src="/thumb/${v.id}" alt="" loading="lazy" onerror="this.outerHTML='<div class=ph>▶</div>'">
<div class="body" data-href="#/watch/${v.id}">
<div class="t">${esc(v.title)}</div>
<div class="m">${fmtDur(v.duration)} · ${fmtViews(v.views)}</div>
</div>
<div class="actions">
<button data-move="up" title="Move up" ${i === 0 ? 'disabled' : ''}>↑</button>
<button data-move="down" title="Move down" ${i === videos.length - 1 ? 'disabled' : ''}>↓</button>
<button data-remove title="Remove from playlist">✕</button>
</div>
</div>`).join('') : `<div class="empty"><div class="big">📋</div><p>This playlist is empty. Add videos from the watch page.</p></div>`}`;
const ids = videos.map(v => v.id);
app.querySelectorAll('.pl-row').forEach(row => {
const rowId = parseInt(row.dataset.id, 10);
const upBtn = row.querySelector('[data-move="up"]');
const downBtn = row.querySelector('[data-move="down"]');
const removeBtn = row.querySelector('[data-remove]');
const idx = ids.indexOf(rowId);
const move = (dir) => {
const j = idx + dir;
if (j < 0 || j >= ids.length) return;
[ids[idx], ids[j]] = [ids[j], ids[idx]];
api(`/api/playlists/${id}/reorder`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ video_ids: ids }) })
.then(() => renderPlaylistDetail(id))
.catch(err => toast(err.message));
};
if (upBtn) upBtn.addEventListener('click', () => move(-1));
if (downBtn) downBtn.addEventListener('click', () => move(1));
if (removeBtn) removeBtn.addEventListener('click', async () => {
try {
await api(`/api/playlists/${id}/items/${rowId}`, { method: 'DELETE' });
renderPlaylistDetail(id);
} catch (err) { toast(err.message); }
});
});
}
async function renderStats() {
currentRoute = 'stats';
searchInput.value = '';
const s = await api('/api/stats').catch(() => null);
if (!s) {
app.innerHTML = `<div class="empty"><div class="big">📊</div><p>Unable to load stats.</p></div>`;
return;
}
const maxSec = Math.max(1, ...s.daily.map(d => d.seconds));
const days = [];
for (let i = 13; i >= 0; i--) {
const d = new Date(Date.now() - i * 86400000);
days.push({ key: d.toISOString().slice(0, 10), label: d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' }), seconds: 0 });
}
const byDay = {};
s.daily.forEach(d => { byDay[d.day] = d.seconds; });
days.forEach(d => { d.seconds = byDay[d.key] || 0; });
const maxSecAll = Math.max(1, ...s.topChannels.map(c => c.seconds));
const maxVideosSec = Math.max(1, ...s.topVideos.map(v => v.seconds));
app.innerHTML = `
<h2 class="section-title">Watch stats</h2>
<div class="stats-grid">
<div class="stat-card"><div class="num">${fmtTime(s.totalSeconds)}</div><div class="lbl">Total watch time</div></div>
<div class="stat-card"><div class="num">${fmtTime(s.thisMonthSeconds)}</div><div class="lbl">This month</div></div>
<div class="stat-card"><div class="num">${s.startedCount}</div><div class="lbl">Videos started</div></div>
<div class="stat-card"><div class="num">${s.completedCount}</div><div class="lbl">Completed</div></div>
</div>
<div class="chart-wrap">
<h3>Last 14 days</h3>
<div class="chart-bars">
${days.map(d => `<div class="chart-bar" title="${d.key}: ${fmtTime(d.seconds)}">
<div class="fill" style="height:${Math.max(3, Math.round((d.seconds / maxSec) * 105))}px"></div>
<div class="day">${d.label}</div>
</div>`).join('')}
</div>
</div>
<div class="stats-cols">
<div class="stats-list">
<h3>Top channels</h3>
${s.topChannels.length ? s.topChannels.map((c, i) => `<div class="stats-item">
<span class="rank">${i + 1}</span>
<div class="body">
<div class="t">${esc(c.channel)}</div>
<div class="m">${c.videos} videos</div>
<div class="bar"><div class="fill" style="width:${((c.seconds / maxSecAll) * 100).toFixed(1)}%"></div></div>
</div>
<span class="secs">${fmtTime(c.seconds)}</span>
</div>`).join('') : '<p style="color:var(--muted);font-size:13px">No watch time yet.</p>'}
</div>
<div class="stats-list">
<h3>Top videos</h3>
${s.topVideos.length ? s.topVideos.map((v, i) => `<a class="stats-item" href="#/watch/${v.id}" style="text-decoration:none;color:inherit">
<span class="rank">${i + 1}</span>
<div class="body">
<div class="t">${esc(v.title)}</div>
<div class="m">${esc(v.channel)}</div>
<div class="bar"><div class="fill" style="width:${((v.seconds / maxVideosSec) * 100).toFixed(1)}%"></div></div>
</div>
<span class="secs">${fmtTime(v.seconds)}</span>
</a>`).join('') : '<p style="color:var(--muted);font-size:13px">No watch time yet.</p>'}
</div>
</div>`;
}
let playerCleanup = null;
async function renderWatch(id) {
currentRoute = 'watch';
const shouldAutoplay = autoplayIntent;
autoplayIntent = false;
const data = await api(`/api/video/${id}`).catch(() => null);
if (!data) {
app.innerHTML = `<div class="empty"><div class="big">🚫</div><p>Video not found or no longer in the library.</p></div>`;
return;
}
const v = data.video;
const history = data.history;
const fav = !!data.favorite;
app.innerHTML = `
<a href="#/" style="color:var(--muted);text-decoration:none;font-size:13px">← Back to library</a>
<div class="watch-layout">
<div>
<div class="player-wrap" id="player-wrap">
<video id="player" controls preload="metadata" src="/video/${v.id}"></video>
</div>
<h1 class="watch-title">${esc(v.title)}</h1>
<div class="watch-meta">
<a href="#/channel/${encodeURIComponent(v.channel)}">${esc(v.channel)}</a>
<span>${fmtViews(v.views)}</span>
<span>${fmtDur(v.duration)}</span>
</div>
<div class="watch-actions">
<button class="btn primary" id="fav-btn">${fav ? '★ Favorited' : '☆ Add to favorites'}</button>
<div class="seg" id="autoplay-seg" title="Autoplay next video">
<button data-mode="off" class="${autoplayMode === 'off' ? 'active' : ''}">Off</button>
<button data-mode="channel" class="${autoplayMode === 'channel' ? 'active' : ''}">Channel</button>
<button data-mode="random" class="${autoplayMode === 'random' ? 'active' : ''}">Random</button>
</div>
<button class="btn ghost" id="playlist-btn">+ Playlist</button>
</div>
<div class="add-playlist-panel" id="playlist-panel" style="display:none"></div>
</div>
<aside class="related">
<h3>More from ${esc(v.channel)}</h3>
<div id="related-list"></div>
</aside>
</div>`;
try { api('/api/view', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ video_id: v.id }) }); } catch {}
const player = document.getElementById('player');
const wrap = document.getElementById('player-wrap');
let resumeAt = 0;
if (history && history.position > 5 && !history.completed && v.duration > 0 && history.position < v.duration * 0.95) {
resumeAt = history.position;
}
let lastSave = -1;
const saveProgress = (force = false) => {
if (!player.duration || !isFinite(player.duration)) return;
const pos = player.currentTime;
if (!force && Math.abs(pos - lastSave) < 1 && lastSave >= 0) return;
lastSave = pos;
api('/api/progress', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ video_id: v.id, position: pos, duration: player.duration }) }).catch(() => {});
};
const onLoaded = () => {
if (resumeAt > 0 && !player.dataset.resumed) {
player.currentTime = resumeAt;
player.dataset.resumed = '1';
}
if (shouldAutoplay) {
player.play().catch(() => {});
}
};
player.addEventListener('loadedmetadata', onLoaded);
const interval = setInterval(saveProgress, 10000);
const onPause = () => saveProgress(true);
const startNext = async () => {
if (autoplayMode === 'off') return;
try {
const r = await api(`/api/videos/${v.id}/next?mode=${autoplayMode}`);
if (!r.video) return;
autoplayIntent = true;
location.hash = `#/watch/${r.video.id}`;
} catch {}
};
const onEnded = () => {
saveProgress(true);
api('/api/progress', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ video_id: v.id, position: player.duration, duration: player.duration }) }).catch(() => {});
startNext();
};
const onError = () => {
wrap.innerHTML = '<div class="player-error"><p>⚠ Unable to play this video. The file may be missing or unsupported.</p></div>';
};
player.addEventListener('pause', onPause);
player.addEventListener('ended', onEnded);
player.addEventListener('error', onError);
document.getElementById('autoplay-seg').addEventListener('click', (e) => {
const btn = e.target.closest('button[data-mode]');
if (!btn) return;
setAutoplayMode(btn.dataset.mode);
document.querySelectorAll('#autoplay-seg button').forEach(b => b.classList.toggle('active', b === btn));
});
const favBtn = document.getElementById('fav-btn');
favBtn.addEventListener('click', async () => {
try {
const r = await api('/api/favorite', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ video_id: v.id }) });
favBtn.textContent = r.favorite ? '★ Favorited' : '☆ Add to favorites';
toast(r.favorite ? 'Added to favorites' : 'Removed from favorites');
} catch (err) { if (err.message !== 'Unauthorized') toast('Error: ' + err.message); }
});
const panel = document.getElementById('playlist-panel');
const playlistBtn = document.getElementById('playlist-btn');
playlistBtn.addEventListener('click', async () => {
if (panel.style.display === 'none') {
panel.style.display = 'block';
await renderPlaylistPanel(panel, v.id);
} else {
panel.style.display = 'none';
}
});
playerCleanup = () => {
clearInterval(interval);
player.removeEventListener('loadedmetadata', onLoaded);
player.removeEventListener('pause', onPause);
player.removeEventListener('ended', onEnded);
player.removeEventListener('error', onError);
};
const related = await api(`/api/videos?channel=${encodeURIComponent(v.channel)}&sort=newest&limit=6`).catch(() => ({ videos: [] }));
const list = document.getElementById('related-list');
if (list) {
const others = related.videos.filter(x => x.id !== v.id).slice(0, 6);
list.innerHTML = others.length ? others.map(x => `
<a class="related-item" href="#/watch/${x.id}">
<img src="/thumb/${x.id}" alt="" loading="lazy" onerror="this.outerHTML='<div class=ph>▶</div>'">
<div><div class="t">${esc(x.title)}</div><div class="m">${fmtDur(x.duration)} · ${fmtViews(x.views)}</div></div>
</a>`).join('') : '<p style="color:var(--muted);font-size:13px">No other videos in this channel.</p>';
}
}
async function renderPlaylistPanel(panel, videoId) {
panel.innerHTML = '<div style="color:var(--muted);font-size:13px;padding:4px 2px">Loading playlists…</div>';
const playlists = await api('/api/playlists').catch(() => []);
const details = await Promise.all(playlists.map(async p => {
try {
const d = await api(`/api/playlists/${p.id}`);
return { ...p, videos: d.videos };
} catch { return { ...p, videos: [] }; }
}));
panel.innerHTML = `
<div class="pl-list">
${details.length ? details.map(p => `<div class="pl-item" data-playlist-id="${p.id}">
<span>${esc(p.name)} <span style="opacity:.55;font-weight:400">(${p.videos.length})</span></span>
<span class="check">${p.videos.some(x => x.id === videoId) ? '✓ In playlist' : ''}</span>
</div>`).join('') : '<p style="color:var(--muted);font-size:13px;padding:2px">No playlists yet — create one below.</p>'}
</div>
<form class="new-pl" id="panel-new-playlist">
<input type="text" id="panel-new-name" placeholder="New playlist name…" maxlength="80" required>
<button type="submit">Create</button>
</form>`;
panel.querySelectorAll('.pl-item').forEach(item => {
item.addEventListener('click', async () => {
const pid = parseInt(item.dataset.playlistId, 10);
const isMember = item.querySelector('.check').textContent.trim() !== '';
try {
if (isMember) {
await api(`/api/playlists/${pid}/items/${videoId}`, { method: 'DELETE' });
} else {
await api(`/api/playlists/${pid}/items`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ video_id: videoId }) });
}
await renderPlaylistPanel(panel, videoId);
} catch (err) { toast(err.message); }
});
});
panel.querySelector('#panel-new-playlist').addEventListener('submit', async (e) => {
e.preventDefault();
const name = document.getElementById('panel-new-name').value.trim();
if (!name) return;
try {
const r = await api('/api/playlists', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name }) });
await api(`/api/playlists/${r.id}/items`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ video_id: videoId }) });
await renderPlaylistPanel(panel, videoId);
} catch (err) { toast(err.message); }
});
}
async function render() {
const hash = location.hash.slice(2);
if (playerCleanup) { playerCleanup(); playerCleanup = null; }
const user = await getMe();
if (!user) { showLoginScreen(); return; }
showApp(user);
document.querySelectorAll('nav a[data-nav]').forEach(a => a.classList.toggle('active',
(hash === '' || hash === '/') && a.dataset.nav === 'home' ||
hash.startsWith('/playlists') && a.dataset.nav === 'playlists' ||
hash.startsWith('/favorites') && a.dataset.nav === 'favorites' ||
hash.startsWith('/history') && a.dataset.nav === 'history' ||
hash.startsWith('/stats') && a.dataset.nav === 'stats'));
const parts = hash.split('/').filter(Boolean);
if (parts[0] === 'channel' && parts[1]) {
await renderChannel(decodeURIComponent(parts.slice(1).join('/')));
} else if (parts[0] === 'watch' && parts[1]) {
await renderWatch(parseInt(parts[1], 10));
} else if (parts[0] === 'playlists' && parts[1]) {
await renderPlaylistDetail(parseInt(parts[1], 10));
} else if (parts[0] === 'playlists') {
await renderPlaylists();
} else if (parts[0] === 'favorites') {
state.q = ''; searchInput.value = '';
await renderFavorites();
} else if (parts[0] === 'history') {
await renderHistory();
} else if (parts[0] === 'stats') {
await renderStats();
} else {
currentRoute = 'home';
state.channel = null;
await renderHome();
}
}
app.addEventListener('click', (e) => {
const favBtn = e.target.closest('.fav-btn');
if (favBtn) {
e.preventDefault();
e.stopPropagation();
toggleFavoriteButton(favBtn);
return;
}
const link = e.target.closest('[data-href]');
if (link) {
e.preventDefault();
location.hash = link.dataset.href;
}
});
async function toggleFavoriteButton(btn) {
const id = parseInt(btn.dataset.videoId, 10);
try {
const r = await api('/api/favorite', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ video_id: id }) });
btn.classList.toggle('off', !r.favorite);
btn.textContent = r.favorite ? '★' : '☆';
toast(r.favorite ? 'Added to favorites' : 'Removed from favorites');
} catch (err) { if (err.message !== 'Unauthorized') toast('Error: ' + err.message); }
}
let searchTimer = null;
searchInput.addEventListener('input', () => {
clearTimeout(searchTimer);
searchTimer = setTimeout(() => {
state.q = searchInput.value.trim();
state.offset = 0;
if (location.hash !== '#/') {
location.hash = '#/';
} else {
renderHome();
}
}, 250);
});
document.getElementById('rescan-btn').addEventListener('click', async () => {
const btn = document.getElementById('rescan-btn');
btn.disabled = true; btn.textContent = '…';
try {
const r = await api('/api/rescan', { method: 'POST' });
toast(`Rescan done — ${r.added} added, ${r.updated} updated, ${r.removed} removed`);
render();
} catch (err) { if (err.message !== 'Unauthorized') toast('Rescan failed: ' + err.message); }
finally { btn.disabled = false; btn.textContent = '⟳'; }
});
window.addEventListener('hashchange', render);
render();