GreasyFork Total Scripts

Shows a user's total scripts count on GreasyFork.

Tính đến 28-04-2022. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

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

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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.

(I already have a user style manager, let me install it!)

// ==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)
}