Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-08-06· OpenAIAi2 WildChat-4.8M (AI2)

window.inicializarAlerta = function () { window.originalAlert = window.alert;…

  1. User

    window.inicializarAlerta = function () { window.originalAlert = window.alert; window.originalConfirm = window.confirm;

    window.alert = (message) => {
        return showCustomNotification(message, 'alert');
    };
    
    window.confirm = (message) => {
        return showCustomNotification(message, 'confirm');
    };
    
    function showCustomNotification(message, type) {
        return new Promise((resolve) => {
            const notificationDiv = document.createElement('div');
            notificationDiv.className = `custom-notification${type === 'confirm' ? ' alertop' : ''}`;
    
            const contentDiv = document.createElement('div');
            contentDiv.className = 'notification-content';
            contentDiv.textContent = message;
            notificationDiv.appendChild(contentDiv);
    
            const modalBackground = document.getElementById('modalBackground2');
            if (modalBackground && type === 'confirm') {
                setTimeout(() => {
                    modalBackground.style.display = 'block';
                    modalBackground.style.visibility = 'visible';
                    modalBackground.style.opacity = '1';
                    modalBackground.style.zIndex = '9999';
                }, 0);
    
                modalBackground.onclick = () => {
                    closeNotification(false);
                };
            }
    
            if (type === 'confirm') {
                const buttonsDiv = document.createElement('div');
                buttonsDiv.className = 'notification-buttons';
    
                const confirmButton = document.createElement('button');
                confirmButton.textContent = 'Confirmar';
                confirmButton.onclick = () => {
                    closeNotification(true);
                };
    
                const cancelButton = document.createElement('button');
                cancelButton.textContent = 'Cancelar';
                cancelButton.onclick = () => {
                    closeNotification(false);
                };
    
                
                buttonsDiv.appendChild(cancelButton); // y este boton secundario
                buttonsDiv.appendChild(confirmButton); //necesito que este boton tenga la clase botonprincipal 
                notificationDiv.appendChild(buttonsDiv);
            } else {
                setTimeout(() => {
                    closeNotification();
                }, 3000);
            }
    
            document.body.appendChild(notificationDiv);
    
            function closeNotification(result) {
                if (notificationDiv) {
                    document.body.removeChild(notificationDiv);
                }
                if (modalBackground && type === 'confirm') {
                    modalBackground.style.display = 'none';
                    modalBackground.onclick = null;
                }
                resolve(result);
            }
        });
    }
    

    };

  2. Assistant

    To ensure that the 'Confirmar' button has the class botonprincipal, you need to modify the code where you create and configure the confirmButton. Here's how you can do that:

    window.inicializarAlerta = function () {
        window.originalAlert = window.alert;
        window.originalConfirm = window.confirm;
    
        window.alert = (message) => {
            return showCustomNotification(message, 'alert');
        };
    
        window.confirm = (message) => {
            return showCustomNotification(message, 'confirm');
        };
    
        function showCustomNotification(message, type) {
            return new Promise((resolve) => {
                const notificationDiv = document.createElement('div');
                notificationDiv.className = `custom-notification${type === 'confirm' ? ' alertop' : ''}`;
    
                const contentDiv = document.createElement('div');
                contentDiv.className = 'notification-content';
                contentDiv.textContent = message;
                notificationDiv.appendChild(contentDiv);
    
                const modalBackground = document.getElementById('modalBackground2');
                if (modalBackground && type === 'confirm') {
                    setTimeout(() => {
                        modalBackground.style.display = 'block';
                        modalBackground.style.visibility = 'visible';
                        modalBackground.style.opacity = '1';
                        modalBackground.style.zIndex = '9999';
                    }, 0);
    
                    modalBackground.onclick = () => {
                        closeNotification(false);
                    };
                }
    
                if (type === 'confirm') {
                    const buttonsDiv = document.createElement('div');
                    buttonsDiv.className = 'notification-buttons';
    
                    const confirmButton = document.createElement('button');
                    confirmButton.textContent = 'Confirmar';
                    confirmButton.className = 'botonprincipal'; // Add the class here
                    confirmButton.onclick = () => {
                        closeNotification(true);
                    };
    
                    const cancelButton = document.createElement('button');
                    cancelButton.textContent = 'Cancelar';
                    cancelButton.onclick = () => {
                        closeNotification(false);
                    };
    
                    buttonsDiv.appendChild(cancelButton); // Append cancel button
                    buttonsDiv.appendChild(confirmButton); // Append confirm button
    
                    notificationDiv.appendChild(buttonsDiv);
                } else {
                    setTimeout(() => {
                        closeNotification();
                    }, 3000);
                }
    
                document.body.appendChild(notificationDiv);
    
                function closeNotification(result) {
                    if (notificationDiv) {
                        document.body.removeChild(notificationDiv);
                    }
                    if (modalBackground && type === 'confirm') {
                        modalBackground.style.display = 'none';
                        modalBackground.onclick = null;
                    }
                    resolve(result);
                }
            });
        }
    };
    

    By adding confirmButton.className = 'botonprincipal';, you ensure that the 'Confirmar' button will be styled with the botonprincipal class, affecting its appearance according to your CSS styling for this class.