GreasyFork Total Scripts

Shows a user's total scripts count on GreasyFork.

Versione datata 28/04/2022. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name GreasyFork Total Scripts
// @namespace -
// @version 3.0.0
// @description Shows a user's total scripts count on GreasyFork.
// @author NotYou
// @include *greasyfork.org/*/users/*
// @include *greasyfork.org/*/scripts*
// @include *sleazyfork.org/*/users/*
// @include *sleazyfork.org/*/scripts*
// @license GPL-3.0-or-later
// @grant none
// ==/UserScript==

const
    select = s => document.querySelector(s),
    selectAll = s => document.querySelectorAll(s),
    addStyle = css => document.documentElement.children[0].insertAdjacentHTML('beforeend', `<style>${css.trim()}</style>`),
    totalCounter = (s, color) => {
        let sel = select(s)
        sel.style.outline = `${color} 2px solid`
        sel.children[0].style.background = `${color}`
    },
    ifElCheck = (var1, var2) => {
        if(var1 < 1) return
        if (var1 == 1) totalCounter(var2, 'rgb(125, 125, 125)')
        else if(var1 >= 100) totalCounter(var2, 'rgb(185, 16, 16)')
        else if(var1 >= 50) totalCounter(var2, 'rgb(185, 87, 16)')
        else if(var1 >= 25) totalCounter(var2, 'rgb(185, 159, 16)')
        else if(var1 >= 10) totalCounter(var2, 'rgb(21, 185, 16)')
        else if(var1 >= 5) totalCounter(var2, 'rgb(16, 185, 153)')
        else if(var1 > 1) totalCounter(var2, 'rgb(16, 42, 185)')
        else if(!var1||var1 < 0) totalCounter(var2, 'rgb(185, 16, 16)')
    },
    currentURL = new URL(location.href)

Element.prototype.appendHTML = function(h) {
    this.insertAdjacentHTML('beforeend', h)
}

Element.prototype.prependHTML = function(h) {
    this.insertAdjacentHTML('afterbegin', h)
}

const csstotal = selectAll('[data-css-available-as-js="true"]').length,
    libtotal = selectAll('#user-library-script-list > li').length,
    jstotal = selectAll('#user-script-list > [data-css-available-as-js="false"]').length,
    jstotalsearch = selectAll('#browse-script-list > li[data-script-language="js"]').length,
    csstotalsearch = selectAll('#browse-script-list > [data-css-available-as-js="true"]').length,
    sensitive = selectAll('li[data-sensitive="true"]').length,
    SIDEBARRED = select('.sidebarred-main-content > p')

if(currentURL.searchParams.has('q')) {
    addStyle(`
    #t-counters {
        display: inline-flex;
        font-weight: 800;
    }
    .total-count {
        font-size: 15px;
        border-radius: 3px;
        background: rgb(45, 45, 45);
        color: rgb(255, 255, 255);
        margin: 0 4px;
    }

    .total-count > span:first-child {
        width: 8px;
        height: 8px;
        display: inline-flex;
        margin-bottom: 1px;
        margin-left: 4px;
        border-radius: 50%;
    }

    .total-count > span:last-child {
        margin: 0 4px;
    }
    `)
    SIDEBARRED.appendHTML(`<div id="t-counters"></div>`)
    const COUNTERS = select('#t-counters'), TS = '#t-scripts', TC = '#t-css',
          createCounterDOM = (id, variable, name) => {
              if(!variable||variable < 1) return
              COUNTERS.appendHTML(`<span id="t-${id}" class="total-count"><span></span><span>${variable ? variable : 'Unexpected'} ${variable ? name : 'Error'}</span></span>`)
          }, createCounter = (id, var1, name, var2) => {
              createCounterDOM(id, var1, name)
              ifElCheck(var1, var2)
          }
    createCounter('scripts', jstotalsearch, 'Scripts', TS)
    createCounter('css', csstotalsearch, 'Styles', TC)
}

var scriptHeader = select('div.sidebarred-main-content h3:first-child')

if(scriptHeader) {
    addStyle(`
    #t-counters {
        display: inline-flex;
    }
    .total-count {
        font-size: 15px;
        border-radius: 3px;
        background: rgb(45, 45, 45);
        color: rgb(255, 255, 255);
        margin: 0 4px;
    }

    .total-count > span:first-child {
        width: 8px;
        height: 8px;
        display: inline-flex;
        margin-bottom: 1px;
        margin-left: 4px;
        border-radius: 50%;
    }

    .total-count > span:last-child {
        margin: 0 4px;
    }
    `)
    scriptHeader.appendHTML(`<div id="t-counters"></div>`)
    const COUNTERS = select('#t-counters'), TS = '#t-scripts', TC = '#t-css', TL = '#t-libs',
          createCounterDOM = (id, variable, name) => {
              if(!variable||variable < 1) return
              COUNTERS.appendHTML(`<span id="t-${id}" class="total-count"><span></span><span>${variable ? variable : 'Unexpected'} ${variable ? name : 'Error'}</span></span>`)
          }, createCounter = (id, var1, name, var2) => {
              createCounterDOM(id, var1, name)
              ifElCheck(var1, var2)
          }
    createCounter('scripts', jstotal, 'Scripts', TS)
    createCounter('css', csstotal, 'Styles', TC)
    createCounter('libs', libtotal, 'Libs', TL)
}