Greasy Fork

Greasy Fork is available in English.

GreasyFork Total Scripts

Shows a user's total scripts count on GreasyFork.

当前为 2022-08-10 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name GreasyFork Total Scripts
// @namespace -
// @version 3.0.1
// @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
// @run-at document-end
// @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)
}