kv-tube/templates/layout.html

579 lines
No EOL
22 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="KV-Tube">
<meta name="theme-color" content="#0f0f0f">
<title>KV-Tube</title>
<link rel="icon" type="image/svg+xml"
href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath fill='%23ff0000' d='M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm115.7 272l-176 101c-15.8 8.8-35.7-2.5-35.7-21V152c0-18.4 19.8-29.8 35.7-21l176 107c16.4 9.2 16.4 32.9 0 42z'/%3E%3C/svg%3E">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="{{ request.url }}">
<meta property="og:title" content="KV-Tube - Video Streaming">
<meta property="og:description" content="Stream your favorite videos on KV-Tube.">
<meta property="og:image" content="{{ url_for('static', filename='og-image.jpg', _external=True) }}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
<link rel="manifest" href="{{ url_for('static', filename='manifest.json') }}">
<script>
// Immediate Theme Init to prevent FOUC
(function () {
let savedTheme = localStorage.getItem('theme');
if (!savedTheme) {
const hour = new Date().getHours();
savedTheme = (hour >= 6 && hour < 18) ? 'light' : 'dark';
}
document.documentElement.setAttribute('data-theme', savedTheme);
})();
</script>
</head>
<body>
<div class="app-wrapper">
<!-- YouTube-style Header -->
<header class="yt-header">
<div class="yt-header-start">
<button class="yt-menu-btn" onclick="toggleSidebar()" aria-label="Menu">
<i class="fas fa-bars"></i>
</button>
<a href="/" class="yt-logo"
style="text-decoration: none; display: flex; align-items: center; gap: 4px;">
<span style="color: #ff0000; font-size: 24px;"><i class="fas fa-play-circle"></i></span>
<span
style="font-family: 'Roboto', sans-serif; font-weight: 700; font-size: 18px; letter-spacing: -0.5px; color: var(--yt-text-primary);">KV-Tube</span>
</a>
</div>
<div class="yt-header-center">
<form class="yt-search-form" action="/" method="get" onsubmit="handleSearch(event)">
<input type="text" id="searchInput" class="yt-search-input" placeholder="Search">
<button type="submit" class="yt-search-btn" aria-label="Search">
<i class="fas fa-search"></i>
</button>
</form>
</div>
<div class="yt-header-end">
<!-- Mobile Search Icon Removed - Search will be visible -->
<!-- <button class="yt-icon-btn yt-mobile-search" onclick="toggleMobileSearch()" aria-label="Search">
<i class="fas fa-search"></i>
</button> -->
{% if session.get('user_id') %}
<div class="yt-avatar" title="{{ session.username }}">
{{ session.username[0]|upper }}
</div>
{% else %}
<a href="/login" class="yt-signin-btn">
<i class="fas fa-user"></i>
<span class="yt-signin-text">Sign in</span>
</a>
{% endif %}
</div>
</header>
<!-- Mobile Search Bar -->
<div class="yt-mobile-search-bar" id="mobileSearchBar">
<button onclick="toggleMobileSearch()" class="yt-back-btn">
<i class="fas fa-arrow-left"></i>
</button>
<input type="text" id="mobileSearchInput" placeholder="Search"
onkeypress="if(event.key==='Enter'){searchYouTube(this.value);toggleMobileSearch();}">
</div>
<!-- YouTube-style Sidebar -->
<aside class="yt-sidebar" id="sidebar">
<a href="/" class="yt-sidebar-item {% if request.path == '/' %}active{% endif %}" data-category="all">
<i class="fas fa-home"></i>
<span>Home</span>
</a>
<a href="javascript:void(0)" class="yt-sidebar-item" data-category="shorts"
onclick="navigateCategory('shorts')">
<i class="fas fa-bolt"></i>
<span>Shorts</span>
</a>
<div class="yt-sidebar-divider"></div>
<a href="/my-videos?type=history" class="yt-sidebar-item" data-category="history">
<i class="fas fa-history"></i>
<span>History</span>
</a>
<a href="/my-videos?type=saved"
class="yt-sidebar-item {% if request.path == '/my-videos' %}active{% endif %}" data-category="saved">
<i class="fas fa-bookmark"></i>
<span>Library</span>
</a>
<!-- Queue Removed -->
<div class="yt-sidebar-divider"></div>
<div class="yt-sidebar-title">Explore</div>
<a href="javascript:void(0)" class="yt-sidebar-item" data-category="tech"
onclick="navigateCategory('tech')">
<i class="fas fa-microchip"></i>
<span>AI & Tech</span>
</a>
<a href="javascript:void(0)" class="yt-sidebar-item" data-category="trending"
onclick="navigateCategory('trending')">
<i class="fas fa-fire"></i>
<span>Trending</span>
</a>
<a href="javascript:void(0)" class="yt-sidebar-item" data-category="music"
onclick="navigateCategory('music')">
<i class="fas fa-music"></i>
<span>Music</span>
</a>
<a href="javascript:void(0)" class="yt-sidebar-item" data-category="gaming"
onclick="navigateCategory('gaming')">
<i class="fas fa-gamepad"></i>
<span>Gaming</span>
</a>
<a href="javascript:void(0)" class="yt-sidebar-item" data-category="news"
onclick="navigateCategory('news')">
<i class="fas fa-newspaper"></i>
<span>News</span>
</a>
<a href="javascript:void(0)" class="yt-sidebar-item" data-category="sports"
onclick="navigateCategory('sports')">
<i class="fas fa-football-ball"></i>
<span>Sports</span>
</a>
<div class="yt-sidebar-divider"></div>
<a href="/settings" class="yt-sidebar-item {% if request.path == '/settings' %}active{% endif %}">
<i class="fas fa-cog"></i>
<span>Settings</span>
</a>
{% if session.get('user_id') %}
<a href="/logout" class="yt-sidebar-item">
<i class="fas fa-sign-out-alt"></i>
<span>Sign out</span>
</a>
{% endif %}
</aside>
<!-- Sidebar Overlay (Mobile) -->
<div class="yt-sidebar-overlay" id="sidebarOverlay" onclick="closeSidebar()"></div>
<!-- Main Content -->
<main class="yt-main" id="mainContent">
{% block content %}{% endblock %}
</main>
<!-- Floating Back Button (Mobile) -->
<button id="floatingBackBtn" class="yt-floating-back" onclick="history.back()" aria-label="Go Back">
<i class="fas fa-arrow-left"></i>
</button>
</div>
<script src="{{ url_for('static', filename='js/main.js') }}"></script>
<script>
// Register Service Worker
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('{{ url_for("static", filename="sw.js") }}')
.then(registration => {
console.log('ServiceWorker registration successful');
})
.catch(err => {
console.log('ServiceWorker registration failed: ', err);
});
});
}
// Add to Home Screen prompt
let deferredPrompt;
const addBtn = document.querySelector('.add-button');
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
// Stash the event so it can be triggered later
deferredPrompt = e;
// Show the button
if (addBtn) addBtn.style.display = 'block';
// Show the install button if it exists
const installButton = document.getElementById('install-button');
if (installButton) {
installButton.style.display = 'block';
installButton.addEventListener('click', () => {
// Show the prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the install prompt');
} else {
console.log('User dismissed the install prompt');
}
deferredPrompt = null;
});
});
}
});
// Sidebar toggle
function toggleSidebar() {
const sidebar = document.getElementById('sidebar');
const main = document.getElementById('mainContent');
const overlay = document.getElementById('sidebarOverlay');
if (window.innerWidth <= 1024) {
sidebar.classList.toggle('open');
overlay.classList.toggle('active');
} else {
sidebar.classList.toggle('collapsed');
main.classList.toggle('sidebar-collapsed');
localStorage.setItem('sidebarCollapsed', sidebar.classList.contains('collapsed'));
}
}
function closeSidebar() {
document.getElementById('sidebar').classList.remove('open');
document.getElementById('sidebarOverlay').classList.remove('active');
}
// Restore sidebar state (desktop only)
if (window.innerWidth > 1024 && localStorage.getItem('sidebarCollapsed') === 'true') {
document.getElementById('sidebar').classList.add('collapsed');
document.getElementById('mainContent').classList.add('sidebar-collapsed');
}
// Mobile search toggle
function toggleMobileSearch() {
const searchBar = document.getElementById('mobileSearchBar');
searchBar.classList.toggle('active');
if (searchBar.classList.contains('active')) {
document.getElementById('mobileSearchInput').focus();
}
}
// Search handler
function handleSearch(e) {
e.preventDefault();
const query = document.getElementById('searchInput').value.trim();
if (query && typeof searchYouTube === 'function') {
searchYouTube(query);
}
}
// Navigate to category (syncs sidebar with top pills)
function navigateCategory(category) {
// Close mobile sidebar
closeSidebar();
// If on home page, trigger category switch
if (window.location.pathname === '/') {
const pill = document.querySelector(`.yt-category-pill[data-category="${category}"]`);
if (pill) {
pill.click();
} else if (typeof switchCategory === 'function') {
// Create a mock button for the function
const pills = document.querySelectorAll('.yt-category-pill');
pills.forEach(p => p.classList.remove('active'));
switchCategory(category, { classList: { add: () => { } } });
}
} else {
// Navigate to home with category
window.location.href = `/?category=${category}`;
}
}
</script>
<!-- Toast Notification Container -->
<div id="toastContainer" class="yt-toast-container"></div>
<!-- Queue Drawer -->
<div class="yt-queue-drawer" id="queueDrawer">
<div class="yt-queue-header">
<h3>Queue (<span id="queueCount">0</span>)</h3>
<button onclick="toggleQueue()" class="yt-icon-btn"><i class="fas fa-times"></i></button>
</div>
<div class="yt-queue-list" id="queueList">
<!-- Queued items -->
</div>
<div class="yt-queue-footer">
<button class="yt-queue-clear-btn" onclick="clearQueue()">Clear Queue</button>
</div>
</div>
<div class="yt-queue-overlay" id="queueOverlay" onclick="toggleQueue()"></div>
<style>
.yt-toast-container {
position: fixed;
bottom: 24px;
left: 24px;
z-index: 9999;
display: flex;
flex-direction: column;
gap: 12px;
pointer-events: none;
}
.yt-toast {
background: #1f1f1f;
color: #fff;
padding: 12px 24px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
font-size: 14px;
animation: slideUp 0.3s ease;
pointer-events: auto;
display: flex;
align-items: center;
gap: 12px;
min-width: 280px;
border-left: 4px solid #3ea6ff;
}
.yt-toast.error {
border-left-color: #ff4e45;
}
.yt-toast.success {
border-left-color: #2ba640;
}
@keyframes slideUp {
from {
transform: translateY(100%);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
</style>
<script>
function showToast(message, type = 'info') {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = `yt-toast ${type}`;
toast.innerHTML = `<span>${message}</span>`;
container.appendChild(toast);
// Remove after 3 seconds
setTimeout(() => {
toast.style.opacity = '0';
toast.style.transform = 'translateY(20px)';
toast.style.transition = 'all 0.3s';
setTimeout(() => toast.remove(), 300);
}, 5000);
}
// --- Queue Logic ---
function toggleQueue() {
const drawer = document.getElementById('queueDrawer');
const overlay = document.getElementById('queueOverlay');
if (drawer.classList.contains('open')) {
drawer.classList.remove('open');
overlay.classList.remove('active');
} else {
drawer.classList.add('open');
overlay.classList.add('active');
renderQueue();
}
}
function renderQueue() {
const list = document.getElementById('queueList');
const queue = JSON.parse(localStorage.getItem('kv_queue') || '[]');
document.getElementById('queueCount').innerText = queue.length;
if (queue.length === 0) {
list.innerHTML = '<p style="padding:20px; text-align:center; color:var(--yt-text-secondary);">Queue is empty</p>';
return;
}
list.innerHTML = queue.map((item, index) => `
<div class="yt-queue-item">
<div class="yt-queue-thumb" onclick="window.location.href='/watch?v=${item.id}'">
<img src="${item.thumbnail}" loading="lazy">
</div>
<div class="yt-queue-info">
<div class="yt-queue-title" onclick="window.location.href='/watch?v=${item.id}'">${item.title}</div>
<div class="yt-queue-uploader">${item.uploader}</div>
</div>
<button class="yt-queue-remove" onclick="removeFromQueue(${index})">
<i class="fas fa-trash"></i>
</button>
</div>
`).join('');
}
function removeFromQueue(index) {
let queue = JSON.parse(localStorage.getItem('kv_queue') || '[]');
queue.splice(index, 1);
localStorage.setItem('kv_queue', JSON.stringify(queue));
renderQueue();
}
function clearQueue() {
// Removed confirmation as requested
localStorage.removeItem('kv_queue');
renderQueue();
showToast("Queue cleared", "success");
}
// --- Back Button Logic ---
// Back Button Logic Removed (Handled Server-Side)
</script>
<style>
/* Queue Drawer Styles */
.yt-queue-drawer {
position: fixed;
top: 0;
right: -350px;
width: 350px;
height: 100vh;
background: var(--yt-bg-secondary);
z-index: 10000;
transition: right 0.3s ease;
display: flex;
flex-direction: column;
/* Shadow removed here to prevent bleeding when closed */
box-shadow: none;
}
.yt-queue-drawer.open {
right: 0;
box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
/* Apply shadow only when open */
}
.yt-queue-header {
padding: 16px;
border-bottom: 1px solid var(--yt-border);
display: flex;
justify-content: space-between;
align-items: center;
}
.yt-queue-header h3 {
font-size: 18px;
font-weight: 600;
}
.yt-queue-list {
flex: 1;
overflow-y: auto;
padding: 16px;
}
.yt-queue-footer {
padding: 16px;
border-top: 1px solid var(--yt-border);
text-align: center;
}
.yt-queue-clear-btn {
background: transparent;
border: 1px solid var(--yt-border);
color: var(--yt-text-primary);
padding: 8px 16px;
border-radius: 18px;
cursor: pointer;
}
.yt-queue-clear-btn:hover {
background: var(--yt-bg-hover);
}
.yt-queue-item {
display: flex;
gap: 12px;
margin-bottom: 12px;
align-items: center;
}
.yt-queue-thumb {
width: 100px;
height: 56px;
border-radius: 8px;
overflow: hidden;
cursor: pointer;
flex-shrink: 0;
}
.yt-queue-thumb img {
width: 100%;
height: 100%;
object-fit: cover;
}
.yt-queue-info {
flex: 1;
overflow: hidden;
}
.yt-queue-title {
font-size: 14px;
font-weight: 500;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
}
.yt-queue-title:hover {
text-decoration: underline;
}
.yt-queue-uploader {
font-size: 12px;
color: var(--yt-text-secondary);
}
.yt-queue-remove {
background: none;
border: none;
color: var(--yt-text-secondary);
cursor: pointer;
padding: 4px;
}
.yt-queue-remove:hover {
color: #ff4e45;
}
.yt-queue-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 9999;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s;
}
.yt-queue-overlay.active {
opacity: 1;
pointer-events: auto;
}
@media (max-width: 480px) {
.yt-queue-drawer {
width: 85%;
right: -85%;
}
}
</style>
</html>