Created
July 7, 2026 15:24
-
-
Save mRoca/48f715bc7b8490a616969aeda7b929f1 to your computer and use it in GitHub Desktop.
Github Avoid truncating PR titles
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 Revert GitHub PR Title Truncation | |
| // @namespace https://github.com/lionel-rowe/ | |
| // @version 0.4 | |
| // @description Revert GitHub PR Title Truncation | |
| // @author https://github.com/lionel-rowe/ | |
| // @match https://github.com/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=github.com | |
| // @grant none | |
| // @run-at document-start | |
| // ==/UserScript== | |
| // https://github.com/orgs/community/discussions/12450 | |
| // @ts-check | |
| /// <reference lib="dom" /> | |
| /// <reference lib="dom.iterable" /> | |
| /** @typedef {{ title: string, body: string }} Content */ | |
| const ELLIPSIS = '…' | |
| new MutationObserver(untruncate).observe( | |
| document.documentElement, | |
| { childList: true, subtree: true }, | |
| ) | |
| untruncate() | |
| function untruncate() { | |
| if (!location.pathname.includes('/compare/')) return | |
| const $title = document.querySelector('[name="pull_request[title]"]') | |
| const $body = document.querySelector('[name="pull_request[body]"]') | |
| if (!$title?.checkVisibility() || !$body?.checkVisibility()) return | |
| if (!($title instanceof HTMLInputElement) || !($body instanceof HTMLTextAreaElement)) { | |
| throw new TypeError('Unexpected element types') | |
| } | |
| reflow($title, $body) | |
| } | |
| /** | |
| * @param {HTMLInputElement} $title | |
| * @param {HTMLTextAreaElement} $body | |
| */ | |
| function reflow($title, $body) { | |
| const result = getReflowed({ title: $title.value, body: $body.value }) | |
| if (result == null) return | |
| $title.value = result.title | |
| $body.value = result.body | |
| } | |
| /** | |
| * @param {Content} content | |
| * @returns {Content | null} | |
| */ | |
| function getReflowed({ title, body }) { | |
| if (title.endsWith(ELLIPSIS) && body.startsWith(ELLIPSIS)) { | |
| const m = /\n\s*/.exec(body) | |
| const first = body.slice(0, m?.index ?? undefined) | |
| const rest = m == null ? '' : body.slice(m.index + m[0].length) | |
| return { | |
| title: title.slice(0, -ELLIPSIS.length) + first.slice(ELLIPSIS.length), | |
| body: rest, | |
| } | |
| } | |
| return null | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment