Pull out issue numbers - drupal.org

11/12/2024, 3:47:07 PM

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Pull out issue numbers - drupal.org
// @namespace   Violentmonkey Scripts
// @match       https://www.drupal.org/project/issues/search/*
// @grant       none
// @version     1.0
// @author      Chris Wells
// @license     MIT
// @description 11/12/2024, 3:47:07 PM
// ==/UserScript==
(function() {
    'use strict';

    // Select the table by class name
    const table = document.querySelector('.views-table.sticky-enabled');

    // If table is not found, exit
    if (!table) return;

    // Add a new header cell for the "Issue Number" column
    const headerRow = table.querySelector('thead tr');
    const newHeaderCell = document.createElement('th');
    newHeaderCell.className = 'views-field views-field-issue-number';
    newHeaderCell.scope = 'col';
    newHeaderCell.textContent = 'Issue Number';
    headerRow.appendChild(newHeaderCell);

    // Iterate over each row in the table body
    const rows = table.querySelectorAll('tbody tr');
    rows.forEach(row => {
        // Find the first column with the link containing the issue number
        const titleCell = row.querySelector('.views-field-title a');
        if (titleCell) {
            // Extract the issue number from the href attribute
            const issueNumber = titleCell.href.split('/').pop();
            const issueText = `[#${issueNumber}]`;

            // Create a new cell for the issue number with a click-to-copy functionality
            const issueCell = document.createElement('td');
            issueCell.className = 'views-field views-field-issue-number';
            issueCell.dataset.th = 'Issue Number';

            // Create a clickable span element
            const issueSpan = document.createElement('span');
            issueSpan.textContent = issueText;
            issueSpan.style.cursor = 'pointer';
            issueSpan.style.color = 'blue'; // Optional styling for better UX

            // Add event listener to copy text to clipboard on click
            issueSpan.addEventListener('click', () => {
                navigator.clipboard.writeText(issueText).then(() => {
                }).catch(err => {
                    console.error('Failed to copy text: ', err);
                });
            });

            // Append the span to the new cell, and the cell to the row
            issueCell.appendChild(issueSpan);
            row.appendChild(issueCell);
        }
    });
})();