// ==UserScript== // @name GitHub 文件夹下载 // @namespace https://github.com/the-eric-kwok/ // @version 0.1 // @description 为 GitHub 文件夹增加一个下载按钮,可以方便地下载某个文件夹 // @author EricKwok // @match *://github.com/* // @icon https://i.loli.net/2021/03/30/ULV9XunaHesqGIR.png // @grant none // @downloadURL none // ==/UserScript== // 注入下载文件夹按钮 function injectDownloadFolderBtn() { if (document.querySelector('.EricKwok')) return; var html = document.querySelector(".btn.mr-2.d-none.d-md-block"); if (!html) return; var _html = `
Download folder `; html.insertAdjacentHTML("beforebegin", _html); } function main() { if (document.querySelector(".file-navigation") && !document.querySelector('.dropdown-menu.dropdown-menu-sw.p-0')) { // 当不在仓库的根目录时注入按钮 injectDownloadFolderBtn(); } } (function() { 'use strict'; document.addEventListener('pjax:success',function(){ // 由于 GitHub 使用 pjax 而不是页面跳转的方式在仓库内导航,因此将 main 函数绑定到 pjax 监听器上 main(); }); main(); })();