ChatGPT Vim-Style Scrolling (Ctrl+U / Ctrl+D)

Scroll ChatGPT with keyboard like Vim (Ctrl+U to scroll up, Ctrl+D to scroll down)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         ChatGPT Vim-Style Scrolling (Ctrl+U / Ctrl+D)
// @namespace    https://greasyfork.org/users/your-username
// @version      1.1
// @description  Scroll ChatGPT with keyboard like Vim (Ctrl+U to scroll up, Ctrl+D to scroll down)
// @author       Maciek Dobaczewski
// @match        https://chatgpt.com/*
// @grant        none
// @license      MIT
// @run-at       document-idle
// ==/UserScript==

(function () {
  'use strict'

  function handleKeydown(e) {
    if (!e.ctrlKey) return

    // You can manually update this selector if chatGPT changes the element. 
    const container = document.querySelector('div.flex.h-full.flex-col.overflow-y-auto')
    if (!container) return

    const key = e.key.toLowerCase()
    if (key === 'd') {
      container.scrollBy({ top: 300 })
      e.preventDefault()
    } else if (key === 'u') {
      container.scrollBy({ top: -300 })
      e.preventDefault()
    }
  }

  document.addEventListener('keydown', handleKeydown, true)
})()