Github-Copilot-Blocker/remove-by-element.js

36 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-12-18 17:33:52 -06:00
function doSomething() {
/* Copilot Top Bar Button */
document.getElementById("copilot-chat-header-button").remove();
/* Copilot Home Page Container */
document.getElementById("copilotPreview__container").remove();
}
if (document.readyState === "loading") {
// Loading hasn't finished yet
// 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
});