Origin

Display the creation time of the github repository.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Origin
// @version      0.1
// @description  Display the creation time of the github repository.
// @author       Sh-Fang
// @match        https://github.com/*
// @grant        none
// @source       https://github.com/Sh-Fang/Origin
// @license MIT
// @namespace https://greatest.deepsurf.us/users/1232796
// ==/UserScript==

(function() {
    'use strict';

    // Parsing username and repository name
    var pathArray = window.location.pathname.split('/');
    var username = pathArray[1];
    var repository = pathArray[2];

    // Check that the username and repository name both exist and are not empty
    if (username && repository) {

        // Construct a unique identifier for storing data in localStorage
        var storageKey = 'githubInfo_' + username + '_' + repository;

        // Trying to get saved information from localStorage
        var storedInfo = localStorage.getItem(storageKey);

        // Use XPath to find the specified element
        var xpathResult = document.evaluate(
            '/html/body/div[1]/div[6]/div/main/div/div[1]/div[1]/div[1]/strong/a',
            document,
            null,
            XPathResult.FIRST_ORDERED_NODE_TYPE,
            null
        );

        // Get the found element
        var repoLink = xpathResult.singleNodeValue;

        // Check if the element is found
        if (repoLink) {

            // Get the text content of the element
            var repoName = repoLink.textContent;

            // If the information has been stored, the stored information is displayed directly
            if (storedInfo) {
                repoLink.textContent = repoName + ' (Created at: ' + storedInfo + ')';
            } else {
                // GitHub API request URLs
                var apiUrl = 'https://api.github.com/repos/' + username + '/' + repository;

                // GitHub API request
                fetch(apiUrl)
                    .then(response => response.json())
                    .then(data => {

                    // Get "created_at" item
                    var createdAt = data.created_at;

                    // Convert timestamps to human-readable date strings (containing only the year, month, and day)
                    var createdDate = new Date(createdAt).toLocaleDateString();

                    // Add a timestamp after repository name
                    repoLink.textContent = repoName + ' (Created at: ' + createdDate + ')';

                    // Save timestamp to localStorage
                    localStorage.setItem(storageKey, createdDate);
                })
                    .catch(error => console.error('Error fetching GitHub API:', error));
            }

        }


    }

})();