Pull out issue numbers - drupal.org

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

目前為 2024-11-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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);
        }
    });
})();