GitHub Homepage Button

Adds a "Homepage" button to GitHub repository search results to quickly access the repository's homepage URL.

  1. // ==UserScript==
  2. // @name GitHub Homepage Button
  3. // @description Adds a "Homepage" button to GitHub repository search results to quickly access the repository's homepage URL.
  4. // @version 1
  5. // @match https://github.com/search?*
  6. // @namespace https://gist.github.com/bethropolis/37cfb3821ad2321b53749ca097ec2963
  7. // @author bethropolis
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const repoList = document.querySelector(".repo-list");
  17. if (repoList) {
  18. const repos = repoList.querySelectorAll("li");
  19. for (const repo of repos) {
  20. const repoLink = repo.querySelector(" div > div > div > a");
  21. if (repoLink) {
  22. const repoUrl = repoLink.getAttribute("href");
  23. const parts = repoUrl.split("/");
  24. const owner = parts[parts.length - 2];
  25. const repoName = parts[parts.length - 1];
  26. const repoListItem = repo.closest('li'); // Get reference to parent li item
  27.  
  28. // Fetch repository details to get homepage URL
  29. fetch(`https://api.github.com/repos/${owner}/${repoName}`)
  30. .then(response => response.json())
  31. .then(data => {
  32. const homepageUrl = data.homepage;
  33.  
  34. // Add "Homepage" button
  35. if (homepageUrl) {
  36. const repoDetails = repo.querySelector(".d-flex");
  37. const a = document.createElement('a');
  38. a.innerText = 'Homepage';
  39. a.href = homepageUrl;
  40. a.target = '_blank'; // Open link in a new tab
  41. a.style.marginLeft = '1rem'; // Add some margin to the left
  42. repoDetails.appendChild(a);
  43. }
  44. })
  45. .catch(error => console.error(error));
  46. }
  47. }
  48. }
  49. })();

QingJ © 2025

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