Skip to content

Instantly share code, notes, and snippets.

@vallieres
Created January 17, 2019 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vallieres/f70f3e5bc646e3658536ba2cf82533b0 to your computer and use it in GitHub Desktop.
Save vallieres/f70f3e5bc646e3658536ba2cf82533b0 to your computer and use it in GitHub Desktop.
Prepares a Status Update from Selected PR in Github
javascript: void((function(d) {
function collectionHas(a, b) { //helper function (see below)
for(var i = 0, len = a.length; i < len; i ++) {
if(a[i] == b) return true;
}
return false;
}
function findParentBySelector(elm, selector) {
var all = document.querySelectorAll(selector);
var cur = elm.parentNode;
while(cur && !collectionHas(all, cur)) { //keep going up until you find a match
cur = cur.parentNode; //go up
}
return cur; //will return null if not found
}
function copyToClipboard(str) {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
el.select();
document.execCommand('copy');
document.body.removeChild(el);
if (selected) {
document.getSelection().removeAllRanges();
document.getSelection().addRange(selected);
}
};
d.querySelectorAll('.js-issue-row label input[type="checkbox"]')
var allPRs = "";
d.querySelectorAll('.js-issue-row label input:checked').forEach(function(x) {
var parent = findParentBySelector(x, '.js-issue-row');
var link = 'https://github.com/' + parent.querySelector('a.h4').getAttribute('href');
console.log('link', link);
var pr = parent.querySelector('a.h4').textContent;
console.log('pr', pr);
var singlePR = '*' + pr + '*' + "\n" + link + "\n> " + "\n\n";
allPRs += singlePR;
});
copyToClipboard(allPRs);
})(document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment