Greasy Fork 支持简体中文。

Github Githack.com (Rawgit) Button 2021

An userscript to add "Rawgit" button on github.

  1. // ==UserScript==
  2. // @name Github Githack.com (Rawgit) Button 2021
  3. // @namespace eight04.blogspot.com
  4. // @description An userscript to add "Rawgit" button on github.
  5. // @include https://github.com/*
  6. // @include https://gist.github.com/*
  7. // @version 1.2.3
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /*
  12. https://gist.github.com/eight04/186267c150a2dfc0580a/raw/812fd7b418e0a157f02caa144a15c55c06ced8ac/uao_decode.py
  13. https://rawgit.com/eight04/186267c150a2dfc0580a/raw/812fd7b418e0a157f02caa144a15c55c06ced8ac/uao_decode.py
  14.  
  15. https://github.com/eight04/linky-square/raw/master/demo.html
  16. https://rawgit.com/eight04/linky-square/master/demo.html
  17.  
  18.  
  19. https://github.com/neoascetic/rawgithack/blob/master/index.html
  20. https://raw.githack.com/neoascetic/rawgithack/master/index.html
  21.  
  22. https://raw.githack.com/neoascetic/rawgithack/master/index.html
  23. */
  24.  
  25.  
  26.  
  27.  
  28. "use strict";
  29.  
  30. function replace(){
  31. // Check if raw-url button exists
  32. var btns, i;
  33. btns = document.querySelectorAll(".BtnGroup a:not(.rawgit)");
  34. for (i = 0; i < btns.length; i++) {
  35. if (btns[i].innerText == "Raw") {
  36. createButton(btns[i]);
  37. }
  38. }
  39. }
  40.  
  41. function createButton(btn) {
  42. var url = btn.href;
  43. if (url.indexOf("gist.github.com") >= 0) {
  44. url = url.replace("gist.github.com", "raw.githack.com");
  45. } else {
  46. url = url.replace(/github\.com\/([^/]+\/[^/]+)\/raw/, "raw.githack.com/$1");
  47. }
  48.  
  49. var newBtn = btn.cloneNode(false);
  50. newBtn.href = url;
  51. newBtn.textContent = "Rawgit";
  52. newBtn.removeAttribute("id");
  53.  
  54. btn.parentNode.insertBefore(newBtn, btn.nextSibling);
  55. btn.classList.add("rawgit");
  56. if (!btn.parentNode.classList.contains("btn-group")) {
  57. var parent = btn.parentNode,
  58. group = document.createElement("div");
  59. group.className = "btn-group";
  60. while (parent.childNodes.length) {
  61. group.appendChild(parent.childNodes[0]);
  62. }
  63. parent.appendChild(group);
  64. }
  65. }
  66.  
  67. var container =
  68. document.querySelector("#js-repo-pjax-container") ||
  69. document.querySelector("#js-pjax-container");
  70.  
  71. if (container) {
  72. new MutationObserver(function(){
  73. replace();
  74. }).observe(container, {childList: true, subtree: true});
  75. }
  76.  
  77. replace();