Last active
August 11, 2025 15:25
-
-
Save PiN73/d55ed0431a17ba9e23f79724c251d3b6 to your computer and use it in GitHub Desktop.
ChatGPT: button to expand all thoughts [Tampermonkey script]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name ChatGPT Expand thoughts | |
// @version 2025-08-11 | |
// @description useful for expporting chat as html, e.g using SingleFile | |
// @match https://chatgpt.com/* | |
// @icon https://chatgpt.com/favicon.ico | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict' | |
const $ = s => document.querySelector(s) | |
const $$ = s => [...document.querySelectorAll(s)] | |
const btn = document.createElement('button') | |
btn.textContent = 'Expand thoughts' | |
btn.onclick = function () { | |
$('button[aria-label="Close sidebar"]')?.click() | |
for (let b of $$(` | |
article | |
span[data-state="closed"]:not(:has(+ .relative.z-0)) | |
div.relative.w-full.text-start | |
button.w-full:not(:disabled) | |
`)) { | |
b.click() | |
} | |
} | |
function throttle(fn, delay) { | |
let pending = false | |
return function (...args) { | |
if (pending) { | |
return | |
} | |
pending = true | |
setTimeout(() => { | |
fn.apply(this, args) | |
pending = false | |
}, delay) | |
} | |
} | |
function ensure() { | |
const c = $('nav[aria-label="Chat history"] div.sticky.bottom-0') | |
if (c && !c.contains(btn)) { | |
c.appendChild(btn) | |
} | |
} | |
ensure = throttle(ensure, 1000) | |
new MutationObserver(ensure).observe( | |
document.body, | |
{ | |
childList: true, | |
subtree: true, | |
} | |
) | |
ensure() | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment