Skip to content

Instantly share code, notes, and snippets.

@srghma
Last active September 12, 2026 03:17
Show Gist options
  • Select an option

  • Save srghma/3f58cfba0806d888194034a24f88418e to your computer and use it in GitHub Desktop.

Select an option

Save srghma/3f58cfba0806d888194034a24f88418e to your computer and use it in GitHub Desktop.
aristotle: find last answer in chat
(async () => {
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
// 1. Locate the true feed scroll container
let container = document.querySelector('[data-scrollable]');
if (!container) {
const feed = document.querySelector('[data-feed-group]');
if (feed) {
let p = feed.parentElement;
while (p && p !== document.body) {
if (p.scrollHeight > p.clientHeight && p.clientHeight > 0) {
container = p;
break;
}
p = p.parentElement;
}
}
}
console.log('Using container:', container, `| scrollTop: ${container?.scrollTop} / ${container?.scrollHeight - container?.clientHeight}`);
// 2. Strict matchers based on your specification
const getAnswer = () => {
const answers = document.querySelectorAll('div[data-ask-answered="true"], [data-ask-answered="true"]');
return answers.length ? answers[answers.length - 1] : null;
};
const getAristotleSpan = () => {
// Strictly matching the span (ignoring textareas / inputs)
const spans = document.querySelectorAll('span[role="img"][aria-label="Aristotle"], span[aria-label="Aristotle"]');
return spans.length ? spans[spans.length - 1] : null;
};
let target = getAnswer();
// 3. If primary target isn't in current DOM viewport, scroll UP to search
if (!target && container && container.scrollTop > 0) {
console.log('Primary target not visible, scrolling up...');
let lastScroll = -1;
while (!target && container.scrollTop > 0 && container.scrollTop !== lastScroll) {
lastScroll = container.scrollTop;
container.scrollTop = Math.max(0, container.scrollTop - container.clientHeight * 0.7);
await sleep(250);
target = getAnswer();
}
}
// 4. Fallback: if no answered question exists anywhere in history
if (!target) {
console.log('No answered question found. Searching for last Aristotle span...');
target = getAristotleSpan();
// If still not found because we scrolled to top, jump to bottom to check recent messages
if (!target && container) {
container.scrollTop = container.scrollHeight;
await sleep(250);
target = getAristotleSpan();
// Scroll up from bottom if needed
let lastScroll = -1;
while (!target && container.scrollTop > 0 && container.scrollTop !== lastScroll) {
lastScroll = container.scrollTop;
container.scrollTop = Math.max(0, container.scrollTop - container.clientHeight * 0.7);
await sleep(250);
target = getAristotleSpan();
}
}
}
if (!target) {
console.error('Neither the answered question nor the Aristotle span could be found.');
return;
}
// 5. Scroll into view, log, and blink 10 times
target.scrollIntoView({ behavior: 'smooth', block: 'center' });
console.log('%c Target Found! %o', 'background: #10b981; color: white; font-weight: bold; padding: 3px 6px;', target);
const prevOutline = target.style.outline;
const prevBoxShadow = target.style.boxShadow;
target.style.transition = 'all 0.15s ease-in-out';
for (let i = 0; i < 10; i++) {
target.style.outline = '4px solid #f59e0b'; // Amber highlight
target.style.boxShadow = '0 0 15px rgba(245, 158, 11, 0.8)';
await sleep(200);
target.style.outline = '4px solid transparent';
target.style.boxShadow = 'none';
await sleep(200);
}
target.style.outline = prevOutline;
target.style.boxShadow = prevBoxShadow;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment