GitHub Folder Downloader

Allows you to download subfolders from GitHub repository pages.

目前为 2025-04-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Folder Downloader
  3. // @description Allows you to download subfolders from GitHub repository pages.
  4. // @icon https://github.githubassets.com/favicons/favicon-dark.svg
  5. // @version 1.2
  6. // @author afkarxyz
  7. // @namespace https://github.com/afkarxyz/userscripts/
  8. // @supportURL https://github.com/afkarxyz/userscripts/issues
  9. // @license MIT
  10. // @match https://github.com/*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const style = document.createElement('style');
  18. style.textContent = `
  19. .github-subfolder-download-icon {
  20. cursor: pointer;
  21. transition: transform 0.1s ease;
  22. }
  23. .github-subfolder-download-icon:hover {
  24. transform: scale(1.1);
  25. }
  26. `;
  27. document.head.appendChild(style);
  28.  
  29. function replaceFolderIcons() {
  30. const directoryRows = document.querySelectorAll('tr.react-directory-row');
  31. directoryRows.forEach(row => {
  32. const svgIcons = row.querySelectorAll('.react-directory-filename-column svg.icon-directory');
  33. svgIcons.forEach(svg => {
  34. if (!svg.dataset.replaced) {
  35. svg.innerHTML = `
  36. <path d="M14.2,3H7.5C7.4,3,7.3,3,7.3,2.9L6.4,1.7C6.1,1.3,5.5,1,5,1H1.8C0.8,1,0,1.8,0,2.8v10.5c0,1,0.8,1.8,1.8,1.8h12.5
  37. c1,0,1.8-0.8,1.8-1.8V4.8C16,3.8,15.2,3,14.2,3z M10.8,9.8l-2.4,2.4c-0.2,0.2-0.6,0.2-0.8,0L5.2,9.8C5,9.6,5,9.2,5.2,9
  38. C5.3,8.7,5.8,8.7,6,9l1.4,1.3V7c0-0.3,0.3-0.6,0.6-0.6S8.5,6.7,8.5,7v3.3L10,9c0.2-0.2,0.6-0.2,0.8,0C11,9.2,11,9.6,10.8,9.8z"/>
  39. `;
  40. svg.classList.add('github-subfolder-download-icon');
  41. svg.dataset.replaced = 'true';
  42.  
  43. const folderLink = row.querySelector('a[href*="/tree/"]');
  44. if (folderLink) {
  45. const fullUrl = folderLink.href;
  46. const downloadUrl = `https://downgit.evecalm.com/#/home?url=${encodeURIComponent(fullUrl)}`;
  47.  
  48. svg.addEventListener('click', (e) => {
  49. e.preventDefault();
  50. e.stopPropagation();
  51. window.open(downloadUrl, '_blank');
  52. });
  53. }
  54. }
  55. });
  56. });
  57. }
  58.  
  59. const observer = new MutationObserver((mutations) => {
  60. for (let mutation of mutations) {
  61. if (mutation.type === 'childList') {
  62. replaceFolderIcons();
  63. }
  64. }
  65. });
  66.  
  67. observer.observe(document.body, { childList: true, subtree: true });
  68.  
  69. replaceFolderIcons();
  70. })();