Claude Up Arrow Edit

Make Up Arrow press the edit button in Claude, similar to Discord

  1. // ==UserScript==
  2. // @name Claude Up Arrow Edit
  3. // @namespace Violentmonkey Scripts
  4. // @match https://claude.ai/*
  5. // @grant none
  6. // @version 1.0
  7. // @license Skibidi
  8. // @description Make Up Arrow press the edit button in Claude, similar to Discord
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Define base selector paths as constants
  15. const BASE_PATH = "body > div.flex.min-h-screen.w-full > div.min-h-full.w-full.min-w-0.flex-1 > div > div.h-screen.flex.flex-col.overflow-hidden > div > div";
  16. const MESSAGES_CONTAINER = `${BASE_PATH} > div.flex-1.flex.flex-col.gap-3.px-4.max-w-3xl.mx-auto.w-full.pt-1`;
  17. const INPUT_CONTAINER = `${BASE_PATH} > div.sticky.bottom-0.mx-auto.w-full.pt-6.z-\\[5\\]`;
  18.  
  19. document.addEventListener('keydown', (event) => {
  20. // Check if the pressed key is the up arrow
  21. if (event.key === 'ArrowUp') {
  22. // Find the input area and check its focus state
  23. const inputArea = document.querySelector(`${INPUT_CONTAINER} > fieldset > div.flex.flex-col.bg-bg-000.border-0\\.5.border-border-300.mx-2.md\\:mx-0.items-stretch.transition-all.duration-200.relative.shadow-\\[0_0\\.25rem_1\\.25rem_hsl\\(var\\(--always-black\\)\\/3\\.5\\%\\)\\].focus-within\\:shadow-\\[0_0\\.25rem_1\\.25rem_hsl\\(var\\(--always-black\\)\\/7\\.5\\%\\)\\].hover\\:border-border-200.focus-within\\:border-border-200.cursor-text.z-10.rounded-2xl > div.flex.flex-col.gap-3\\.5.m-3\\.5 > div.relative > div > div`);
  24.  
  25. // Check if Prosemirror is focused
  26. const isProseMirrorFocused = inputArea && inputArea.classList.contains('ProseMirror-focused');
  27.  
  28. // Get the paragraph element inside the input area
  29. const inputParagraph = document.querySelector(`${INPUT_CONTAINER} > fieldset > div.flex.flex-col.bg-bg-000.border-0\\.5.border-border-300.mx-2.md\\:mx-0.items-stretch.transition-all.duration-200.relative.shadow-\\[0_0\\.25rem_1\\.25rem_hsl\\(var\\(--always-black\\)\\/3\\.5\\%\\)\\].focus-within\\:shadow-\\[0_0\\.25rem_1\\.25rem_hsl\\(var\\(--always-black\\)\\/7\\.5\\%\\)\\].hover\\:border-border-200.focus-within\\:border-border-200.cursor-text.z-10.rounded-2xl > div.flex.flex-col.gap-3\\.5.m-3\\.5 > div.relative > div > div > p`);
  30.  
  31. // Check if input is empty (could be null, or might have no innerText)
  32. const isInputEmpty = !inputParagraph || (inputParagraph.innerText.trim() === '');
  33.  
  34. // Conditions to trigger edit:
  35. // 1. Input is not focused OR
  36. // 2. Input is focused but empty
  37. if (!isProseMirrorFocused || (isProseMirrorFocused && isInputEmpty)) {
  38. // Find the edit button for the last message
  39. // Try both nth-last-child(2) and nth-last-child(4) to handle different states
  40. let editButton = document.querySelector(`${MESSAGES_CONTAINER} > div:nth-last-child(2) > div > div > div.absolute.bottom-0.-right-1\\.5 > div > div > button`);
  41.  
  42. // If not found, try the alternate selector
  43. if (!editButton) {
  44. editButton = document.querySelector(`${MESSAGES_CONTAINER} > div:nth-last-child(4) > div > div > div.absolute.bottom-0.-right-1\\.5 > div > div > button`);
  45. }
  46.  
  47. // If the button exists, click it
  48. if (editButton) {
  49. editButton.click();
  50. event.preventDefault(); // Prevent default up arrow behavior
  51.  
  52. // Set a small timeout to wait for the textarea to appear
  53. setTimeout(() => {
  54. const textarea = document.querySelector(`${MESSAGES_CONTAINER} > form > div > div > div.font-user-message.mr-3.grid.w-full.grid-cols-1.gap-2.py-0\\.5.text-\\[0\\.9375rem\\].leading-6 > div.group.relative > div > textarea`);
  55.  
  56. if (textarea) {
  57. // Move cursor to the end of the text
  58. textarea.focus();
  59. textarea.selectionStart = textarea.value.length;
  60. textarea.selectionEnd = textarea.value.length;
  61. }
  62. }, 10); // Small delay to ensure the textarea is available
  63. }
  64. }
  65. }
  66. });
  67. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址