Find File Shortcut (GitHub)

Adds a keyboard shortcut to use GitHub's find file feature

  1. // ==UserScript==
  2. // @name Find File Shortcut (GitHub)
  3. // @namespace chriskim06
  4. // @description Adds a keyboard shortcut to use GitHub's find file feature
  5. // @include https://github.com/*/*
  6. // @version 1.6
  7. // @grant none
  8. // @locale en
  9. // ==/UserScript==
  10.  
  11. document.querySelector('html').addEventListener('keydown', function(e) {
  12. if (e.shiftKey && e.which === 80 && e.target.nodeName !== 'INPUT') {
  13. var url = window.location.href.match(/(https:\/\/github\.com\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-]+)/);
  14. if (url) {
  15. var branchMenu = document.getElementsByClassName('btn btn-sm select-menu-button js-menu-target css-truncate')[0];
  16. if (branchMenu) {
  17. var branch = branchMenu.getElementsByClassName('js-select-button css-truncate-target')[0];
  18. if (branch) {
  19. window.location.href = url[1] + '/find/' + branch.innerHTML;
  20. }
  21. }
  22. }
  23. }
  24. });
  25.