Resizable Diff Sidebar (GitHub PR Files)

Make GitHub PR diff sidebar resizable with a visible drag handle

اعتبارا من 15-09-2025. شاهد أحدث إصدار.

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 or Violentmonkey 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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         Resizable Diff Sidebar (GitHub PR Files)
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Make GitHub PR diff sidebar resizable with a visible drag handle
// @author       Louis Yvelin
// @match        https://github.com/*/*/pull/*/files
// @grant        none
// @license MIT 
// ==/UserScript==

(function() {
    'use strict';

    const parent = document.querySelector("#diff-layout-component")
    const sidebar = document.querySelector("#diff-layout-component > div.Layout-sidebar.overflow-y-auto.hx_Layout--sidebar.diff-sidebar.position-sticky")

    if (!parent || !sidebar) return

    const handle = document.createElement("div")
    handle.style.width = "5px"
    handle.style.cursor = "col-resize"
    handle.style.position = "absolute"
    handle.style.top = "0"
    handle.style.bottom = "0"
    handle.style.right = "0"
    handle.style.zIndex = "9999"
    handle.style.background = "rgba(0, 123, 255, 0)"
    handle.style.transition = "background 0.2s ease"

    sidebar.style.position = "relative"
    sidebar.appendChild(handle)

    sidebar.addEventListener("mouseenter", () => {
        if (!isDragging) handle.style.background = "rgba(0, 123, 255, 0.5)"
    })
    sidebar.addEventListener("mouseleave", () => {
        if (!isDragging) handle.style.background = "rgba(0, 123, 255, 0)"
    })

    let isDragging = false

    handle.addEventListener("mousedown", e => {
        e.preventDefault()
        isDragging = true
        document.body.style.userSelect = "none"
        handle.style.background = "rgba(0, 123, 255, 0.9)"
    })

    document.addEventListener("mousemove", e => {
        if (!isDragging) return
        const rect = parent.getBoundingClientRect()
        const newWidth = e.clientX - rect.left
        parent.style.setProperty("--Layout-sidebar-width", `${newWidth}px`)
    })

    document.addEventListener("mouseup", () => {
        if (isDragging) {
            isDragging = false
            document.body.style.userSelect = ""
            handle.style.background = "rgba(0, 123, 255, 0.5)"
        }
    })
})()