Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Assorted helpful tweaks for git.git
// ==UserScript==
// @name Assorted helpful tweaks for git.git
// @version 0.1
// @description Helps maintain git.git PRs and commit comments
// @match https://github.com/git/git/*
// @source https://gist.github.com/dscho/536ffb491d964dd444f0eb6d91f87266
// @updateURL https://gist.github.com/dscho/536ffb491d964dd444f0eb6d91f87266/raw/git.git-helper.user.js
// @downloadURL https://gist.github.com/dscho/536ffb491d964dd444f0eb6d91f87266/raw/git.git-helper.user.js
// @run-at document-end
// @connect api.github.com
// ==/UserScript==
(() => {
// Add a 'Off Topic' button to all comments
const comments = document.querySelectorAll('.review-comment');
for (const comment of comments) {
const h3 = comment.querySelector('.js-suggested-changes-container .timeline-comment-actions');
if (!h3) continue;
const reason = comment.querySelector('[aria-label="Reason"]');
if (!reason) continue;
const hideCommentButton = reason.parentNode.querySelector(".btn");
if (!hideCommentButton) continue;
const resolveButton = document.createElement('btn');
resolveButton.classList.add('btn', 'btn-sm');
resolveButton.innerHTML = 'Off Topic';
resolveButton.onclick = () => {
reason.value = 'OFF_TOPIC';
hideCommentButton.click();
};
h3.appendChild(resolveButton);
}
for (const comment of document.querySelectorAll('.timeline-comment-wrapper')) {
const h3 = comment.querySelector('.timeline-comment-header .timeline-comment-actions');
if (!h3) continue;
const reason = comment.querySelector('[aria-label="Reason"]');
if (!reason) continue;
const hideCommentButton = reason.parentNode.querySelector(".btn");
if (!hideCommentButton) continue;
const resolveButton = document.createElement('btn');
resolveButton.classList.add('btn', 'btn-sm');
resolveButton.innerHTML = 'Off Topic';
resolveButton.onclick = () => {
reason.value = 'OFF_TOPIC';
hideCommentButton.click();
};
h3.appendChild(resolveButton);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.