ChatGPT ReadMode Alt+R

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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
}