Gist Downloader Plus

Enhance your GitHub experience with Gist Downloader Plus. This userscript adds a download button to GitHub gists, allowing you to easily download them as source files (instead of zip files).

当前为 2024-03-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Gist Downloader Plus
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Enhance your GitHub experience with Gist Downloader Plus. This userscript adds a download button to GitHub gists, allowing you to easily download them as source files (instead of zip files).
  6. // @author Ahmed Mohamed Abdelaty
  7. // @match https://gist.github.com/*/*
  8. // @grant GM_addStyle
  9. // @grant GM_xmlhttpRequest
  10. // @grant GM_download
  11. // @license MIT; https://opensource.org/licenses/MIT
  12. // ==/UserScript==
  13.  
  14. // to download the gist as a file
  15. ;(function () {
  16. 'use strict'
  17. // get the name of the gist
  18. const gistName = document.querySelector('.gist-blob-name').innerText
  19.  
  20. // get the raw url of the gist
  21. const rawUrl = document.querySelector('.file-actions')
  22. // get the first a element
  23. const a = rawUrl.querySelector('a')
  24. // get the href attribute
  25. const href = a.getAttribute('href')
  26.  
  27. // create button next to the raw button
  28. const button = document.createElement('button')
  29.  
  30. // copy the properties of the raw button to the new button
  31. const rawButton = document.querySelector('.file-actions a')
  32. const rawButtonStyles = getComputedStyle(a)
  33. button.textContent = rawButton.textContent
  34. button.style.cssText = rawButtonStyles.cssText
  35. button.style.marginLeft = '5px'
  36. button.style.padding = '5px'
  37. button.style.backgroundColor = 'green'
  38. button.innerText = 'Download'
  39. button.style.borderRadius = '10px'
  40.  
  41. // add the button to the rawUrl div
  42. rawUrl.appendChild(button)
  43.  
  44. button.addEventListener('click', () => {
  45. // get the raw content of the gist
  46. GM_xmlhttpRequest({
  47. method: 'GET',
  48. url: href,
  49. onload: function (response) {
  50. const blob = new Blob([response.responseText], {
  51. type: 'text/plain',
  52. })
  53. const url = URL.createObjectURL(blob)
  54. const a = document.createElement('a')
  55. a.href = url
  56. a.download = gistName
  57. a.click()
  58. },
  59. })
  60. })
  61. })()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址