GitHub Ordner-Downloader

Fügen Sie einen Download-Button hinzu,Ermöglicht das einfache Herunterladen spezifischer GitHub Ordner。

Version vom 11.09.2024. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        GitHub Folder Downloader
// @name:zh-CN    GitHub 文件夹下载器
// @description:zh-CN  添加一个下载按钮,允许轻松下载特定的 GitHub 文件夹。
// @name:ar    GitHub تنزيل المجلد
// @description:ar  أضف زر التنزيل,يتيح سهولة تنزيل ملفات محددة GitHub المجلد。
// @name:bg    GitHub програма за изтегляне на папки
// @description:bg  Добавете бутон за изтегляне,Позволява лесно изтегляне на конкретни GitHub папка。
// @name:cs    GitHub stahovač složek
// @description:cs  Přidejte tlačítko stahování,Umožňuje snadné stahování konkrétních GitHub složku。
// @name:da    GitHub mappe downloader
// @description:da  Tilføj en downloadknap,Tillader nem download af specifikke GitHub folder。
// @name:de    GitHub Ordner-Downloader
// @description:de  Fügen Sie einen Download-Button hinzu,Ermöglicht das einfache Herunterladen spezifischer GitHub Ordner。
// @name:el    GitHub πρόγραμμα λήψης φακέλων
// @description:el  Προσθέστε ένα κουμπί λήψης,Επιτρέπει την εύκολη λήψη συγκεκριμένων GitHub ντοσιέ。
// @name:en    GitHub folder downloader
// @description:en  Add a download button,Allows easy downloading of specific GitHub folder。
// @name:eo    GitHub dosierujo elŝutilo
// @description:eo  Aldonu elŝutan butonon,Ebligas facilan elŝuton de specifaj GitHub dosierujo。
// @name:es    GitHub descargador de carpetas
// @description:es  Agregar un botón de descarga,Permite descargar fácilmente archivos específicos GitHub carpeta。
// @name:fi    GitHub kansion latausohjelma
// @description:fi  Lisää latauspainike,Mahdollistaa helpon lataamisen tiettyjä GitHub kansio。
// @name:fr    GitHub téléchargeur de dossiers
// @description:fr  Ajouter un bouton de téléchargement,Permet de télécharger facilement des fichiers spécifiques GitHub dossier。
// @name:he    GitHub הורדת תיקיות
// @description:he  הוסף כפתור הורדה,מאפשר הורדה קלה של ספציפיים GitHub תיקייה。
// @name:hr    GitHub preuzimač mapa
// @description:hr  Dodajte gumb za preuzimanje,Omogućuje jednostavno preuzimanje određenih GitHub mapa。
// @name:hu    GitHub mappa letöltő
// @description:hu  Letöltés gomb hozzáadása,Lehetővé teszi a konkrét GitHub mappát。
// @name:id    GitHub pengunduh folder
// @description:id  Tambahkan tombol unduh,Memungkinkan pengunduhan yang spesifik dengan mudah GitHub map。
// @name:it    GitHub downloader di cartelle
// @description:it  Aggiungi un pulsante di download,Consente un facile download di specifici GitHub cartella。
// @name:ja    GitHub フォルダーダウンローダー
// @description:ja  ダウンロードボタンを追加する,特定のファイルを簡単にダウンロードできます GitHub フォルダ。
// @name:ka    GitHub საქაღალდის ჩამოტვირთვა
// @description:ka  დაამატეთ ჩამოტვირთვის ღილაკი,საშუალებას გაძლევთ მარტივად ჩამოტვირთოთ კონკრეტული GitHub საქაღალდე。
// @name:ko    GitHub 폴더 다운로더
// @description:ko  다운로드 버튼 추가,특정 파일을 쉽게 다운로드할 수 있습니다. GitHub 접는 사람。
// @name:nl    GitHub mapdownloader
// @description:nl  Voeg een downloadknop toe,Maakt eenvoudig downloaden van specifieke GitHub map。
// @name:nb    GitHub mappenedlasting
// @description:nb  Legg til en nedlastingsknapp,Tillater enkel nedlasting av spesifikke GitHub mappe。
// @name:pl    GitHub narzędzie do pobierania folderów
// @description:pl  Dodaj przycisk pobierania,Umożliwia łatwe pobieranie określonych GitHub falcówka。
// @name:pt-BR    GitHub downloader de pasta
// @description:pt-BR  Adicione um botão de download,Permite fácil download de arquivos específicos GitHub pasta。
// @name:ro    GitHub folder downloader
// @description:ro  Adăugați un buton de descărcare,Permite descărcarea ușoară a anumitor GitHub pliant。
// @name:ru    GitHub загрузчик папок
// @description:ru  Добавьте кнопку загрузки,Позволяет легко загружать определенные GitHub папка。
// @name:sk    GitHub sťahovač priečinkov
// @description:sk  Pridajte tlačidlo sťahovania,Umožňuje jednoduché sťahovanie konkrétnych GitHub priečinok。
// @name:sr    GitHub фолдер за преузимање
// @description:sr  Додајте дугме за преузимање,Омогућава лако преузимање одређених GitHub фолдер。
// @name:sv    GitHub mappnedladdare
// @description:sv  Lägg till en nedladdningsknapp,Tillåter enkel nedladdning av specifika GitHub mapp。
// @name:th    GitHub ดาวน์โหลดโฟลเดอร์
// @description:th  เพิ่มปุ่มดาวน์โหลด,ช่วยให้ดาวน์โหลดเฉพาะได้ง่าย GitHub โฟลเดอร์。
// @name:tr    GitHub klasör indirici
// @description:tr  İndirme düğmesi ekleyin,Belirli dosyaların kolayca indirilmesine izin verir GitHub dosya。
// @name:ug    GitHub ھۆججەت قىسقۇچ
// @description:ug  چۈشۈرۈش كۇنۇپكىسىنى قوشۇڭ,كونكرېت چۈشۈرۈشكە ئاسان يول قويىدۇ GitHub ھۆججەت قىسقۇچ。
// @name:uk    GitHub завантажувач папок
// @description:uk  Додайте кнопку завантаження,Дозволяє легко завантажувати певні GitHub папку。
// @name:vi    GitHub trình tải xuống thư mục
// @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。
// @name:zh-TW    GitHub 資料夾下載器
// @description:zh-TW  新增一個下載按鈕,允許輕鬆下載特定的 GitHub 資料夾。
// @name:zh-HK    GitHub 資料夾下載器
// @description:zh-HK  新增一個下載按鈕,允許輕鬆下載特定的 GitHub 資料夾。
// @name:fr-CA    GitHub téléchargeur de dossiers
// @description:fr-CA  Ajouter un bouton de téléchargement,Permet de télécharger facilement des fichiers spécifiques GitHub dossier。
// @description  To add a download button for a GitHub folder, which allows easy downloading of a specific folder, you can follow these steps
// @namespace               https://github.com/ChinaGodMan/UserScripts
// @version 0.7.0.21
// @author       EricKwok,人民的勤务员 <[email protected]>
// @supportURL              https://github.com/ChinaGodMan/UserScripts/issues
// @homepageURL   https://github.com/ChinaGodMan/UserScripts
// @match        *://github.com/*
// @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
// @iconbak https://i.loli.net/2021/03/30/ULV9XunaHesqGIR.png
// @run-at       document-idle
// @grant        none
// @license      MIT
// ==/UserScript==
// 记录页面宽度是否允许 GitHub 展开完整页面的变量
var isFold = false
var isRun = false
function observeAndAddLinks() {
    const parentElement = document.querySelector('#__primerPortalRoot__')
    if (!parentElement) return
    const observer = new MutationObserver((mutationsList) => {
        for (const mutation of mutationsList) {
            if (mutation.addedNodes.length > 0) {
                for (const node of mutation.addedNodes) {
                    const ulElement = parentElement.querySelector('ul[role="menu"]')
                    if (document.querySelector('.github-folder-download')) return
                    console.log(node)
                    if (ulElement) {
                        const _html = `
                            <li class="github-folder-download">
                                <p style="padding:0px 8px 2px 10px; color:grey; margin:0; font-size:10px;">Download folder with..</p>
                            </li>
                            <a class="dropdown-item" target="_blank" href="https://download-directory.github.io?url=${window.location.href}">
                                download-directory
                            </a>
                            <a class="dropdown-item" target="_blank" href="https://downgit.github.io/#/home?url=${window.location.href}">
                                DownGit
                            </a>
                            <li class="d-block d-md-none dropdown-divider github-folder-download" role="none"></li>`
                        ulElement.insertAdjacentHTML("beforeend", _html)
                    }
                    return
                }
            }
        }
    })
    const config = { childList: true, subtree: true }
    if (!isRun) {
        isRun = true
        observer.observe(parentElement, config)
    }
    return true
}
observeAndAddLinks()
// 注入下载文件夹按钮
function injectDownloadFolderBtn() {
    if (document.querySelector('.github-folder-download')) return
    if (!isFold) {
        // 展开状态(PC端)
        let html = document.querySelector('[data-testid="tree-overflow-menu-anchor"]')//.types__StyledButton-sc-ws60qy-0.feqCqy
        let _html = `
            <details data-view-component="true" class="details-overlay details-reset position-relative mr-2 github-folder-download">
                <summary role="button" data-view-component="true">
                    <span class="btn d-none d-md-flex flex-items-center">
                        Download folder
                        <span class="dropdown-caret ml-1"></span>
                    </span>
                    <span class="btn d-inline-block d-md-none">
                        <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">
                            <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>
                        </svg>
                    </span>
                </summary>
                <div class="dropdown-menu dropdown-menu-sw" style="top:32px;width:220px;">
                    <ul class="list-style-none">
                        <li class="Box-row Box-row--hover-gray p-3 mt-0">
                            <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}">
                            With download - directory
                            </a >
                        </li >
                        <li class="Box-row Box-row--hover-gray p-3 mt-0">
                            <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}">
                                With DownGit
                            </a>
                        </li>
                    </ul >
                </div >
            </detials>`
        html.insertAdjacentHTML("beforebegin", _html)
    } else {
        observeAndAddLinks()
    }
}
function removeAllInjectedElem() {
    document.querySelectorAll(".github-folder-download").forEach(elem => elem.remove())
}
function detectFoldUnfold() {
    if (document.body.clientWidth <= 1200 && !isFold) {
        console.log("收起" + document.body.clientWidth)
        isFold = true
    } else if (document.body.clientWidth > 1200 && isFold) {
        console.log("展开" + document.body.clientWidth)
        isFold = false
    }
}
function reinject() {
    if (document.querySelector(".octicon.octicon-copy")) {//复制路径的元素
        // 仅当处于文件夹内时注入按钮
        removeAllInjectedElem()
        injectDownloadFolderBtn()
    }
}
function main() {
    detectFoldUnfold()
    reinject()
}
(function () {
    'use strict'
    /**
     * 在浏览器窗口大小改变时自动重新定位设置菜单
     */
    window.onresize = function () {
        // 监听窗口大小改变
        main()
    }
    function observeUrlChanges(callback, delay = 1000) {
        let lastUrl = location.href
        const observer = new MutationObserver(() => {
            const url = location.href
            if (url !== lastUrl) {
                lastUrl = url
                setTimeout(() => {
                    console.log("页面发生变动,")
                    callback()
                }, delay)
            }
        })
        observer.observe(document, { subtree: true, childList: true })
        return observer
    }
    observeUrlChanges(main)
    main()
})()