Skip to content

Instantly share code, notes, and snippets.

@gnyman
Created January 3, 2024 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnyman/595f388b9c60f29bad6e6a30ef0c038a to your computer and use it in GitHub Desktop.
Save gnyman/595f388b9c60f29bad6e6a30ef0c038a to your computer and use it in GitHub Desktop.
Incognito button for ChatGPT
// Simple script that adds a "incognito" shortcut to ChatGPT (toggles the history)
// run this in the console, or add it to StopTheMadness, Tampermonkey or similar
// Author @gnyman
// Licence CCO
function waitForElement(xpath) {
return new Promise((resolve, reject) => {
// Check if the element already exists
var existingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (existingElement) {
resolve(existingElement);
return;
}
const observer = new MutationObserver((mutations, me) => {
var element = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (element) {
me.disconnect(); // Stop observing
resolve(element);
}
});
observer.observe(document, {
childList: true,
subtree: true
});
});
}
async function dispatchEventWhenAvailable(xpath, eventType) {
try {
const element = await waitForElement(xpath);
if (eventType === 'click') {
element.click();
} else if (eventType === 'mousedown') {
element.dispatchEvent(new MouseEvent('mousedown', {
bubbles: true,
cancelable: true
}));
}
} catch (error) {
console.error('Error waiting for element:', error);
}
}
async function runClicksInOrder() {
const actions = [{
xpath: "//*[starts-with(@id, 'headlessui-menu-button-:')]",
eventType: 'click'
},
{
xpath: "//node()[text()='Settings & Beta']",
eventType: 'click'
},
{
xpath: "//node()[text()='Data controls']",
eventType: 'mousedown'
}, // Changed to mousedown
{
xpath: "//*[@aria-label='Chat history & training']",
eventType: 'click'
},
];
for (let action of actions) {
await dispatchEventWhenAvailable(action.xpath, action.eventType);
}
}
var button = document.createElement('button');
button.innerHTML = '😎'; // Glasses emoji
button.style.position = 'fixed';
button.style.top = '10px';
button.style.right = '10px';
button.style.zIndex = '1000';
button.style.backgroundColor = 'white';
button.style.border = '1px solid #ddd';
button.style.borderRadius = '4px';
button.style.padding = '5px 10px';
button.style.cursor = 'pointer';
// Define the custom JavaScript to run when the button is clicked
button.onclick = function() {
console.log('Incognito button clicked');
runClicksInOrder();
};
// Append the button to the body of the webpage
document.body.appendChild(button);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment