Created
April 20, 2020 09:59
-
-
Save ton1517/4625932e66bb99b021657d19c850fc72 to your computer and use it in GitHub Desktop.
This file contains 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 Itemize Pull Requests | |
// @version 0.1 | |
// @author ton1517 | |
// @namespace ton1517 | |
// @match https://github.com/* | |
// @grant none | |
// ==/UserScript== | |
;(function () { | |
'use strict' | |
function itemizePullRequests() { | |
if (document.querySelector('.itemize-pull-requests')) return | |
const btn = document.createElement('button') | |
btn.type = 'button' | |
btn.className = 'btn itemize-pull-requests' | |
btn.innerHTML = 'Itemize Pull Requests' | |
btn.onclick = async function () { | |
const prTextField = document.querySelector('.js-comment-field') | |
if (!prTextField) return | |
const prs = [] | |
document.querySelectorAll('.js-issue-link').forEach((e, i) => { | |
prs[i] = fetch(e.dataset.url, { headers: { Accept: 'application/json' } }) | |
.then((res) => res.json()) | |
.then((res) => `* ${res.title} ${e.text}`) | |
}) | |
const results = await Promise.all(prs) | |
prTextField.textContent = results.join('\n') | |
} | |
document.querySelector('.timeline-comment-wrapper').append(btn) | |
} | |
new MutationObserver(() => { | |
if (location.href.match(/https?:\/\/github.com\/.*\/compare\/.*/)) { | |
itemizePullRequests() | |
} | |
}).observe(document.body, { attributes: true }) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment