Copy Github PR/Issue Title

Add "copy Github PR title or issue title" button

  1. // ==UserScript==
  2. // @name Copy Github PR/Issue Title
  3. // @namespace http://tampermonkey.net/
  4. // @version 2025-04-20
  5. // @description Add "copy Github PR title or issue title" button
  6. // @author You
  7. // @match https://github.com/*/pull/*
  8. // @match https://github.com/*/issues/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
  10. // @license MIT
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const title_selector = "bdi.markdown-title"
  18. const copy_svg = (title) => `<clipboard-copy aria-label="Copy" data-copy-feedback="Copied!" value="${title}" data-view-component="true" class="Link--onHover js-copy-branch color-fg-muted d-inline-block ml-1" tabindex="0" role="button">
  19. <svg xmlns="http://www.w3.org/2000/svg" height="16" viewBox="0 -960 960 960" width="16" fill="#e3e3e3"><path d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"/></svg>
  20. </clipboard-copy>`
  21. const h1_selector = `h1:has(${title_selector})`
  22. const append_copy_button = () => {
  23. const h1 = document.querySelector(h1_selector)
  24. const title = h1.querySelector(title_selector).innerText
  25. h1.insertAdjacentHTML("afterbegin", copy_svg(title))
  26. }
  27. append_copy_button()
  28. })();