Created
June 20, 2023 10:28
-
-
Save mreq/d87d1d8975ea1a61555f7bcc7978b41b to your computer and use it in GitHub Desktop.
Copies issue number and title on click
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 github issue title | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://github.com/* | |
// @grant GM_setClipboard | |
// ==/UserScript== | |
(function () { | |
'use strict' | |
document.addEventListener('click', (e) => { | |
const target = e.target.closest('.gh-header-title') | |
if (target) { | |
let title, number | |
if (target.classList.contains('gh-header-title')) { | |
title = target.querySelector('.js-issue-title').innerText.trim() | |
} else if (target.dataset.testId === 'side-panel-title') { | |
title = target.querySelector('h2').innerText.trim() | |
number = null | |
} | |
const matches = window.location.href.match(/(issues|pull)\/(\d+)/) | |
number = `#${matches[2].split("/").pop()}` | |
if (matches[1] === "pull") { | |
const author = document.querySelector('.gh-header-meta .author') | |
if (author && author.innerText) { | |
title += ` (PR by ${author.innerText.trim()})` | |
} | |
} | |
if (title && number) { | |
target.style.transition = 'background .15s ease-in-out' | |
target.style.background = '#c2e5f9' | |
GM_setClipboard(`${number}: ${title}`) | |
setTimeout(() => { target.style.background = 'none' }, 250) | |
} | |
} | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment