Download script.js from Serg434/ozonglow-theme-toggle-wizardry: direct link, hf CLI and curl.
- Browser
- Download file 8 kB
-
https://huggingface.co/spaces/Serg434/ozonglow-theme-toggle-wizardry/resolve/main/script.js
- Command line
-
hf download hf://spaces/Serg434/ozonglow-theme-toggle-wizardry/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Serg434/ozonglow-theme-toggle-wizardry/resolve/main/script.js
8 kB
| // OzonAuth MiniApp - Main JavaScript | |
| class OzonAuthApp { | |
| constructor() { | |
| this.init(); | |
| } | |
| init() { | |
| this.bindEvents(); | |
| this.setCurrentYear(); | |
| } | |
| bindEvents() { | |
| const form = document.getElementById('authForm'); | |
| if (form) { | |
| form.addEventListener('submit', this.handleSubmit.bind(this)); | |
| } | |
| } | |
| async handleSubmit(event) { | |
| event.preventDefault(); | |
| const formData = new FormData(event.target); | |
| const clientId = formData.get('clientId'); | |
| const apiKey = formData.get('apiKey'); | |
| // Show loading state | |
| this.showLoading(); | |
| try { | |
| // Simulate API validation (replace with actual Ozon API call) | |
| const isValid = await this.validateOzonCredentials(clientId, apiKey); | |
| if (isValid) { | |
| this.showSuccess('Авторизация успешна! Данные проверены.'); | |
| } else { | |
| this.showError('Ошибка авторизации. Проверьте Client ID и API Key.'); | |
| } | |
| } catch (error) { | |
| this.showError('Произошла ошибка при подключении: ' + error.message); | |
| } | |
| } | |
| async validateOzonCredentials(clientId, apiKey) { | |
| // Simulate API validation delay | |
| await new Promise(resolve => setTimeout(resolve, 1500)); | |
| // Basic validation (replace with actual Ozon API endpoint) | |
| if (clientId && apiKey && clientId.length >= 5 && apiKey.length >= 10) { | |
| // In a real app, you would make a request to Ozon API here | |
| // For demo purposes, we'll simulate success for valid-looking credentials | |
| return clientId.startsWith('ozon') || apiKey.includes('api'); | |
| } | |
| return false; | |
| } | |
| showLoading() { | |
| const resultDiv = document.getElementById('result'); | |
| const submitBtn = document.querySelector('button[type="submit"]'); | |
| // Disable button and show loading | |
| if (submitBtn) { | |
| submitBtn.disabled = true; | |
| submitBtn.innerHTML = ` | |
| <div class="flex items-center justify-center space-x-2"> | |
| <div class="w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin"></div> | |
| <span>Проверка...</span> | |
| </div> | |
| `; | |
| } | |
| if (resultDiv) { | |
| resultDiv.classList.add('hidden'); | |
| } | |
| } | |
| showSuccess(message) { | |
| this.showResult('success', 'Успех!', message); | |
| } | |
| showError(message) { | |
| this.showResult('error', 'Ошибка', message); | |
| } | |
| showResult(type, title, message) { | |
| const resultDiv = document.getElementById('result'); | |
| const resultContainer = resultDiv?.querySelector('div'); | |
| const resultTitle = document.getElementById('resultTitle'); | |
| const resultMessage = document.getElementById('resultMessage'); | |
| const submitBtn = document.querySelector('button[type="submit"]'); | |
| // Reset button | |
| if (submitBtn) { | |
| submitBtn.disabled = false; | |
| submitBtn.innerHTML = ` | |
| <div class="flex items-center justify-center space-x-3"> | |
| <i data-feather="send" class="w-5 h-5"></i> | |
| <span class="text-lg">Авторизоваться</span> | |
| </div> | |
| `; | |
| } | |
| // Update result display | |
| if (resultTitle) resultTitle.textContent = title; | |
| if (resultMessage) resultMessage.textContent = message; | |
| if (resultContainer) { | |
| // Remove existing classes and apply modern styles | |
| resultContainer.className = 'p-5 rounded-2xl border-2 glass'; | |
| if (type === 'success') { | |
| resultContainer.classList.add('success-border', 'success-bg'); | |
| if (resultTitle) resultTitle.classList.add('success-text', 'font-semibold'); | |
| if (resultMessage) resultMessage.classList.add('success-text'); | |
| } else { | |
| resultContainer.classList.add('error-border', 'error-bg'); | |
| if (resultTitle) resultTitle.classList.add('error-text', 'font-semibold'); | |
| if (resultMessage) resultMessage.classList.add('error-text'); | |
| } | |
| } | |
| if (resultDiv) { | |
| resultDiv.classList.remove('hidden'); | |
| resultDiv.classList.add('floating'); | |
| feather.replace(); | |
| // Auto-hide after 5 seconds with fade out | |
| setTimeout(() => { | |
| resultDiv.style.opacity = '0'; | |
| resultDiv.style.transform = 'translateY(-10px)'; | |
| setTimeout(() => { | |
| if (resultDiv) { | |
| resultDiv.classList.add('hidden'); | |
| resultDiv.style.opacity = '1'; | |
| resultDiv.style.transform = 'translateY(0)'; | |
| }, 300); | |
| }, 5000); | |
| } | |
| } | |
| } | |
| setCurrentYear() { | |
| const yearElement = document.getElementById('currentYear'); | |
| if (yearElement) { | |
| yearElement.textContent = new Date().getFullYear(); | |
| } | |
| } | |
| } | |
| // Theme management | |
| class ThemeManager { | |
| static init() { | |
| const themeToggle = document.getElementById('themeToggle'); | |
| if (themeToggle) { | |
| themeToggle.addEventListener('click', (event) => { | |
| this.handleThemeToggle(event); | |
| }); | |
| } | |
| this.updateThemeIcon(); | |
| } | |
| static handleThemeToggle(event) { | |
| const isDark = document.documentElement.classList.contains('dark'); | |
| // Toggle theme immediately | |
| document.documentElement.classList.toggle('dark'); | |
| localStorage.setItem('theme', !isDark ? 'dark' : 'light'); | |
| this.updateThemeIcon(); | |
| } | |
| static updateThemeIcon() { | |
| const themeToggle = document.getElementById('themeToggle'); | |
| const themeIcon = themeToggle?.querySelector('i'); | |
| if (themeIcon) { | |
| const isDark = document.documentElement.classList.contains('dark'); | |
| themeIcon.setAttribute('data-feather', isDark ? 'sun' : 'moon'); | |
| feather.replace(); | |
| } | |
| } | |
| } | |
| // Utility function for Telegram MiniApp integration | |
| class TelegramIntegration { | |
| static init() { | |
| // This would be replaced with actual Telegram MiniApp SDK integration | |
| if (window.Telegram && window.Telegram.WebApp) { | |
| const tg = window.Telegram.WebApp; | |
| // Expand the app to full height | |
| tg.expand(); | |
| // Set theme based on Telegram's theme | |
| if (tg.colorScheme === 'dark') { | |
| document.documentElement.classList.add('dark'); | |
| } else { | |
| document.documentElement.classList.remove('dark'); | |
| } | |
| // Handle theme changes from Telegram | |
| tg.onEvent('themeChanged', () => { | |
| if (tg.colorScheme === 'dark') { | |
| document.documentElement.classList.add('dark'); | |
| } else { | |
| document.documentElement.classList.remove('dark'); | |
| } | |
| ThemeManager.updateThemeIcon(); | |
| }); | |
| } | |
| } | |
| } | |
| // Initialize everything when DOM is loaded | |
| document.addEventListener('DOMContentLoaded', () => { | |
| new OzonAuthApp(); | |
| ThemeManager.init(); | |
| TelegramIntegration.init(); | |
| // Load saved theme | |
| const savedTheme = localStorage.getItem('theme'); | |
| const systemPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; | |
| if (savedTheme === 'dark' || (!savedTheme && systemPrefersDark)) { | |
| document.documentElement.classList.add('dark'); | |
| } | |
| ThemeManager.updateThemeIcon(); | |
| }); | |