ChatGPT ReadMode Alt+R

5/29/2023, 10:32:31 AM

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        ChatGPT ReadMode Alt+R
// @namespace   Violentmonkey Scripts
// @match       https://chat.openai.com/c/*
// @grant       none
// @version     1.0
// @author      -
// @description 5/29/2023, 10:32:31 AM
// @license MIT
// ==/UserScript==

let readMode = false
let sidebar, chatPane, formBlock

waitFor(isMainPresent).then(assignListener)

function waitFor(predicateFn) {
  return new Promise(resolve => {
    setTimeout(() => {
      const result = predicateFn()
      if (result) resolve(result)
      else waitFor(predicateFn).then(resolve)
    })
  })
}

function isMainPresent() {
  return document.querySelector('.w-full.h-full')
}

function assignListener(main) {
  [sideBar, chatPane] = main.children

  addEventListener('keydown', e => {
    if (e.key == 'r' && e.altKey) toggleReadMode()
  })
}

function toggleReadMode() {
  formBlock = chatPane.querySelector('.absolute.bottom-0')
  readMode = !readMode

  document.documentElement.style.fontSize = readMode ? '24px' : null
  sideBar.hidden = readMode
  if (formBlock) formBlock.hidden = readMode
}