// Modern JavaScript Application - ES6+ with Modules class DownloadApplication { constructor() { this.config = this.loadInitialData(); this.components = new Map(); this.state = { ageVerified: this.config.session.age_verified, downloadCount: this.config.stats.download_count, isLoading: false }; this.initializeApplication(); } loadInitialData() { const scriptElement = document.getElementById('initial-data'); if (scriptElement) { try { return JSON.parse(scriptElement.textContent); } catch (error) { console.error('Failed to parse initial data:', error); } } return {}; } async initializeApplication() { try { // Initialize core modules await this.initializeModules(); // Render application this.render(); // Start background services this.startServices(); // Track application load this.analytics.track('application_loaded'); } catch (error) { console.error('Application initialization failed:', error); this.showError('خطا در بارگذاری برنامه'); } } async initializeModules() { // Core modules this.router = new Router(); this.stateManager = new StateManager(this.state); this.analytics = new AnalyticsService(this.config); this.uiManager = new UIManager(); this.downloadManager = new DownloadManager(); this.ageGateManager = new AgeGateManager(); // Register components this.registerComponents(); // Initialize modules await Promise.all([ this.router.initialize(), this.stateManager.initialize(), this.analytics.initialize() ]); } registerComponents() { this.components.set('banner', new BannerComponent()); this.components.set('download', new DownloadComponent()); this.components.set('age-gate', new AgeGateComponent()); this.components.set('toast', new ToastComponent()); this.components.set('debug', new DebugComponent()); } render() { const appElement = document.getElementById('app'); if (!appElement) return; appElement.innerHTML = this.generateHTML(); this.attachEventListeners(); } generateHTML() { return `
برای دسترسی به محتوا باید ۱۸ سال یا بیشتر داشته باشید
${JSON.stringify(config, null, 2)}