Skip to content

Commit

Permalink
Merge pull request #1537 from Azmoria/Fix---mutation-observer-bug-due…
Browse files Browse the repository at this point in the history
…-to-item-not-existing-yet

Fix - mutation observer bug due to item not existing yet
  • Loading branch information
Azmoria authored Sep 21, 2023
2 parents de179f6 + cd846cc commit 4f29b92
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2229,16 +2229,57 @@ Disadvantage: 2d20kl1 (keep lowest)&#xa;&#xa;<br/>
}, 0);
}
})
const mutation_target = $(".dice-toolbar__dropdown")[0];
const mutation_config = { attributes: true, childList: true, characterData: true, subtree: true };
window.rollButtonObserver.observe(mutation_target, mutation_config);

let watchForDicePanel = new MutationObserver((mutations) => {
mutations.every((mutation) => {
if (!mutation.addedNodes) return

for (let i = 0; i < mutation.addedNodes.length; i++) {
// do things to your newly added nodes here
let node = mutation.addedNodes[i]
if ((node.className == 'dice-rolling-panel' || $('.dice-rolling-panel').length>0)){
const mutation_target = $(".dice-toolbar__dropdown")[0];
const mutation_config = { attributes: true, childList: true, characterData: true, subtree: true };
window.rollButtonObserver.observe(mutation_target, mutation_config);
watchForDicePanel.disconnect();
return false;
}
}
return true // must return true if doesn't break
})
});

window.sendToDefaultObserver = new MutationObserver(function() {
localStorage.setItem(`${gameId}-sendToDefault`, gamelog_send_to_text());
})
const sendto_mutation_target = $(".glc-game-log .tss-l9t796-SendToLabel")[0];
const sendto_mutation_config = { attributes: true, childList: true, characterData: true, subtree: true };
window.sendToDefaultObserver.observe(mutation_target, mutation_config);


let gamelogObserver = new MutationObserver((mutations) => {
mutations.every((mutation) => {
if (!mutation.addedNodes) return
for (let i = 0; i < mutation.addedNodes.length; i++) {
// do things to your newly added nodes here
let node = mutation.addedNodes[i]
if(node.className == 'tss-l9t796-SendToLabel' || $('.glc-game-log .tss-l9t796-SendToLabel ~ button').length>0){
const sendto_mutation_target = $(".glc-game-log .tss-l9t796-SendToLabel ~ button")[0];
const sendto_mutation_config = { attributes: true, childList: true, characterData: true, subtree: true };
window.sendToDefaultObserver.observe(sendto_mutation_target, sendto_mutation_config);
gamelogObserver.disconnect();
return false;
}
}
return true // must return true if doesn't break
})
});

watchForDicePanel.observe(document.body, {childList: true, subtree: true, attributes: false, characterData: false});
gamelogObserver.observe(document.body, {childList: true, subtree: true, attributes: false, characterData: false});









Expand Down

0 comments on commit 4f29b92

Please sign in to comment.