Last active
November 27, 2024 12:33
-
-
Save keyboardsamurai/91b76cff1bac1859617c2f6ec03cce20 to your computer and use it in GitHub Desktop.
Tampermonkey script for the Anthropic console workbench. Automatically scrolls to the latest message when you click 'Add to Conversation' in the chat interface
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 Anthropic Console Auto Scroll | |
// @namespace http://tampermonkey.net/ | |
// @version 1.2 | |
// @description Automatically scrolls to the latest message when you click 'Add to Conversation' in the Anthropic Claude Workbench chat interface | |
// @author keyboardsamurai | |
// @match https://console.anthropic.com/workbench/* | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Immediately log to verify script execution | |
console.log('AutoScroll Script Starting...'); | |
//alert('Script is running'); | |
//document.body.style.border = '5px solid red'; | |
// Function to scroll the container to bottom | |
function scrollToBottom() { | |
// Find the container using multiple possible selectors | |
const container = document.querySelector('[data-testid="structured-composer-container"] .overflow-y-auto') || | |
document.querySelector('.overflow-y-auto.scroll-pb-6'); | |
if (container) { | |
container.scrollTop = container.scrollHeight; | |
} else { | |
console.log('Container not found!'); | |
} | |
} | |
// Function to set up the click listener | |
function setupClickListener() { | |
// Use event delegation on document body | |
document.body.addEventListener('click', function(e) { | |
// Check all parent elements up to the clicked element for the button | |
let element = e.target; | |
while (element && element !== document.body) { | |
if (element.tagName === 'BUTTON' && | |
element.textContent.includes('Add to Conversation')) { | |
// Multiple scroll attempts with different delays | |
[100, 300, 500, 1000].forEach(delay => { | |
setTimeout(() => { | |
scrollToBottom(); | |
}, delay); | |
}); | |
break; | |
} | |
element = element.parentElement; | |
} | |
}); | |
} | |
// Function to initialize everything | |
function initialize() { | |
setupClickListener(); | |
} | |
// Set up initialization | |
if (document.readyState === 'loading') { | |
document.addEventListener('DOMContentLoaded', initialize); | |
} else { | |
initialize(); | |
} | |
// Backup initialization after a delay | |
setTimeout(() => { | |
initialize(); | |
}, 2000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment