Add proper element removal
This commit is contained in:
parent
f022037aec
commit
8e8e0aecc3
1 changed files with 12 additions and 26 deletions
|
@ -1,35 +1,21 @@
|
|||
|
||||
function doSomething() {
|
||||
/* Copilot Top Bar Button */
|
||||
document.getElementById("copilot-chat-header-button").remove();
|
||||
const copilotHeaderDivs = document.querySelectorAll('.AppHeader-CopilotChat');
|
||||
const copilotHomePageDivs = document.querySelectorAll('.copilotPreview__container');
|
||||
|
||||
/* Copilot Home Page Container */
|
||||
document.getElementById("copilotPreview__container").remove();
|
||||
copilotHeaderDivs.forEach(function(div) {
|
||||
div.remove(); // Remove each matching div
|
||||
});
|
||||
|
||||
copilotHomePageDivs.forEach(function(div) {
|
||||
div.remove(); // Remove each matching div
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
// Loading hasn't finished yet
|
||||
// document.addEventListener("DOMContentLoaded", doSomething);
|
||||
document.addEventListener("DOMContentLoaded", doSomething);
|
||||
} else {
|
||||
// `DOMContentLoaded` has already fired
|
||||
// doSomething();
|
||||
}
|
||||
|
||||
// Set up the MutationObserver to listen for added nodes
|
||||
const observer = new MutationObserver(function(mutations) {
|
||||
mutations.forEach(function(mutation) {
|
||||
mutation.addedNodes.forEach(function(node) {
|
||||
// Check if the added node is a div with the desired class
|
||||
if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains('AppHeader-CopilotChat')) {
|
||||
console.log("AppHeader-CopilotChat div added, removing it...");
|
||||
node.remove(); // Remove the element as soon as it's added
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Start observing the document body for added nodes, including all descendants (subtree: true)
|
||||
observer.observe(document.body, {
|
||||
childList: true, // Look for added or removed child nodes
|
||||
subtree: true // Observe all descendants, not just the immediate children
|
||||
});
|
||||
doSomething();
|
||||
}
|
Loading…
Reference in a new issue