Estoy trabajando con un complemento jQuery llamado Notify.js. El complemento crea mensajes en el DOM y los elimina al hacer clic.
He creado un botón que eliminará todos los mensajes. El botón solo debe existir cuando hay más de dos mensajes.
Agregué un MutationObserver para verificar si el contenedor de mensajes tiene <3 hijos y, de ser así, se debe eliminar el botón.
Eso funciona bien en Edge, Firefox y Opera, pero no en Chrome.
Después de cancelar las Opciones de Chrome para acelerar el hardware y permitir que los programas funcionen en segundo plano, la función funciona en mi computadora, pero no para mis compañeros de equipo.
La ayuda sería muy apreciada.
function message(text, type, obj_id) { var auto_hide = true; var auto_hide_delay = 10000; if (type == "error") { auto_hide_delay = 60000; } var notify_properties = { clickToHide: true, autoHide: auto_hide, autoHideDelay: auto_hide_delay, elementPosition: "bottom center", globalPosition: "bottom left", className: type, showAnimation: "slideDown", showDuration: 400, hideAnimation: "slideUp", hideDuration: 200, gap: 2, }; handle_close_all_messges(); if (obj_id == undefined || $("#" + obj_id).length == 0) { $.notify(text, notify_properties); } else { $("#" + obj_id).notify(text, notify_properties); } } function handle_close_all_messges() { const notifyjs = document.querySelector('.notifyjs-corner'); if (notifyjs && notifyjs.childElementCount > 2) { create_notifyjs_observer(); create_messages_container(); create_close_all_msgs_btn(); add_notifyjs_to_container(); } } function create_notifyjs_observer() { if (document.querySelector('.messages-container')) { return; } const MutationObserver = window.MutationObserver || window.WebKitMutationObserver; const observer = new MutationObserver(onMutationObserved); const notifyjs = document.querySelector('.notifyjs-corner'); const options = { childList: true, subtree: true }; observer.observe(notifyjs, options); } function onMutationObserved (mutations_list) { for (let mutation of mutations_list) { if (mutation.type === 'childList') { const notifyjs = document.querySelector('.notifyjs-corner'); if (notifyjs && notifyjs.childElementCount < 3) { delete_close_all_msgs_btn(); } } } }Enlace al código completo: https://jsfiddle.net/a5eLpq4z/