Skip to content

Instantly share code, notes, and snippets.

@mreq
Created June 20, 2023 10:28
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 mreq/d87d1d8975ea1a61555f7bcc7978b41b to your computer and use it in GitHub Desktop.
Save mreq/d87d1d8975ea1a61555f7bcc7978b41b to your computer and use it in GitHub Desktop.
Copies issue number and title on click
// ==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