Skip to content

Instantly share code, notes, and snippets.

@drifterz28
Created April 25, 2019 16:30
Show Gist options
  • Save drifterz28/c9d31f9422c9abb5ff7afc29b9c32633 to your computer and use it in GitHub Desktop.
Save drifterz28/c9d31f9422c9abb5ff7afc29b9c32633 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name PR Copy
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://github.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
setTimeout(function() {
var link = location.href;
var title = document.querySelector('.js-issue-title').textContent.trim();
var codeDiffAdd = document.querySelector('.diffstat .text-green').textContent.trim();
var codeDiffSubtract = document.querySelector('.diffstat .text-red').textContent.trim();
var headerActions = document.querySelector('.gh-header-actions');
headerActions.insertAdjacentHTML('afterbegin', '<button type="button" class="btn btn-sm js-textareacopybtn" style="margin-left:10px;">Copy</button>');
headerActions.insertAdjacentHTML('afterbegin', `<input type="text" autocomplete="off" style="float: left;" class="js-copytextarea" value="${link} - ${title} (${codeDiffAdd} ${codeDiffSubtract})">`);
var copyTextareaBtn = document.querySelector('.js-textareacopybtn');
copyTextareaBtn.addEventListener('click', function(event) {
var copyTextarea = document.querySelector('.js-copytextarea');
copyTextarea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
});
}, 500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment