Last active
February 13, 2018 15:56
-
-
Save Jaace/9c4cfb812f70d41b44c9e88659c70086 to your computer and use it in GitHub Desktop.
Expand/Collapse button on Github PRs
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
// Add a button to Collapse or Expand comments in a GitHub PR. | |
// | |
// Install Tampermonkey and add this as a script | |
// ==UserScript== | |
// @name Github PRs: Expand / Collapse Comments. | |
// @namespace TBD | |
// @version 0.1 | |
// @description Add a button to expand or collapse comments in a GitHub PR. | |
// @author Jason Boyle | |
// @match https://github.com/* | |
// @grant GM_addStyle | |
// ==/UserScript== | |
GM_addStyle( | |
'.pr-expand-collapse-btn { margin: 0 0 0 6px; position: absolute; right: 10px; top: 4px; } ' + | |
'.collapsed { display: none; }' | |
); | |
window.addEventListener('load', () => { | |
initializeButtons(); | |
}); | |
function initializeButtons() { | |
const comments = document.querySelectorAll('.file.js-comment-container'); | |
for (let comment of comments) { | |
const actions = comment.querySelector('.file-header'); | |
const diffTable = comment.querySelector('.blob-wrapper'); | |
const reviewComments = comment.querySelector('.review-comments'); | |
const expandCollapseBtn = document.createElement('a'); | |
expandCollapseBtn.classList.add('pr-expand-collapse-btn', 'btn', 'btn-sm'); | |
expandCollapseBtn.innerHTML = 'Collapse'; | |
actions.appendChild(expandCollapseBtn); | |
expandCollapseBtn.onclick = function() { | |
if ('Collapse' === expandCollapseBtn.innerHTML) { | |
expandCollapseBtn.innerHTML = 'Expand'; | |
} else { | |
expandCollapseBtn.innerHTML = 'Collapse'; | |
} | |
diffTable.classList.toggle('collapsed'); | |
reviewComments.classList.toggle('collapsed'); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment