Gist Downloader Plus

Directly download GitHub gists as source files.

  1. // ==UserScript==
  2. // @name Gist Downloader Plus
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Directly download GitHub gists as source 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. ;(function () {
  15. 'use strict'
  16. // get the name of the gist
  17. const gistName = document.querySelector('.gist-blob-name').innerText
  18.  
  19. // get the raw url of the gist
  20. const rawUrl = document.querySelector('.file-actions')
  21. // get the first a element
  22. const a = rawUrl.querySelector('a')
  23. // get the href attribute
  24. const href = a.getAttribute('href')
  25.  
  26. // create button next to the raw button
  27. const button = document.createElement('button')
  28.  
  29. // copy the properties of the raw button to the new button
  30. const rawButton = document.querySelector('.file-actions a')
  31. const rawButtonStyles = getComputedStyle(a)
  32. button.textContent = rawButton.textContent
  33. button.style.cssText = rawButtonStyles.cssText
  34. button.style.marginLeft = '5px'
  35. button.style.padding = '5px'
  36. button.style.backgroundColor = 'green'
  37. button.innerText = 'Download'
  38. button.style.borderRadius = '10px'
  39.  
  40. // add the button to the rawUrl div
  41. rawUrl.appendChild(button)
  42.  
  43. button.addEventListener('click', () => {
  44. // get the raw content of the gist
  45. GM_xmlhttpRequest({
  46. method: 'GET',
  47. url: href,
  48. onload: function (response) {
  49. const blob = new Blob([response.responseText], {
  50. type: 'text/plain',
  51. })
  52. const url = URL.createObjectURL(blob)
  53. const a = document.createElement('a')
  54. a.href = url
  55. a.download = gistName
  56. a.click()
  57. },
  58. })
  59. })
  60. })()

QingJ © 2025

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