github-pages.user.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // ==UserScript==
  2. // @name Github Pages
  3. // @namespace Zera's Github Pages
  4. // @match https://github.com/*/*
  5. // @match https://*.github.io/*
  6. // @version 1
  7. // @grant none
  8. // ==/UserScript==
  9. // Epic Key handler from:
  10. // https://stackoverflow.com/questions/3168574/how-can-i-create-a-shortcut-for-firefox-in-greasemonkey
  11. (function(){
  12. document.addEventListener('keydown', function(e) {
  13. // pressed alt+g
  14. if (e.keyCode == 71 && !e.shiftKey && !e.ctrlKey && e.altKey && !e.metaKey) {
  15. url = window.location;
  16. path = url.pathname.split("/").filter(e => typeof e === 'string' && e != '');
  17. domain = url.host;
  18. if (domain.includes("github.io")) {
  19. // This is not perfect. Apperently any repo on github can
  20. // get turned into a github pages site. So without a path
  21. // idk what that repo is... This is better than nothing.
  22. redirect = `https://github.com/${domain.split(".")[0]}`
  23. if (path[0] != undefined) {
  24. window.location = redirect + `/${path[0]}`;
  25. } else {
  26. window.location = redirect;
  27. }
  28. } else {
  29. window.location = `https://${path[0]}.github.io/${path[1]}`;
  30. }
  31. }
  32. }, false);
  33. })();