GitHub Creation Date

Displays the creation date of a GitHub repository when clicked.

目前為 2025-02-23 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name GitHub Creation Date
  3. // @namespace Violentmonkey Scripts
  4. // @match https://github.com/*/*
  5. // @grant none
  6. // @version 1.0
  7. // @author -
  8. // @description Displays the creation date of a GitHub repository when clicked.
  9. // @run-at document-end
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15.  
  16. const createButton = (text, styles = {}) => {
  17. const button = document.createElement("button");
  18. button.textContent = text;
  19. Object.assign(button.style, {
  20. marginLeft: "10px",
  21. padding: "3px 6px",
  22. cursor: "pointer",
  23. backgroundColor: "#0366d6",
  24. color: "#fff",
  25. border: "none",
  26. borderRadius: "3px",
  27. fontSize: "12px",
  28. lineHeight: "1.5",
  29. ...styles,
  30. });
  31. return button;
  32. };
  33.  
  34. const fetchRepoInfo = async (owner, repo) => {
  35. const apiUrl = `https://api.github.com/repos/${owner}/${repo}`;
  36. const response = await fetch(apiUrl, {
  37. headers: { Accept: "application/vnd.github.v3+json" },
  38. });
  39.  
  40. if (!response.ok) {
  41. throw new Error(
  42. `Failed to fetch repository info (Status: ${response.status})`
  43. );
  44. }
  45. return response.json();
  46. };
  47.  
  48. const init = () => {
  49. const repoTitleComponent = document.querySelector(
  50. 'div[id="repo-title-component"]'
  51. );
  52. if (!repoTitleComponent) {
  53. console.error("Could not find the repository title component.");
  54. return;
  55. }
  56.  
  57. const button = createButton("Creation Date");
  58. repoTitleComponent.appendChild(button);
  59.  
  60. button.addEventListener("click", async () => {
  61. const [, owner, repo] = window.location.pathname.split("/");
  62.  
  63. if (!owner || !repo) {
  64. alert("Invalid repository URL.");
  65. return;
  66. }
  67.  
  68. try {
  69. const repoInfo = await fetchRepoInfo(owner, repo);
  70. alert(
  71. `'${repo}' was created on: ${new Date(
  72. repoInfo.created_at
  73. ).toLocaleString()}`
  74. );
  75. } catch (error) {
  76. alert(`Error: ${error.message}`);
  77. }
  78. });
  79. };
  80.  
  81. init();
  82. })();

QingJ © 2025

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