Skip to content

Commit

Permalink
inline_message: add an extra mutation observer for when the msg_text_…
Browse files Browse the repository at this point in the history
…inner element shows up in the DOM right after its parent msg_text
  • Loading branch information
mercihabam authored and josaphatim committed May 22, 2024
1 parent 4149028 commit d1c727e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
19 changes: 19 additions & 0 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -2578,3 +2578,22 @@ const handleExternalResources = (inline) => {

document.querySelector('.external_notices').insertAdjacentElement('beforebegin', noticesElement);
};

const observeMessageTextMutationAndHandleExternalResources = (inline) => {
const message = document.querySelector('.msg_text');
if (message) {
new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(function (node) {
if (node.classList.contains('msg_text_inner')) {
handleExternalResources(inline);
}
});
}
});
}).observe(message, {
childList: true
});
}
};
17 changes: 1 addition & 16 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1265,22 +1265,7 @@ var imap_hide_add_contact_popup = function(event) {
popup.classList.toggle("show");
};

const message = document.querySelector('.msg_text');
if (message) {
new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(function (node) {
if (node.classList.contains('msg_text_inner')) {
handleExternalResources();
}
});
}
});
}).observe(message, {
childList: true
});
}
observeMessageTextMutationAndHandleExternalResources();

const handleDownloadMsgSource = function() {
const messageSource = document.querySelector('pre.msg_source');
Expand Down
3 changes: 2 additions & 1 deletion modules/inline_message/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ const messagesListMutation = new MutationObserver(function (mutations) {
if (mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(function (node) {
if (node.classList.contains('msg_text') || node.classList.contains('inline_msg')) {
if(node.querySelector('.msg_text_inner')) {
observeMessageTextMutationAndHandleExternalResources(true);
if(node.querySelector('.msg_text_inner') && !document.querySelector('.external_notices')) {
handleExternalResources(true);
}
}
Expand Down

0 comments on commit d1c727e

Please sign in to comment.