9f85908ff3
- Modernized the frontend with HTMX for server-driven UI and Alpine.js for client state. - Refactored anime, player, and recommendation logic into modular routers. - Updated README.md to reflect the latest project state and technologies (v2.4). - Added Plyr.io for an improved streaming experience. - Improved project structure with componentized templates. - Added Playwright and Vitest configuration for frontend testing.
46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
/**
|
|
* Main initialization and event handlers - Modernized for HTMX/Alpine
|
|
*/
|
|
|
|
// Initialize on DOM load
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
// Only keeping essential initializations
|
|
// Note: loadHomeContent() removed as it is now handled by hx-trigger="load"
|
|
|
|
// Initial download load
|
|
if (typeof loadDownloads === 'function') {
|
|
loadDownloads();
|
|
setInterval(loadDownloads, 2000);
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Switch between tabs (Modernized to Alpine.js)
|
|
*/
|
|
function switchTab(tabName) {
|
|
console.log('Switching tab to:', tabName);
|
|
window.dispatchEvent(new CustomEvent('set-tab', { detail: { tab: tabName } }));
|
|
window.location.hash = tabName;
|
|
}
|
|
|
|
// Handle URL hash on page load
|
|
if (window.location.hash) {
|
|
const hash = window.location.hash.substring(1);
|
|
const validTabs = ['home', 'watchlist', 'anime', 'series', 'providers', 'downloads'];
|
|
if (validTabs.includes(hash)) {
|
|
// Short delay to ensure Alpine is ready
|
|
setTimeout(() => switchTab(hash), 100);
|
|
}
|
|
}
|
|
|
|
// Listen for hash changes
|
|
window.addEventListener('hashchange', function() {
|
|
if (window.location.hash) {
|
|
const hash = window.location.hash.substring(1);
|
|
const validTabs = ['home', 'watchlist', 'anime', 'series', 'providers', 'downloads'];
|
|
if (validTabs.includes(hash)) {
|
|
switchTab(hash);
|
|
}
|
|
}
|
|
});
|