Greasy Fork is available in English.

Github raw.githack.com Button

A userscript to add raw.githack.com button on Github.

As of 2019-02-04. See the latest version.

  1. // ==UserScript==
  2. // @name Github raw.githack.com Button
  3. // @version 0.1.0
  4. // @description A userscript to add raw.githack.com button on Github.
  5. // @homepageURL https://github.com/eight04/raw-githack-button#readme
  6. // @supportURL https://github.com/eight04/raw-githack-button/issues
  7. // @license MIT
  8. // @author eight <eight04@gmail.com> (https://github.com/eight04)
  9. // @namespace https://github.com/eight04
  10. // @include https://github.com/*
  11. // @include https://gist.github.com/*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (() => {
  16. const container =
  17. document.querySelector("#js-repo-pjax-container") ||
  18. document.querySelector("#js-pjax-container");
  19.  
  20. if (container) {
  21. new MutationObserver(function(){
  22. replace();
  23. }).observe(container, {childList: true, subtree: true});
  24. }
  25.  
  26. replace();
  27. function replace(){
  28. // Check if raw-url button exists
  29. var btns, i;
  30. btns = document.querySelectorAll(".file-actions a:not(.raw-githack)");
  31. for (i = 0; i < btns.length; i++) {
  32. if (btns[i].textContent == "Raw") {
  33. createButton(btns[i]);
  34. }
  35. }
  36. }
  37.  
  38. function createButton(btn) {
  39. var url = btn.href;
  40. if (url.indexOf("gist.github.com") >= 0) {
  41. url = url.replace("gist.github.com", "raw.githack.com");
  42. } else {
  43. url = url.replace(/github\.com\/([^/]+\/[^/]+)\/raw/, "raw.githack.com/$1");
  44. }
  45.  
  46. var newBtn = btn.cloneNode(false);
  47. newBtn.href = url;
  48. newBtn.textContent = "Raw Githack";
  49. newBtn.removeAttribute("id");
  50.  
  51. btn.parentNode.insertBefore(newBtn, btn.nextSibling);
  52. btn.classList.add("raw-githack");
  53. if (!btn.parentNode.classList.contains("btn-group")) {
  54. var parent = btn.parentNode,
  55. group = document.createElement("div");
  56. group.className = "btn-group";
  57. while (parent.childNodes.length) {
  58. group.appendChild(parent.childNodes[0]);
  59. }
  60. parent.appendChild(group);
  61. }
  62. }
  63. })();