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() {
|
function doSomething() {
|
||||||
/* Copilot Top Bar Button */
|
const copilotHeaderDivs = document.querySelectorAll('.AppHeader-CopilotChat');
|
||||||
document.getElementById("copilot-chat-header-button").remove();
|
const copilotHomePageDivs = document.querySelectorAll('.copilotPreview__container');
|
||||||
|
|
||||||
/* Copilot Home Page Container */
|
copilotHeaderDivs.forEach(function(div) {
|
||||||
document.getElementById("copilotPreview__container").remove();
|
div.remove(); // Remove each matching div
|
||||||
|
});
|
||||||
|
|
||||||
|
copilotHomePageDivs.forEach(function(div) {
|
||||||
|
div.remove(); // Remove each matching div
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.readyState === "loading") {
|
if (document.readyState === "loading") {
|
||||||
// Loading hasn't finished yet
|
// Loading hasn't finished yet
|
||||||
// document.addEventListener("DOMContentLoaded", doSomething);
|
document.addEventListener("DOMContentLoaded", doSomething);
|
||||||
} else {
|
} else {
|
||||||
// `DOMContentLoaded` has already fired
|
// `DOMContentLoaded` has already fired
|
||||||
// doSomething();
|
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
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in a new issue