DownGit

Create GitHub Resource Download Link.

当前为 2022-04-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name DownGit
  3. // @namespace http://mogeko.me
  4. // @version 0.0.1
  5. // @description Create GitHub Resource Download Link.
  6. // @author mogeko
  7. // @match https://github.com/*/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
  9. // @run-at document-idle
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. /**
  14. * <div role="row">
  15. * <div><svg class={{icon}}/></div>,
  16. * <div><span><a>{{name}}</a></span></div>,
  17. * <div><span><a>{{message}}</a></span></div>,
  18. * <div><span>{time}</span></div>,
  19. * </div>
  20. */
  21.  
  22. const svg_icon = `<svg class="octicon octicon-download hx_color-icon-directory" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M7.47 10.78a.75.75 0 001.06 0l3.75-3.75a.75.75 0 00-1.06-1.06L8.75 8.44V1.75a.75.75 0 00-1.5 0v6.69L4.78 5.97a.75.75 0 00-1.06 1.06l3.75 3.75zM3.75 13a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5z"/></svg>`;
  23.  
  24. const downloader = (local_url) =>
  25. `https://minhaskamal.github.io/DownGit/#/home?url=${local_url}`;
  26.  
  27. const getButton = (file_title, url) => {
  28. const div = document.createElement("div");
  29. div.className = "mr-3 flex-shrink-0";
  30. const a = document.createElement("a");
  31. a.href = downloader(url);
  32. a.title = `Download ${file_title}.zip`;
  33. a.innerHTML = svg_icon;
  34. div.appendChild(a);
  35. return div;
  36. };
  37.  
  38. (function () {
  39. "use strict";
  40.  
  41. const context = document.querySelectorAll("div.Box-row");
  42. context.forEach((node) => {
  43. const url = node.querySelector("a");
  44. const last_child = node.querySelector("div.text-right");
  45. if (url.querySelector("span")) return;
  46. const button = getButton(url.innerHTML, url.href);
  47. node.insertBefore(button, last_child);
  48. });
  49. })();