Skip to content

Instantly share code, notes, and snippets.

@g0t4
Created January 23, 2025 15:41
Show Gist options
  • Save g0t4/8b4692e632fd30dc117e6120a2bddf94 to your computer and use it in GitHub Desktop.
Save g0t4/8b4692e632fd30dc117e6120a2bddf94 to your computer and use it in GitHub Desktop.
Tampermonkey script that removes banners / fact checking advertisements in chatgpt.com chats (on the fly)
// ==UserScript==
// @name OpenAI Remove Fact Checking Banners
// @namespace http://tampermonkey.net/
// @version 2025-01-23
// @description Remove advertisements to trust Reuters/AP.. probably CDC too
// @author Wes Higbee
// @match https://chatgpt.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=chatgpt.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
// List of approved scam ad text snippets, add a subset of new ads here to remove them automatically
const approvedSnippets = [
"The Associated Press, Reuters, ",
];
// Function to check if the element contains any approved snippet
function containsApprovedSnippet(element) {
const textContent = element.textContent || "";
return approvedSnippets.some(snippet => textContent.includes(snippet));
}
// WHEN TO RUN:
// window.addEventListener('load', removeScamAds);
// observe DOM for dynamically loaded ads:
const observer = new MutationObserver(removeScamAds);
observer.observe(document.body, { childList: true, subtree: true });
// TEST THIS by asking anything about "who won 2020 election" or "did Trump win in 2020"
function removeScamAds() {
// Select all elements containing the SVG with the unique icon class
const scamSvgs = document.querySelectorAll('svg.icon-lg.shrink-0.text-token-text-secondary');
scamSvgs.forEach(svg => {
// Traverse up to find the parent scam ad container
const adContainer = svg.closest('.flex.flex-col.gap-2');
if (adContainer) {
// Skip if the container does not have text content (yet, so when first loading it doesn't have the message yet... so don't remove it until the message is present so I can check the message)
const textContent = adContainer.textContent.trim();
if (!textContent) {
console.log("Skipping empty container:", adContainer);
return;
}
// Check if the content matches any approved snippet
if (containsApprovedSnippet(adContainer)) {
adContainer.remove();
console.log('Scam ad removed:', adContainer);
} else {
// TODO alert only once..
// Alert for manual review if content doesn't match
//console.log("NEW SCAM AD DETECTED, check if it should be removed: ", adContainer.outerHTML);
alert("Potential scam ad detected for review:\n\n" + textContent);
}
}
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment