CoolFace
Apppublic

itamirabbas/green-canvas-studio

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
script.js132 linesDownload Raw Back to root
1// Shared JavaScript across all pages2console.log('MIDORI TEAM App loaded');3 4// Global state management5class AppState {6    constructor() {7        this.settings = {8            hardware: {9                use_gpu: true,10                max_threads: 'auto',11                vram_aware_tiling: true12            },13            conflict_policy_default: 'rename',14            locale: 'en',15            log_level: 'normal',16            remember_last_folders: true,17            telemetry: false18        };19        this.currentTool = null;20        this.progress = {21            overall: 0,22            current: 0,23            eta: 'Calculating...'24        };25    }26 27    // Method to update settings28    updateSettings(newSettings) {29        this.settings = { ...this.settings, ...newSettings };30        this.saveToLocalStorage();31    }32 33    // Save to localStorage34    saveToLocalStorage() {35        try {36            localStorage.setItem('midori-team-settings', JSON.stringify(this.settings));37        console.log('Settings saved to localStorage');38    }39 40    // Load from localStorage41    loadFromLocalStorage() {42        try {43            const saved = localStorage.getItem('midori-team-settings');44            if (saved) {45                this.settings = JSON.parse(saved);46                console.log('Settings loaded from localStorage');47            }48        } catch (error) {49            console.warn('Could not load settings from localStorage:', error);50        }51    }52}53 54// Initialize app state55const appState = new AppState();56appState.loadFromLocalStorage();57 58// Toast notification system59class ToastManager {60    constructor() {61        this.container = null;62        this.init();63    }64 65    init() {66        // Create toast container if it doesn't exist67        if (!document.getElementById('toast-container')) {68            this.container = document.createElement('div');69            this.container.id = 'toast-container';70            this.container.className = 'fixed top-4 right-4 z-50 space-y-2';71            document.body.appendChild(this.container);72        } else {73            this.container = document.getElementById('toast-container');74        }75    }76 77    show(message, type = 'success', duration = 5000) {78        if (!this.container) this.init();79 80        const toast = document.createElement('div');81        toast.className = `toast ${type} max-w-sm`;82        toast.innerHTML = `83            <div class="flex items-center justify-between">84                <span class="text-sm">${message}</span>85                <button onclick="this.parentElement.parentElement.remove()" class="text-[#F4F1E8]/60 hover:text-[#F4F1E8]">86                    <i data-feather="x" class="w-4 h-4"></i>87                </button>88            </div>89        `;90 91        this.container.appendChild(toast);92 93        // Auto remove after duration94        setTimeout(() => {95            if (toast.parentElement) {96                toast.remove();97            }98        }, duration);99 100        // Update feather icons101        feather.replace();102    }103}104 105// Initialize toast manager106const toastManager = new ToastManager();107 108// Global event handlers109document.addEventListener('DOMContentLoaded', function() {110    // Initialize all tooltips and interactive elements111    const tooltips = document.querySelectorAll('[data-tooltip]');112    113    tooltips.forEach(tooltip => {114        tooltip.addEventListener('mouseenter', function(e) {115            // Tooltip implementation can be added here116        });117    });118 119    // Handle global control buttons120    const controlButtons = document.querySelectorAll('.control-btn');121    controlButtons.forEach(button => {122        button.addEventListener('click', function() {123            const action = this.textContent.trim();124            console.log(`Global control: ${action}`);125            toastManager.show(`${action} action triggered`, 'success', 2000);126        });127    });128});129 130// Export for use in other modules131window.AppState = AppState;132window.toastManager = toastManager;