CoolFace
Apppublic

pppppppp100/deepsite-project-bf5tl

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
script.js171 linesDownload Raw Back to root
1// Global utility functions for BNP Paribas Banking App2 3// Format currency4function formatCurrency(amount, currency = 'EUR') {5    return new Intl.NumberFormat('fr-FR', {6        style: 'currency',7        currency: currency,8        minimumFractionDigits: 29    }).format(amount);10}11 12// Format date13function formatDate(date) {14    return new Intl.DateTimeFormat('fr-FR', {15        day: '2-digit',16        month: '2-digit',17        year: 'numeric'18    }).format(new Date(date));19}20 21// Mask sensitive data22function maskString(str, showLast = 4) {23    if (str.length <= showLast) return str;24    return '•'.repeat(str.length - showLast) + str.slice(-showLast);25}26 27// Generate random transaction ID28function generateTransactionId() {29    return 'TXN' + Date.now() + Math.random().toString(36).substr(2, 9).toUpperCase();30}31 32// Validate IBAN (basic check)33function validateIBAN(iban) {34    const regex = /^[A-Z]{2}\d{2}[A-Z0-9]{4}\d{7}([A-Z0-9]?){0,16}$/;35    return regex.test(iban.replace(/\s/g, ''));36}37 38// Session management39const SessionManager = {40    set(key, value) {41        sessionStorage.setItem(key, JSON.stringify(value));42    },43    get(key) {44        const item = sessionStorage.getItem(key);45        return item ? JSON.parse(item) : null;46    },47    remove(key) {48        sessionStorage.removeItem(key);49    },50    clear() {51        sessionStorage.clear();52    }53};54 55// Toast notification system56function showToast(message, type = 'info', duration = 3000) {57    const toast = document.createElement('div');58    const colors = {59        success: 'bg-green-500',60        error: 'bg-red-500',61        warning: 'bg-yellow-500',62        info: 'bg-blue-500'63    };64    65    toast.className = `fixed bottom-4 right-4 ${colors[type]} text-white px-6 py-3 rounded-lg shadow-lg transform translate-y-20 opacity-0 transition-all duration-300 z-50 flex items-center space-x-2`;66    toast.innerHTML = `67        <i data-lucide="${type === 'success' ? 'check-circle' : type === 'error' ? 'x-circle' : 'info'}"></i>68        <span>${message}</span>69    `;70    71    document.body.appendChild(toast);72    lucide.createIcons();73    74    // Animate in75    requestAnimationFrame(() => {76        toast.classList.remove('translate-y-20', 'opacity-0');77    });78    79    // Remove after duration80    setTimeout(() => {81        toast.classList.add('translate-y-20', 'opacity-0');82        setTimeout(() => toast.remove(), 300);83    }, duration);84}85 86// Loading spinner87function showLoading(element, text = 'Chargement...') {88    const originalContent = element.innerHTML;89    element.innerHTML = `90        <div class="flex items-center justify-center space-x-2">91            <div class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"></div>92            <span>${text}</span>93        </div>94    `;95    element.disabled = true;96    return () => {97        element.innerHTML = originalContent;98        element.disabled = false;99    };100}101 102// Debounce function103function debounce(func, wait) {104    let timeout;105    return function executedFunction(...args) {106        const later = () => {107            clearTimeout(timeout);108            func(...args);109        };110        clearTimeout(timeout);111        timeout = setTimeout(later, wait);112    };113}114 115// Local storage wrapper with expiry116const StorageWithExpiry = {117    set(key, value, ttl) {118        const now = new Date();119        const item = {120            value: value,121            expiry: now.getTime() + ttl,122        };123        localStorage.setItem(key, JSON.stringify(item));124    },125    get(key) {126        const itemStr = localStorage.getItem(key);127        if (!itemStr) return null;128        const item = JSON.parse(itemStr);129        const now = new Date();130        if (now.getTime() > item.expiry) {131            localStorage.removeItem(key);132            return null;133        }134        return item.value;135    }136};137 138// Security: Clear sensitive data on unload139window.addEventListener('beforeunload', () => {140    // Optional: clear specific session data if needed141    // SessionManager.remove('tempData');142});143 144// Prevent right click on sensitive elements (optional security)145document.addEventListener('contextmenu', (e) => {146    if (e.target.classList.contains('sensitive')) {147        e.preventDefault();148        showToast('Cette information est sensible', 'warning');149    }150});151 152// Auto logout after inactivity (30 minutes)153let inactivityTimer;154function resetInactivityTimer() {155    clearTimeout(inactivityTimer);156    inactivityTimer = setTimeout(() => {157        if (sessionStorage.getItem('authenticated')) {158            sessionStorage.removeItem('authenticated');159            window.location.href = 'index.html';160            alert('Session expirée pour inactivité.');161        }162    }, 30 * 60 * 1000); // 30 minutes163}164 165['mousedown', 'keydown', 'touchstart', 'scroll'].forEach(event => {166    document.addEventListener(event, resetInactivityTimer);167});168 169resetInactivityTimer();170 171console.log('BNP Paribas Banking App initialized');