Last active
December 19, 2017 22:31
-
-
Save drifterz28/0dfd30f6dba9c5c9d3b37e2a9fcd49d2 to your computer and use it in GitHub Desktop.
Copy to clipboard
This file contains hidden or 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 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