Pull out issue numbers - drupal.org

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

当前为 2024-11-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
        }
    });
})();