GitHub Enhanced Repo Buttons

Enhances GitHub repository pages with buttons to view active forks and open the repo in a VSCode-like interface.

  1. // ==UserScript==
  2. // @name GitHub Enhanced Repo Buttons
  3. // @version 1.0
  4. // @description Enhances GitHub repository pages with buttons to view active forks and open the repo in a VSCode-like interface.
  5. // @license MIT
  6. // @author Mobile46
  7. // @match https://github.com/*/*
  8. // @icon https://www.google.com/s2/favicons?domain=github.com&sz=32
  9. // @namespace https://gf.qytechs.cn/users/1466082
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function isValidRepoPage() {
  16. const path = window.location.pathname.split('/');
  17. return path.length >= 3 && !path[3];
  18. }
  19.  
  20. function getRepoInfo() {
  21. const path = window.location.pathname.split('/');
  22. if (path.length >= 3) {
  23. return {
  24. owner: path[1],
  25. repo: path[2]
  26. };
  27. }
  28. return null;
  29. }
  30.  
  31. function addButtons() {
  32. if (!isValidRepoPage()) {
  33. return;
  34. }
  35.  
  36. const repoInfo = getRepoInfo();
  37. if (!repoInfo) {
  38. console.log('Could not extract repo info');
  39. return;
  40. }
  41.  
  42. const actionsArea = document.querySelector('.pagehead-actions');
  43. if (!actionsArea) {
  44. console.log('Actions area not found');
  45. return;
  46. }
  47.  
  48. const forksLi = document.createElement('li');
  49. const forksButton = document.createElement('a');
  50. forksButton.className = 'btn-sm btn';
  51. forksButton.setAttribute('data-view-component', 'true');
  52. forksButton.href = `https://techgaun.github.io/active-forks/index.html#${repoInfo.owner}/${repoInfo.repo}`;
  53. forksButton.target = '_blank';
  54. forksButton.rel = 'noopener noreferrer';
  55. forksButton.innerHTML = `
  56. <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo-forked mr-2">
  57. <path d="M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"></path>
  58. </svg>
  59. Active Forks
  60. `;
  61. forksLi.appendChild(forksButton);
  62.  
  63. const vscodeLi = document.createElement('li');
  64. const vscodeButton = document.createElement('a');
  65. vscodeButton.className = 'btn-sm btn';
  66. vscodeButton.setAttribute('data-view-component', 'true');
  67. vscodeButton.href = `https://github1s.com/${repoInfo.owner}/${repoInfo.repo}`;
  68. vscodeButton.target = '_blank';
  69. vscodeButton.rel = 'noopener noreferrer';
  70. vscodeButton.innerHTML = `
  71. <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-code mr-2">
  72. <path d="m11.28 3.22 4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042L13.69 8 10.22 4.53a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018ZM4.72 3.22a.75.75 0 0 1 1.06 1.06L2.31 8l3.47 3.47a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-4.25-4.25a.75.75 0 0 1 0-1.06l4.25-4.25Z"></path>
  73. </svg>
  74. View in VSCode
  75. `;
  76. vscodeLi.appendChild(vscodeButton);
  77.  
  78. actionsArea.appendChild(forksLi);
  79. actionsArea.appendChild(vscodeLi);
  80. }
  81.  
  82. addButtons();
  83.  
  84. const observer = new MutationObserver(() => {
  85. if (document.querySelector('.pagehead-actions') &&
  86. !document.querySelector('a[href*="techgaun.github.io/active-forks"]') &&
  87. !document.querySelector('a[href*="github1s.com"]')) {
  88. addButtons();
  89. }
  90. });
  91.  
  92. observer.observe(document.body, {
  93. childList: true,
  94. subtree: true
  95. });
  96. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址