GitHub Repo Size

Calculate repo size and inject into GitHub page

2021-02-08 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name            GitHub Repo Size
// @namespace       https://gist.github.com/miraclx/aad03f43fe8ac85682b0243f4f242f0d
// @description     Calculate repo size and inject into GitHub page
// @icon            https://github.githubassets.com/favicons/favicon.png
// @version         0.1
// @author          miraclx
// @supportURL      https://gist.github.com/miraclx/aad03f43fe8ac85682b0243f4f242f0d
// @grant           GM_xmlhttpRequest
// @match           https://github.com/*
// @require         https://code.jquery.com/jquery-3.5.1.min.js
// @connect         tokei.rs
// ==/UserScript==
/* global $ */

(function() {
    'use strict';

    const CLOC_ID = "tokei-cloc";
    const DATA_URL = `https://tokei.rs/b1/github/${window.location.pathname.split('/').slice(1, 3).join('/')}`;
    const REPO_SUMMARY = $("#repo-content-pjax-container div.gutter-condensed.gutter-lg div.file-navigation div.flex-self-center");
    const CLOC_ELM = document.getElementById(CLOC_ID);

    if (REPO_SUMMARY.length !== 0 && !CLOC_ELM) {
        function handleLoad(response, code) {
            if (response.response && typeof (code = response.response.code) === "number") {
                const bloq = $(`
                    <a href="${DATA_URL}?category=code" id="${CLOC_ID}" class="ml-3 link-gray-dark no-underline">
                         <svg text="gray" class="octicon octicon-file-code" width="16" height="16" viewBox="0 0 16 16" version="1.1" aria-hidden="true">
                             <path fill-rule="evenodd" d="M8.5 1H1c-.55 0-1 .45-1 1v12c0 .55.45 1 1 1h10c.55 0 1-.45 1-1V4.5L8.5 1zM11 14H1V2h7l3 3v9zM5 6.98L3.5 8.5 5 10l-.5 1L2 8.5 4.5 6l.5.98zM7.5 6L10 8.5 7.5 11l-.5-.98L8.5 8.5 7 7l.5-1z">
                             </path>
                         </svg>
                         <strong>
                           ${code.toString().replace(/(\d)(?=(\d{3})+$)/g, "$1,")}
                         </strong>
                         <span class="text-gray-light">lines of code</span>
                    </a>
                `);
                REPO_SUMMARY.append(bloq);
            }
        }

        GM_xmlhttpRequest({
            method: "GET",
            url: DATA_URL,
            responseType: "json",
            headers: { "Accept": "application/json"},
            onload: handleLoad,
            onerror: console.error,
            onabort: console.error,
            ontimeout: console.error,
        });
    }
})();