Greasy Fork is available in English.

Github Rawgit Button

An userscript to add "Rawgit" button on github.

  1. // ==UserScript==
  2. // @name Github Rawgit Button
  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.2
  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. "use strict";
  20.  
  21. function replace(){
  22. // Check if raw-url button exists
  23. var btns, i;
  24. btns = document.querySelectorAll(".file-actions a:not(.rawgit)");
  25. for (i = 0; i < btns.length; i++) {
  26. if (btns[i].textContent == "Raw") {
  27. createButton(btns[i]);
  28. }
  29. }
  30. }
  31.  
  32. function createButton(btn) {
  33. var url = btn.href;
  34. if (url.indexOf("gist.github.com") >= 0) {
  35. url = url.replace("gist.github.com", "rawgit.com");
  36. } else {
  37. url = url.replace(/github\.com\/([^/]+\/[^/]+)\/raw/, "rawgit.com/$1");
  38. }
  39.  
  40. var newBtn = btn.cloneNode(false);
  41. newBtn.href = url;
  42. newBtn.textContent = "Rawgit";
  43. newBtn.removeAttribute("id");
  44.  
  45. btn.parentNode.insertBefore(newBtn, btn.nextSibling);
  46. btn.classList.add("rawgit");
  47. if (!btn.parentNode.classList.contains("btn-group")) {
  48. var parent = btn.parentNode,
  49. group = document.createElement("div");
  50. group.className = "btn-group";
  51. while (parent.childNodes.length) {
  52. group.appendChild(parent.childNodes[0]);
  53. }
  54. parent.appendChild(group);
  55. }
  56. }
  57.  
  58. var container =
  59. document.querySelector("#js-repo-pjax-container") ||
  60. document.querySelector("#js-pjax-container");
  61.  
  62. if (container) {
  63. new MutationObserver(function(){
  64. replace();
  65. }).observe(container, {childList: true, subtree: true});
  66. }
  67.  
  68. replace();