GitHub Creation Date

Displays the creation date of a GitHub repository when clicked.

< 脚本 GitHub Creation Date 的反馈

评价:好评 - 脚本运行良好

§
发布于:2025-07-21

Do you have a Github repository for contributions? I prefer this version that displays the creation date automatically without needing a click:

(function () {
  "use strict";

  const fetchRepoInfo = async (owner, repo) => {
    const apiUrl = `https://api.github.com/repos/${owner}/${repo}`;
    const response = await fetch(apiUrl, {
      headers: { Accept: "application/vnd.github.v3+json" },
    });

    if (!response.ok) {
      throw new Error(`Failed to fetch repository info (Status: ${response.status})`);
    }

    return response.json();
  };

  const insertCreationDate = async () => {
    const [, owner, repo] = window.location.pathname.split("/");

    // Exclude paths that are not main repo pages
    if (!owner || !repo || repo.includes('.')) return;

    try {
      const repoInfo = await fetchRepoInfo(owner, repo);
      const createdAt = new Date(repoInfo.created_at).toLocaleString();

      const repoTitleComponent = document.querySelector('div[id="repo-title-component"]');
      if (repoTitleComponent) {
        const dateElement = document.createElement("span");
        dateElement.textContent = ` • Created: ${createdAt}`;
        dateElement.style.fontSize = "12px";
        dateElement.style.marginLeft = "8px";
        dateElement.style.color = "#57606a";
        repoTitleComponent.appendChild(dateElement);
      }
    } catch (error) {
      console.error("Error fetching creation date:", error);
    }
  };

  insertCreationDate();
})();
maanimis作者
§
发布于:2025-07-29

Do you have a Github repository for contributions? I prefer this version that displays the creation date automatically without needing a click:

(function () {
  "use strict";

  const fetchRepoInfo = async (owner, repo) => {
    const apiUrl = `https://api.github.com/repos/${owner}/${repo}`;
    const response = await fetch(apiUrl, {
      headers: { Accept: "application/vnd.github.v3+json" },
    });

    if (!response.ok) {
      throw new Error(`Failed to fetch repository info (Status: ${response.status})`);
    }

    return response.json();
  };

  const insertCreationDate = async () => {
    const [, owner, repo] = window.location.pathname.split("/");

    // Exclude paths that are not main repo pages
    if (!owner || !repo || repo.includes('.')) return;

    try {
      const repoInfo = await fetchRepoInfo(owner, repo);
      const createdAt = new Date(repoInfo.created_at).toLocaleString();

      const repoTitleComponent = document.querySelector('div[id="repo-title-component"]');
      if (repoTitleComponent) {
        const dateElement = document.createElement("span");
        dateElement.textContent = ` • Created: ${createdAt}`;
        dateElement.style.fontSize = "12px";
        dateElement.style.marginLeft = "8px";
        dateElement.style.color = "#57606a";
        repoTitleComponent.appendChild(dateElement);
      }
    } catch (error) {
      console.error("Error fetching creation date:", error);
    }
  };

  insertCreationDate();
})();

This is great

https://github.com/maanimis

发布留言

登录(不可用)以发布留言。

QingJ © 2025

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