Created
May 22, 2025 14:28
-
-
Save mcw0933/8c280c2aa55d276f08997bfbc43b46e5 to your computer and use it in GitHub Desktop.
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 Show/Hide Inline Review Comments on GitHub | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Adds a button in the upper right of the UI to toggle visibility of GitHub inline comments on pull requests | |
// @author Matt C. Wilson, with "help" from OpenAI (ok I edited the UserScript header don't @ me) | |
// @match https://github.com/*/pull/*/files | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
// Wait for the page to load completely | |
function waitForPageReady(callback) { | |
const check = () => { | |
const target = document.querySelector('body'); | |
if (target) callback(); | |
else setTimeout(check, 500); | |
}; | |
check(); | |
} | |
function addToggleButton() { | |
// Avoid adding the button multiple times | |
if (document.getElementById('toggle-inline-comments-btn')) return; | |
const button = document.createElement('button'); | |
button.id = 'toggle-inline-comments-btn'; | |
button.textContent = 'Toggle Comments'; | |
button.style.position = 'fixed'; | |
button.style.top = '10px'; | |
button.style.right = '10px'; | |
button.style.zIndex = '9999'; | |
button.style.padding = '6px 12px'; | |
button.style.backgroundColor = '#2da44e'; | |
button.style.color = 'white'; | |
button.style.border = 'none'; | |
button.style.borderRadius = '6px'; | |
button.style.cursor = 'pointer'; | |
button.style.fontSize = '14px'; | |
let visible = true; | |
button.addEventListener('click', () => { | |
const commentRows = document.querySelectorAll('tr.inline-comments'); | |
commentRows.forEach(row => { | |
if (visible) { | |
row.style.display = 'none'; | |
} else { | |
row.style.display = ''; | |
} | |
}); | |
visible = !visible; | |
}); | |
document.body.appendChild(button); | |
} | |
waitForPageReady(() => { | |
addToggleButton(); | |
// Optional: re-add if navigating on SPA | |
document.addEventListener('pjax:end', addToggleButton); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment