|
// ==UserScript== |
|
// @name Assorted helpful tweaks for GitGitGadget's Git fork |
|
// @version 0.14 |
|
// @description Removes the merge button on the GitHub `gitgitgadget/git` project, as PRs there are never to be merged. Adds more buttons. |
|
// @source https://gist.github.com/dscho/3ea2406669ae4097ca58971b41f9c9ed |
|
// @match https://github.com/gitgitgadget/git/pull/* |
|
// @updateURL https://gist.github.com/dscho/3ea2406669ae4097ca58971b41f9c9ed/raw/hide-gitgitgadget-git-merge-button.user.js |
|
// @downloadURL https://gist.github.com/dscho/3ea2406669ae4097ca58971b41f9c9ed/raw/hide-gitgitgadget-git-merge-button.user.js |
|
// @run-at document-end |
|
// @grant GM_xmlhttpRequest |
|
// @connect api.github.com |
|
// ==/UserScript== |
|
|
|
(() => { |
|
const clearMergeButton = () => { |
|
['merge', 'squash', 'rebase'].map((mode) => { |
|
for (const e of document.querySelectorAll(`.btn-group-${mode}`)) { |
|
e.style.display = 'none'; |
|
} |
|
}); |
|
for (const e of document.querySelectorAll('.js-merge-method-menu-button')) { |
|
e.style.display = 'none'; |
|
} |
|
}; |
|
|
|
clearMergeButton(); |
|
new MutationObserver((events, observer) => { |
|
events.forEach((event) => { |
|
if (event.addedNodes) { |
|
clearMergeButton(); |
|
} |
|
}) |
|
}).observe(document, { attributes: true, childList: true, subtree: true }); |
|
|
|
// Merge button gets reset after you add a comment for some reason, so hide it then too |
|
const form = document.querySelector('form.js-new-comment-form') |
|
form.addEventListener('submit', function() { setTimeout(clearMergeButton, 1000); }); |
|
|
|
// Add a 'Resolve' button to all comments |
|
const comments = document.querySelectorAll('.js-comment-container'); |
|
for (const comment of comments) { |
|
const h3 = comment.querySelector('.unminimized-comment .timeline-comment-header-text'); |
|
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 = 'Resolve'; |
|
resolveButton.onclick = () => { |
|
reason.value = 'RESOLVED'; |
|
hideCommentButton.click(); |
|
}; |
|
h3.appendChild(resolveButton); |
|
} |
|
|
|
// Add a prominent link to the gitgitgadget.git build |
|
const prNumbers = document.querySelectorAll('.gh-header-number'); |
|
if (prNumbers.length > 0) { |
|
const addBuildLink = function(response) { |
|
response = JSON.parse(response.responseText); |
|
for (const prNumber of prNumbers) { |
|
const a = document.createElement('a'); |
|
a.innerHTML = `Build ${response.conclusion}`; |
|
a.setAttribute('href', response.details_url); |
|
prNumber.parentElement.appendChild(a); |
|
} |
|
} |
|
|
|
for (const run of document.querySelectorAll('.merge-status-item')) { |
|
if (run.innerHTML.match(/>\s*gitgitgadget\.git\s*</)) { |
|
const actions = run.querySelectorAll('a.status-actions'); |
|
const href = actions.length === 1 && actions[0].getAttribute('href'); |
|
const match = href && href.match(/\?check_run_id=(\d+)/); |
|
if (match) { |
|
GM_xmlhttpRequest({ |
|
method: 'GET', |
|
headers: { |
|
'Accept': 'application/vnd.github.antiope-preview+json', |
|
}, |
|
url: `https://api.github.com/repos/gitgitgadget/git/check-runs/${match[1]}`, |
|
onload: addBuildLink, |
|
}); |
|
} |
|
} |
|
} |
|
} |
|
})(); |