Github/Gitlab 导航栏增强

Github/Gitlab 导航增加快速跳转到个人仓库列表的链接按钮

目前为 2022-01-21 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Github/Gitlab nav enhance
  3. // @name:zh-CN Github/Gitlab 导航栏增强
  4. // @description Added link button for quick jump to personal repository list in Github/Gitlab
  5. // @description:zh-CN Github/Gitlab 导航增加快速跳转到个人仓库列表的链接按钮
  6.  
  7. // @author GallenHu
  8. // @namespace https://hgl2.com
  9. // @license MIT
  10. // @icon https://github.githubassets.com/favicons/favicon.png
  11.  
  12. // @grant none
  13. // @run-at document-end
  14. // @include *://github.com/*
  15. // @include *://gitlab.com/*
  16.  
  17. // @date 03/22/2021
  18. // @modified 01/21/2022
  19. // @version 0.2
  20. // @require https://cdn.staticfile.org/jquery/1.12.2/jquery.min.js
  21. // ==/UserScript==
  22.  
  23.  
  24. (function () {
  25. 'use strict';
  26.  
  27. const host = window.location.host;
  28. const pathname = window.location.pathname;
  29. const isGithub = host.endsWith('github.com');
  30. const isGitlab = host.endsWith('gitlab.com');
  31.  
  32. if (isGithub) {
  33. const userName = document.querySelector('meta[name="user-login"]').content;
  34.  
  35. const nav = document.querySelector('nav.d-flex');
  36. const html = `<a class="js-selected-navigation-item Header-link flex-auto mt-md-n3 mb-md-n3 py-2 py-md-3 mr-0 mr-md-3 border-top border-md-top-0 border-white-fade-15" data-ga-click="Header, click, Nav menu - item:marketplace context:user" data-octo-click="marketplace_click" data-octo-dimensions="location:nav_bar" data-selected-links="/${userName}?tab=repositories" href="/${userName}?tab=repositories">Repositories</a>
  37. <a class="js-selected-navigation-item Header-link flex-auto mt-md-n3 mb-md-n3 py-2 py-md-3 mr-0 mr-md-3 border-top border-md-top-0 border-white-fade-15" data-ga-click="Header, click, Nav menu - item:marketplace context:user" data-octo-click="marketplace_click" data-octo-dimensions="location:nav_bar" data-selected-links="/${userName}?tab=repositories" href="/${userName}?tab=stars">Stars</a>
  38. `
  39. $(nav).append(html);
  40. }
  41.  
  42. if (isGitlab) {
  43. const userName = window.gon.current_username;
  44. const nav = document.querySelector('ul.navbar-sub-nav');
  45. const html = `<ul class="nav navbar-sub-nav">
  46. <li class="nav-item">
  47. <a href="/">Repositories</a>
  48. </li>
  49. <li class="nav-item">
  50. <a href="/users/${userName}/starred">Stars</a>
  51. </li>
  52. </ul>
  53. `
  54. $(document).ready(() => {
  55. $('.title-container').append(html);
  56. });
  57.  
  58. }
  59. })();