Greasy Fork is available in English.

GitHub mappenedlasting

Legg til en nedlastingsknapp,Tillater enkel nedlasting av spesifikke GitHub mappe。

Fra 11.09.2024. Se den seneste versjonen.

  1. // ==UserScript==
  2. // @name GitHub Folder Downloader
  3. // @name:zh-CN GitHub 文件夹下载器
  4. // @description:zh-CN 添加一个下载按钮,允许轻松下载特定的 GitHub 文件夹。
  5. // @name:ar GitHub تنزيل المجلد
  6. // @description:ar أضف زر التنزيل,يتيح سهولة تنزيل ملفات محددة GitHub المجلد。
  7. // @name:bg GitHub програма за изтегляне на папки
  8. // @description:bg Добавете бутон за изтегляне,Позволява лесно изтегляне на конкретни GitHub папка。
  9. // @name:cs GitHub stahovač složek
  10. // @description:cs Přidejte tlačítko stahování,Umožňuje snadné stahování konkrétních GitHub složku。
  11. // @name:da GitHub mappe downloader
  12. // @description:da Tilføj en downloadknap,Tillader nem download af specifikke GitHub folder。
  13. // @name:de GitHub Ordner-Downloader
  14. // @description:de Fügen Sie einen Download-Button hinzu,Ermöglicht das einfache Herunterladen spezifischer GitHub Ordner。
  15. // @name:el GitHub πρόγραμμα λήψης φακέλων
  16. // @description:el Προσθέστε ένα κουμπί λήψης,Επιτρέπει την εύκολη λήψη συγκεκριμένων GitHub ντοσιέ。
  17. // @name:en GitHub folder downloader
  18. // @description:en Add a download button,Allows easy downloading of specific GitHub folder。
  19. // @name:eo GitHub dosierujo elŝutilo
  20. // @description:eo Aldonu elŝutan butonon,Ebligas facilan elŝuton de specifaj GitHub dosierujo。
  21. // @name:es GitHub descargador de carpetas
  22. // @description:es Agregar un botón de descarga,Permite descargar fácilmente archivos específicos GitHub carpeta。
  23. // @name:fi GitHub kansion latausohjelma
  24. // @description:fi Lisää latauspainike,Mahdollistaa helpon lataamisen tiettyjä GitHub kansio。
  25. // @name:fr GitHub téléchargeur de dossiers
  26. // @description:fr Ajouter un bouton de téléchargement,Permet de télécharger facilement des fichiers spécifiques GitHub dossier。
  27. // @name:he GitHub הורדת תיקיות
  28. // @description:he הוסף כפתור הורדה,מאפשר הורדה קלה של ספציפיים GitHub תיקייה。
  29. // @name:hr GitHub preuzimač mapa
  30. // @description:hr Dodajte gumb za preuzimanje,Omogućuje jednostavno preuzimanje određenih GitHub mapa。
  31. // @name:hu GitHub mappa letöltő
  32. // @description:hu Letöltés gomb hozzáadása,Lehetővé teszi a konkrét GitHub mappát。
  33. // @name:id GitHub pengunduh folder
  34. // @description:id Tambahkan tombol unduh,Memungkinkan pengunduhan yang spesifik dengan mudah GitHub map。
  35. // @name:it GitHub downloader di cartelle
  36. // @description:it Aggiungi un pulsante di download,Consente un facile download di specifici GitHub cartella。
  37. // @name:ja GitHub フォルダーダウンローダー
  38. // @description:ja ダウンロードボタンを追加する,特定のファイルを簡単にダウンロードできます GitHub フォルダ。
  39. // @name:ka GitHub საქაღალდის ჩამოტვირთვა
  40. // @description:ka დაამატეთ ჩამოტვირთვის ღილაკი,საშუალებას გაძლევთ მარტივად ჩამოტვირთოთ კონკრეტული GitHub საქაღალდე。
  41. // @name:ko GitHub 폴더 다운로더
  42. // @description:ko 다운로드 버튼 추가,특정 파일을 쉽게 다운로드할 수 있습니다. GitHub 접는 사람。
  43. // @name:nl GitHub mapdownloader
  44. // @description:nl Voeg een downloadknop toe,Maakt eenvoudig downloaden van specifieke GitHub map。
  45. // @name:nb GitHub mappenedlasting
  46. // @description:nb Legg til en nedlastingsknapp,Tillater enkel nedlasting av spesifikke GitHub mappe。
  47. // @name:pl GitHub narzędzie do pobierania folderów
  48. // @description:pl Dodaj przycisk pobierania,Umożliwia łatwe pobieranie określonych GitHub falcówka。
  49. // @name:pt-BR GitHub downloader de pasta
  50. // @description:pt-BR Adicione um botão de download,Permite fácil download de arquivos específicos GitHub pasta。
  51. // @name:ro GitHub folder downloader
  52. // @description:ro Adăugați un buton de descărcare,Permite descărcarea ușoară a anumitor GitHub pliant。
  53. // @name:ru GitHub загрузчик папок
  54. // @description:ru Добавьте кнопку загрузки,Позволяет легко загружать определенные GitHub папка。
  55. // @name:sk GitHub sťahovač priečinkov
  56. // @description:sk Pridajte tlačidlo sťahovania,Umožňuje jednoduché sťahovanie konkrétnych GitHub priečinok。
  57. // @name:sr GitHub фолдер за преузимање
  58. // @description:sr Додајте дугме за преузимање,Омогућава лако преузимање одређених GitHub фолдер。
  59. // @name:sv GitHub mappnedladdare
  60. // @description:sv Lägg till en nedladdningsknapp,Tillåter enkel nedladdning av specifika GitHub mapp。
  61. // @name:th GitHub ดาวน์โหลดโฟลเดอร์
  62. // @description:th เพิ่มปุ่มดาวน์โหลด,ช่วยให้ดาวน์โหลดเฉพาะได้ง่าย GitHub โฟลเดอร์。
  63. // @name:tr GitHub klasör indirici
  64. // @description:tr İndirme düğmesi ekleyin,Belirli dosyaların kolayca indirilmesine izin verir GitHub dosya。
  65. // @name:ug GitHub ھۆججەت قىسقۇچ
  66. // @description:ug چۈشۈرۈش كۇنۇپكىسىنى قوشۇڭ,كونكرېت چۈشۈرۈشكە ئاسان يول قويىدۇ GitHub ھۆججەت قىسقۇچ。
  67. // @name:uk GitHub завантажувач папок
  68. // @description:uk Додайте кнопку завантаження,Дозволяє легко завантажувати певні GitHub папку。
  69. // @name:vi GitHub trình tải xuống thư mục
  70. // @description:vi Thêm nút tải xuống,Cho phép dễ dàng tải xuống cụ thể GitHub thư mục。
  71. // @name:zh-TW GitHub 資料夾下載器
  72. // @description:zh-TW 新增一個下載按鈕,允許輕鬆下載特定的 GitHub 資料夾。
  73. // @name:zh-HK GitHub 資料夾下載器
  74. // @description:zh-HK 新增一個下載按鈕,允許輕鬆下載特定的 GitHub 資料夾。
  75. // @name:fr-CA GitHub téléchargeur de dossiers
  76. // @description:fr-CA Ajouter un bouton de téléchargement,Permet de télécharger facilement des fichiers spécifiques GitHub dossier。
  77. // @description To add a download button for a GitHub folder, which allows easy downloading of a specific folder, you can follow these steps
  78. // @namespace https://github.com/ChinaGodMan/UserScripts
  79. // @version 0.7.0.22
  80. // @author EricKwok,人民的勤务员 <toniaiwanowskiskr47@gmail.com>
  81. // @supportURL https://github.com/ChinaGodMan/UserScripts/issues
  82. // @homepageURL https://github.com/ChinaGodMan/UserScripts
  83. // @match *://github.com/*
  84. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAADY0lEQVR42q1XTUwTURDek3pQEw+7/dmlqbSlaFFBiZgQA0JEDwjIBTwT4pF4RgxyQsSgQOGCBzApBsQTJnjgxxCinrDeeoDYlDSpJEArxLb8jO9LKKnt27K0+yWTwM68mXkz82amgla4XK5TJkm6Z5Qkt1EU5xn5DJL0B4S/8Q08yEBW0AtWUTQyxcMGUQwzIo0UxhmcFbKF3W4/zZR0mQyGHSjNhnAWOqArm1t/gxI9CLo0R0ORpKssnwEc1JOgE7qPvTnHuK5OwIZqzlPDfru8nB63ttIlp/PExgrsdmptaaG71dVp6eDWBIolVcm7sTEC9vb2yOPx0JWiIsL3/IsXqbKighrq6uhhfT3dqawkh81G4BUWFNDbkRGKx+MEfJqe5tVEV1roedW+vLxMydjZ3iafz0cHBwfEw8rKCm1tbVEy/H4/93X8lwq8WV4YvV4v5Yq1tTW1lzF81OHUmszkxATlitnZWdVmBdsCWidPIN9qpUAgQLliY2ODLhcWcp2AbYTfzWMODgyQXhj3eNTS4BYwRHjM1dVV0gvhcJjrAGzDAR8v/HrjRkkJzwGfgHGayrhZWkp6435NTZoDsI0aSHv/NtZodAYuxauBHTjg5+VnfX2d9EI0GiWLovAc+AUHvvMc+DA5SXphfm5OdUwLJlF8w2MiZ3rhUXMz1wHYRiNq5DFBQ2435Yr34+Okph+2BafTeY79E1EJEb3o7qbd3V06KTCwcAGz0ajmQMQlimcTw2gwwXjW0UEfp6YwYo+ErxcX08ueHvqysECbm5ukhkgkQouLi/S6r49ulZVlXk4MhgEhAUUU7cyJGBhOh4NgCKO3uqoq7eCD2lrVcdzY0KB1R4zmSZItdSF5nhCw5+dTMBhEO04bJJ9nZkgNS0tLWh3o5K5krDN5E0JP2toI+B0K0fDQED1tbydsSLFYjFSA9BxrHDZU13Sz2ZzHhIIQRPFglp8UssmUyYEgbAiZIEvStWQnmpuaCNU8NjpKr3p7aX9/nzIgU9UHoVvQAlmWFRaqHzxFWDYzAPseL+w/2c0t2fw060TFJitDX88EJp9cbDFGXVar9YyQLfBc2Jvtxw4nm81/WQQGiegroxCj+CGFDr/158lyBGMW246iKA5BL6BrWSyWC1rSx6J3Xqvef4nmwJHOHrGpAAAAAElFTkSuQmCC
  85. // @iconbak https://i.loli.net/2021/03/30/ULV9XunaHesqGIR.png
  86. // @run-at document-idle
  87. // @grant none
  88. // @license MIT
  89. // ==/UserScript==
  90. // 记录页面宽度是否允许 GitHub 展开完整页面的变量
  91. var isFold = false
  92. var isRun = false
  93. function observeAndAddLinks() {
  94. const parentElement = document.querySelector('#__primerPortalRoot__')
  95. if (!parentElement) return
  96. const observer = new MutationObserver((mutationsList) => {
  97. for (const mutation of mutationsList) {
  98. if (mutation.addedNodes.length > 0) {
  99. for (const node of mutation.addedNodes) {
  100. const ulElement = parentElement.querySelector('ul[role="menu"]')
  101. if (document.querySelector('.github-folder-download')) return
  102. console.log(node)
  103. if (ulElement) {
  104. const _html = `
  105. <li class="github-folder-download">
  106. <p style="padding:0px 8px 2px 10px; color:grey; margin:0; font-size:10px;">Download folder with..</p>
  107. </li>
  108. <a class="dropdown-item" target="_blank" href="https://download-directory.github.io?url=${window.location.href}">
  109. download-directory
  110. </a>
  111. <a class="dropdown-item" target="_blank" href="https://downgit.github.io/#/home?url=${window.location.href}">
  112. DownGit
  113. </a>
  114. <li class="d-block d-md-none dropdown-divider github-folder-download" role="none"></li>`
  115. ulElement.insertAdjacentHTML("beforeend", _html)
  116. }
  117. return
  118. }
  119. }
  120. }
  121. })
  122. const config = { childList: true, subtree: true }
  123. if (!isRun) {
  124. isRun = true
  125. observer.observe(parentElement, config)
  126. }
  127. return true
  128. }
  129. observeAndAddLinks()
  130. // 注入下载文件夹按钮
  131. function injectDownloadFolderBtn() {
  132. if (document.querySelector('.github-folder-download')) return
  133. if (!isFold) {
  134. // 展开状态(PC端)
  135. let html = document.querySelector('[data-testid="tree-overflow-menu-anchor"]')//.types__StyledButton-sc-ws60qy-0.feqCqy
  136. let _html = `
  137. <details data-view-component="true" class="details-overlay details-reset position-relative mr-2 github-folder-download">
  138. <summary role="button" data-view-component="true">
  139. <span class="btn d-none d-md-flex flex-items-center">
  140. Download folder
  141. <span class="dropdown-caret ml-1"></span>
  142. </span>
  143. <span class="btn d-inline-block d-md-none">
  144. <svg aria-label="More options" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-kebab-horizontal">
  145. <path d="M8 9a1.5 1.5 0 100-3 1.5 1.5 0 000 3zM1.5 9a1.5 1.5 0 100-3 1.5 1.5 0 000 3zm13 0a1.5 1.5 0 100-3 1.5 1.5 0 000 3z"></path>
  146. </svg>
  147. </span>
  148. </summary>
  149. <div class="dropdown-menu dropdown-menu-sw" style="top:32px;width:220px;">
  150. <ul class="list-style-none">
  151. <li class="Box-row Box-row--hover-gray p-3 mt-0">
  152. <a class="d-flex flex-items-center color-text-primary text-bold no-underline" rel="noopener" target="_blank" href="https://download-directory.github.io?url=${window.location.href}">
  153. With download - directory
  154. </a >
  155. </li >
  156. <li class="Box-row Box-row--hover-gray p-3 mt-0">
  157. <a class="d-flex flex-items-center color-text-primary text-bold no-underline" rel="noopener" target="_blank" href="https://downgit.github.io/#/home?url=${window.location.href}">
  158. With DownGit
  159. </a>
  160. </li>
  161. </ul >
  162. </div >
  163. </detials>`
  164. html.insertAdjacentHTML("beforebegin", _html)
  165. } else {
  166. observeAndAddLinks()
  167. }
  168. }
  169. function removeAllInjectedElem() {
  170. document.querySelectorAll(".github-folder-download").forEach(elem => elem.remove())
  171. }
  172. function detectFoldUnfold() {
  173. if (document.body.clientWidth <= 1200 && !isFold) {
  174. console.log("收起" + document.body.clientWidth)
  175. isFold = true
  176. } else if (document.body.clientWidth > 1200 && isFold) {
  177. console.log("展开" + document.body.clientWidth)
  178. isFold = false
  179. }
  180. }
  181. function reinject() {
  182. if (document.querySelector(".octicon.octicon-copy")) {//复制路径的元素
  183. // 仅当处于文件夹内时注入按钮
  184. removeAllInjectedElem()
  185. injectDownloadFolderBtn()
  186. }
  187. }
  188. function main() {
  189. detectFoldUnfold()
  190. reinject()
  191. }
  192. (function () {
  193. 'use strict'
  194. /**
  195. * 在浏览器窗口大小改变时自动重新定位设置菜单
  196. */
  197. window.onresize = function () {
  198. // 监听窗口大小改变
  199. main()
  200. }
  201. function observeUrlChanges(callback, delay = 1000) {
  202. let lastUrl = location.href
  203. const observer = new MutationObserver(() => {
  204. const url = location.href
  205. if (url !== lastUrl) {
  206. lastUrl = url
  207. setTimeout(() => {
  208. console.log("页面发生变动,")
  209. callback()
  210. }, delay)
  211. }
  212. })
  213. observer.observe(document, { subtree: true, childList: true })
  214. return observer
  215. }
  216. observeUrlChanges(main)
  217. main()
  218. })()