Initial Commit

This commit is contained in:
Michael 2024-12-18 17:33:52 -06:00
commit f022037aec
Signed by: TheShadowEevee
GPG key ID: 7A8AA92B3BAFAB75
3 changed files with 85 additions and 0 deletions

36
manifest.json Normal file
View file

@ -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"
]
}

14
remove-by-URL.js Normal file
View file

@ -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"]
);

35
remove-by-element.js Normal file
View file

@ -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
});