Olá,
Alguma ideia de como posso obter elementos DOM no discourse sem ter que usar um setTimeout e um querySelector.
Porque atualmente eu faço algo assim:-
setTimeout(() => {
var createTopicButton = document.querySelector("#create-topic");
if(createTopicButton)
createTopicButton.onclick = function (e) {
if (window.Moengage && window.Moengage.track_event) {
window.Moengage.track_event("Topic_Create_Clicked", {});
}
setTimeout(() => {
var topicCreate = document.querySelector("#reply-control .save-or-cancel .btn-primary")
topicCreate.onclick = function (e) {
let heading = document.querySelector('#reply-control #reply-title').value;
let category = document.querySelector('.select-kit-header-wrapper >.select-kit-selected-name >.name >.badge-wrapper >.badge-category >.category-name')?.innerText;
let desc = document.querySelector('.d-editor-textarea-column >.d-editor-textarea-wrapper textarea').value;
let imagePresent = desc.includes("upload://");
if (window.Moengage && window.Moengage.track_event && heading && category && desc) {
window.Moengage.track_event("Topic_Created", {"Category":category,"Topic Name":heading,"Topic Description":desc,"Is_image_present":imagePresent});
}
}
},[300])
};
},[500])
Se eu não usar os timeouts acima, às vezes recebo elementos nulos, pois o DOM ainda não foi totalmente carregado, mesmo depois de colocar isso dentro de uma função window.onload.
Então, meu objetivo é obter elementos DOM e alterar a funcionalidade onChange.
Qualquer ajuda seria ótima.
Obrigado ![]()