Greasy Fork is available in English.

Github Rawgit Button

An userscript to add "Rawgit" button on github.

2015-01-14 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  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.0
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. "use strict";
  12.  
  13. function replace(){
  14. // Check if raw-url button exists
  15. var btn = document.querySelector("#raw-url") || document.querySelector(".raw-url");
  16. if (!btn || btn.classList.contains("rawgit")) {
  17. return;
  18. }
  19.  
  20. var url = location.href;
  21. if (url.indexOf("gist.github.com") > -1) {
  22. url = url.replace("gist.github.com", "rawgit.com");
  23. url = url + "/raw/";
  24. } else {
  25. url = url.replace("github.com", "rawgit.com");
  26. url = url.replace("/blob/", "/");
  27. }
  28.  
  29. var newBtn = document.createElement("a");
  30. newBtn.href = url;
  31. newBtn.className = "minibutton";
  32. newBtn.textContent = "Rawgit";
  33.  
  34. btn.parentNode.insertBefore(newBtn, btn.nextSibling);
  35.  
  36. btn.classList.add("rawgit");
  37. }
  38.  
  39. var container =
  40. document.querySelector("#js-repo-pjax-container") ||
  41. document.querySelector("#js-pjax-container");
  42.  
  43. if (container) {
  44. new MutationObserver(function(e){
  45. replace();
  46. }).observe(container, {childList: true, subtree: true});
  47. }
  48.  
  49. replace();