Skip to content

Instantly share code, notes, and snippets.

@heyitsaamir
Last active December 31, 2021 23:58
Show Gist options
  • Save heyitsaamir/d9e36e23ee2402e6d41e92903827bf32 to your computer and use it in GitHub Desktop.
Save heyitsaamir/d9e36e23ee2402e6d41e92903827bf32 to your computer and use it in GitHub Desktop.
Github Title Selector
/* globals jQuery, $, waitForKeyElements */
// ==UserScript==
// @name Github Title Selector
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Aamir Jawaid
// @match https://github.com/*/pull/*
// @icon https://www.google.com/s2/favicons?domain=tampermonkey.net
// @grant none
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @include https://github.com/*/pull/*
// ==/UserScript==
/*
When you click on the title of a github pull request,
this script will copy the title, diff and url to your clipboard.
Use with tapermonkey.
*/
function copyToClipboard(text) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val(text).select();
document.execCommand("copy");
$temp.remove();
}
(function() {
'use strict';
$( ".gh-header-title" ).click(function() {
const titleDOM = $('span.markdown-title');
if (!titleDOM) return;
const title = (titleDOM.length) ? titleDOM[0].innerText.trim() : titleDOM.innerText.trim();
const diffStatDOM = $('span#diffstat');
if (!diffStatDOM) return;
const diffStat = (diffStatDOM.length) ? diffStatDOM[0].innerText.trim() : diffStatDOM.innerText.trim();
const url = window.location.href;
const text = `\`${title}\` (${diffStat}) ${url}`;
copyToClipboard(text);
});
})();
@camflint
Copy link

Thanks for this!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment