diff --git a/remove-by-element.js b/remove-by-element.js index df83154..8655d16 100644 --- a/remove-by-element.js +++ b/remove-by-element.js @@ -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(); +} \ No newline at end of file