🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

📑 镜像加速信息:本页面由 Cloudflare 边缘节点提供
同步时间:2025/12/22 16:40:00 (已命中边缘缓存)

GitHub code review helper - open/hide diff on click

Open/hide GitHub diff when clicking on diff header

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         GitHub code review helper - open/hide diff on click
// @namespace    http://think.js/
// @version      0.3.4
// @description  Open/hide GitHub diff when clicking on diff header
// @include      http*://github.com/*/*/commit/*
// @include      http*://github.com/*/*/pull/*
// @include      http*://github.com/*/*/compare/*
// @grant none
// @copyright    2013+, Victor Homyakov
// ==/UserScript==

function hasClass(element, className) {
    return element && element.classList && element.classList.contains(className);
}

function isDiffHeader(element) {
    return hasClass(element, 'file-header');
}

function isDiffContent(element) {
    return hasClass(element, 'image') || hasClass(element, 'data') || hasClass(element, 'render-wrapper');
}

function toggle(element) {
    element.hidden = !element.hidden;
    element.style.display = element.hidden ? 'none' : '';
}

document.body.addEventListener('click', function(event) {
    var target = event.target;
    while (target) {
        if (hasClass(target, 'file-actions')) {
            break;
        }
        if (isDiffHeader(target)) {
            var next = target;

            next = next.nextElementSibling;
            if (isDiffContent(next)) {
                toggle(next);
            }

            next = next.nextElementSibling;
            if (isDiffContent(next)) {
                toggle(next);
            }

            break;
        }
        target = target.parentElement;
    }
});