Pull out issue numbers - drupal.org

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

  1. // ==UserScript==
  2. // @name Pull out issue numbers - drupal.org
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.drupal.org/project/issues/search/*
  5. // @grant none
  6. // @version 1.0
  7. // @author Chris Wells
  8. // @license MIT
  9. // @description 11/12/2024, 3:47:07 PM
  10. // ==/UserScript==
  11. (function() {
  12. 'use strict';
  13.  
  14. // Select the table by class name
  15. const table = document.querySelector('.views-table.sticky-enabled');
  16.  
  17. // If table is not found, exit
  18. if (!table) return;
  19.  
  20. // Add a new header cell for the "Issue Number" column
  21. const headerRow = table.querySelector('thead tr');
  22. const newHeaderCell = document.createElement('th');
  23. newHeaderCell.className = 'views-field views-field-issue-number';
  24. newHeaderCell.scope = 'col';
  25. newHeaderCell.textContent = 'Issue Number';
  26. headerRow.appendChild(newHeaderCell);
  27.  
  28. // Iterate over each row in the table body
  29. const rows = table.querySelectorAll('tbody tr');
  30. rows.forEach(row => {
  31. // Find the first column with the link containing the issue number
  32. const titleCell = row.querySelector('.views-field-title a');
  33. if (titleCell) {
  34. // Extract the issue number from the href attribute
  35. const issueNumber = titleCell.href.split('/').pop();
  36. const issueText = `[#${issueNumber}]`;
  37.  
  38. // Create a new cell for the issue number with a click-to-copy functionality
  39. const issueCell = document.createElement('td');
  40. issueCell.className = 'views-field views-field-issue-number';
  41. issueCell.dataset.th = 'Issue Number';
  42.  
  43. // Create a clickable span element
  44. const issueSpan = document.createElement('span');
  45. issueSpan.textContent = issueText;
  46. issueSpan.style.cursor = 'pointer';
  47. issueSpan.style.color = 'blue'; // Optional styling for better UX
  48.  
  49. // Add event listener to copy text to clipboard on click
  50. issueSpan.addEventListener('click', () => {
  51. navigator.clipboard.writeText(issueText).then(() => {
  52. }).catch(err => {
  53. console.error('Failed to copy text: ', err);
  54. });
  55. });
  56.  
  57. // Append the span to the new cell, and the cell to the row
  58. issueCell.appendChild(issueSpan);
  59. row.appendChild(issueCell);
  60. }
  61. });
  62. })();