GitHub Docker Image Tag Copy Button

Adds a "copy" icon next to each Docker image tag on GitHub pages that list published Docker images.

当前为 2023-05-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Docker Image Tag Copy Button
  3. // @description Adds a "copy" icon next to each Docker image tag on GitHub pages that list published Docker images.
  4. // @version 2
  5. // @match https://github.com/*
  6. // @grant GM_setClipboard
  7. // @require https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js
  8. // @license MIT
  9. // @author Howard D. Lince III
  10. // @supportURL https://twitter.com/HowardL3
  11. // @namespace https://github.com/howard3
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. function addCopyButton(tagEl) {
  18. // Create a "copy" button with an icon
  19. const copyBtn = document.createElement('button');
  20. copyBtn.classList.add('btn', 'btn-sm');
  21. copyBtn.style.marginRight = '10px';
  22. copyBtn.style.cursor = 'pointer';
  23.  
  24. const copyIcon = document.createElement('i');
  25. copyIcon.classList.add('fas', 'fa-copy');
  26. copyIcon.style.marginRight = '5px';
  27.  
  28. // Add the icon to the button
  29. copyBtn.appendChild(copyIcon);
  30.  
  31. // Add a click event listener to copy the tag text to the clipboard
  32. copyBtn.addEventListener('click', () => {
  33. GM_setClipboard(tagEl.textContent.trim());
  34. });
  35.  
  36. // Insert the "copy" button next to the Docker image tag
  37. tagEl.parentNode.insertBefore(copyBtn, tagEl.nextSibling);
  38. }
  39.  
  40. function addCopyButtons(node) {
  41. // Find all elements that contain Docker image tags with links
  42. const tagEls = node.querySelectorAll('.Box-row a.Label');
  43.  
  44. if (tagEls.length > 0) {
  45. // Loop through each Docker image tag element and add a "copy" button with an icon
  46. tagEls.forEach(addCopyButton);
  47. }
  48. }
  49.  
  50. // Add copy buttons when the page first loads
  51. addCopyButtons(document);
  52.  
  53. // Watch for changes to the DOM using a MutationObserver
  54. const observer = new MutationObserver((mutationsList) => {
  55. for (const mutation of mutationsList) {
  56. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  57. for (const addedNode of mutation.addedNodes) {
  58. // Query the added node for Docker image tags with links and add copy buttons to them
  59. addCopyButtons(addedNode);
  60. }
  61. }
  62. }
  63. });
  64.  
  65. observer.observe(document.body, { childList: true, subtree: true });
  66. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址