GitHub Project Copy Column

Grab links from a GitHub project column and copy them to the clipboard for easy pasting into a PR or issue description.

  1. // ==UserScript==
  2. // @name GitHub Project Copy Column
  3. // @namespace https://github.com/scruffian/github-project-copy-column
  4. // @version 0.2
  5. // @description Grab links from a GitHub project column and copy them to the clipboard for easy pasting into a PR or issue description.
  6. // @author Scruffian
  7. // @match https://github.com/*
  8. // @icon https://raw.githubusercontent.com/xthexder/wide-github/master/icons/icon.png
  9. // @grant none
  10. // @license GPLv2 or later
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. const copyToClipboardHelper = ( textToCopy ) => {
  16. let finalText = textToCopy;
  17.  
  18. if ( textToCopy.current ) {
  19. const parentElement = textToCopy.current.parentElement;
  20. const savedDisplay = parentElement.style.display;
  21. parentElement.style.display = 'block';
  22. finalText = textToCopy.current.innerText.replace(
  23. /([0-9]+)/g,
  24. '\r\n$1. '
  25. );
  26. parentElement.style.display = savedDisplay;
  27. }
  28.  
  29. const textarea = document.createElement( 'textarea' );
  30. textarea.value = finalText;
  31. document.body.appendChild( textarea );
  32. textarea.select();
  33. document.execCommand( 'copy' );
  34. textarea.remove();
  35. };
  36.  
  37. const columns = document.querySelectorAll('div[data-board-column]');
  38. columns.forEach( function( column ) {
  39. const titleDiv = column.querySelector( 'div > div' );
  40. const number = column.querySelector( 'div > div [data-testid=column-items-counter]' );
  41. let link = document.createElement('span');
  42.  
  43. number.title = 'Copy URLs of all cards';
  44. number.onclick = function() {
  45. const scrollableArea = column.querySelector( '.column-drop-zone' );
  46. scrollableArea.scrollTop = 0;
  47. const allLinks = [];
  48.  
  49. const getLinks = setInterval(function(){
  50. scrollableArea.scrollTop = scrollableArea.scrollTop + scrollableArea.offsetHeight;
  51. const linksForScrollPoint = column.querySelectorAll( '[data-testid=board-view-column-card] a' );
  52. linksForScrollPoint.forEach( function( link ) {
  53. if ( link.href ) {
  54. allLinks.push( link.href );
  55. }
  56. } );
  57.  
  58. if(scrollableArea.scrollTop + scrollableArea.offsetHeight + 1 >= scrollableArea.scrollHeight){
  59. clearInterval(getLinks);
  60. const uniqueLinks = new Set( allLinks );
  61. const linksString = Array.from( uniqueLinks ).join( '\n\n' );
  62. copyToClipboardHelper( linksString );
  63. alert( 'Copied ' + uniqueLinks.size + ' links to clipbard' );
  64. }
  65. }, 150);
  66. };
  67. } );
  68. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址