Skip to content

Instantly share code, notes, and snippets.

@flarn2006
Created April 9, 2025 02:40
Show Gist options
  • Save flarn2006/9c6caa3bb1174c71301c19818b34e6c4 to your computer and use it in GitHub Desktop.
Save flarn2006/9c6caa3bb1174c71301c19818b34e6c4 to your computer and use it in GitHub Desktop.
Userscript to log URL's of partially-generated ChatGPT images
// ==UserScript==
// @name Log ChatGPT Generated Image URLs
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Log the src of images with alt text "Generated image" on chat.openai.com
// @match https://chat.openai.com/*
// @match https://chatgpt.com/*
// @match https://www.chatgpt.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function logSrc(img) {
if (img.alt === "Generated image" && img.src) {
console.log("Generated image src:", img.src);
}
}
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
// Check for newly added nodes
if (mutation.type === 'childList') {
for (const node of mutation.addedNodes) {
if (node.nodeType === Node.ELEMENT_NODE) {
const imgs = node.querySelectorAll?.('img[alt="Generated image"]') || [];
imgs.forEach(logSrc);
if (node.matches?.('img[alt="Generated image"]')) {
logSrc(node);
}
}
}
}
// Check for attribute changes
if (mutation.type === 'attributes' && mutation.target.tagName === 'IMG') {
const img = mutation.target;
if (img.alt === "Generated image" && mutation.attributeName === 'src') {
logSrc(img);
}
}
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['src']
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment