From f022037aecdcda5a197d20e67640099664fc5bbb Mon Sep 17 00:00:00 2001 From: TheShadowEevee Date: Wed, 18 Dec 2024 17:33:52 -0600 Subject: [PATCH] Initial Commit --- manifest.json | 36 ++++++++++++++++++++++++++++++++++++ remove-by-URL.js | 14 ++++++++++++++ remove-by-element.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 manifest.json create mode 100644 remove-by-URL.js create mode 100644 remove-by-element.js diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..88f612e --- /dev/null +++ b/manifest.json @@ -0,0 +1,36 @@ +{ + "manifest_version": 3, + "name": "Github Copilot Remover", + "version": "1.0", + + "description": "Attempts to hide the Copilot button on the Github website", + + "icons": { + "48": "icons/border-48.png" + }, + + "background": { + "scripts": ["remove-by-URL.js"] + }, + + "content_scripts": [ + { + "matches": ["*://*.github.com/*"], + "js": ["remove-by-element.js"], + "run_at": "document_idle", + "world": "MAIN" + } + ], + + "host_permissions": [ + "https://github.com/*", + "https://github.githubassets.com/*" + ], + + "permissions": [ + "tabs", + "webRequest", + "webRequestBlocking" + ] + } + \ No newline at end of file diff --git a/remove-by-URL.js b/remove-by-URL.js new file mode 100644 index 0000000..5ae270f --- /dev/null +++ b/remove-by-URL.js @@ -0,0 +1,14 @@ +/* Blocks requests to Github / Github Assets containing Copilot URIs */ + +browser.webRequest.onBeforeRequest.addListener( + function() { + return {cancel: true}; + }, + { + urls: [ + "*://github.com/github-copilot/*", + "*://github.githubassets.com/assets/*copilot*" + ] + }, + ["blocking"] +); diff --git a/remove-by-element.js b/remove-by-element.js new file mode 100644 index 0000000..df83154 --- /dev/null +++ b/remove-by-element.js @@ -0,0 +1,35 @@ + +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 +});