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.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         GitHub Project Copy Column
// @namespace    https://github.com/scruffian/github-project-copy-column
// @version      0.2
// @description  Grab links from a GitHub project column and copy them to the clipboard for easy pasting into a PR or issue description.
// @author       Scruffian
// @match        https://github.com/*
// @icon         https://raw.githubusercontent.com/xthexder/wide-github/master/icons/icon.png
// @grant        none
// @license      GPLv2 or later
// ==/UserScript==

(function() {
    'use strict';
    const copyToClipboardHelper = ( textToCopy ) => {
        let finalText = textToCopy;

        if ( textToCopy.current ) {
            const parentElement = textToCopy.current.parentElement;
            const savedDisplay = parentElement.style.display;
            parentElement.style.display = 'block';
            finalText = textToCopy.current.innerText.replace(
                /([0-9]+)/g,
                '\r\n$1. '
            );
            parentElement.style.display = savedDisplay;
        }

        const textarea = document.createElement( 'textarea' );
        textarea.value = finalText;
        document.body.appendChild( textarea );
        textarea.select();
        document.execCommand( 'copy' );
        textarea.remove();
    };

    const columns = document.querySelectorAll('div[data-board-column]');
    columns.forEach( function( column ) {
        const titleDiv = column.querySelector( 'div > div' );
        const number = column.querySelector( 'div > div [data-testid=column-items-counter]' );
        let link = document.createElement('span');

        number.title = 'Copy URLs of all cards';
        number.onclick = function() {
            const scrollableArea = column.querySelector( '.column-drop-zone' );
            scrollableArea.scrollTop = 0;
            const allLinks = [];

            const getLinks = setInterval(function(){
                scrollableArea.scrollTop = scrollableArea.scrollTop + scrollableArea.offsetHeight;
                const linksForScrollPoint = column.querySelectorAll( '[data-testid=board-view-column-card] a' );
                linksForScrollPoint.forEach( function( link ) {
                    if ( link.href ) {
                        allLinks.push( link.href );
                    }
                } );

                if(scrollableArea.scrollTop + scrollableArea.offsetHeight + 1 >= scrollableArea.scrollHeight){
                    clearInterval(getLinks);
                    const uniqueLinks = new Set( allLinks );
                    const linksString = Array.from( uniqueLinks ).join( '\n\n' );
                    copyToClipboardHelper( linksString );
                    alert( 'Copied ' + uniqueLinks.size + ' links to clipbard' );
                }
            }, 150);
        };
    } );
})();