NpmPackageRepo

See if npm package repo is forked from others

Από την 27/09/2022. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         NpmPackageRepo
// @namespace    mailto:[email protected]
// @version      0.1.0
// @description  See if npm package repo is forked from others
// @author       fish-404
// @match        https://www.npmjs.com/package/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=npmjs.com
// @homepage     https://github.com/fish-404/UserScriptsStyles/tree/main/npm/Scripts
// @license      MIT
// @grant        GM.xmlHttpRequest
// ==/UserScript==

(function() {
    'use strict';
    let link = document.querySelector('#repository-link').innerText.substring(11);
    let repo = document.querySelector('#repository');

    const notFoundHtml = '<img src="https://badgen.net/badge/status/404/red" alt="Repository Not Found Badge"/>'

    if (link) {
        GM.xmlHttpRequest( {
            method: "GET",
            url: `https://api.github.com/repos/${link}`,
            headers: {
                "accept": "application/vnd.github+json"
            },
            onload: function(response) {
                if (response.status = '200') {
                    if (response.statusText === "Not Found") {
                        insertBadge(repo, notFoundHtml);
                    }
                    else {
                        let cur = JSON.parse(response.response);
                        let curForkHtml = `<img src="https://badgen.net/badge/Forks/${cur.forks}/blue" alt="Repository Total Fork Badge"/>`;
                        if (cur.fork === true) {
                            insertBadge(repo, curForkHtml);
                            insertBadge(repo,
                                `<a href="${cur.parent.html_url}">
                                    <img src="https://badgen.net/badge/Parent Forks/${cur.parent.forks}/orange" alt="Respository Parent Fork Badge" />
                                </a>`);
                        }
                        else {
                            insertBadge(repo, curForkHtml);
                        }
                    }
                }
            }
        });
    }
    else {
        console.info("Repository link not found");
    }
})();

function insertBadge(element, htmlText) {
   element.insertAdjacentHTML('afterend', htmlText);
}