Greasy Fork Total Installs(modified)

A userscript that shows the total installs for any page on Greasy Fork

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name Greasy Fork Total Installs(modified)
// @version 0.1.2
// @description A userscript that shows the total installs for any page on Greasy Fork
// @license MIT
// @namespace Rob Garrison
// @author Rob Garrison
// @modifiedBy NotYou
// @namespace https://github.com/Mottie
// @include https://greasyfork.org/*
// @run-at document-idle
// @grant none
// @icon https://greasyfork.org/packs/media/images/blacklogo96-b2384000fca45aa17e45eb417cbcbb59.png
// ==/UserScript==

/* What's New?
 *  Counts of total daily installs
 *  Replaced icon URL to new
 */

(() => {
	"use strict";

	const wrapper = $("#browse-script-list, #user-script-list");
	if (wrapper) {
        // CONSTANTAS //
		const els = [...wrapper.querySelectorAll("dd.script-list-total-installs")];
        const els2 = [...wrapper.querySelectorAll("dd.script-list-daily-installs")];
		const nonDigits = /[^\d]/g;
		const getNum = txt => parseFloat(txt.replace(nonDigits, ""));
		const total = els.reduce((acc, el) => acc + getNum(el.textContent), 0);
        const totald = els2.reduce((acc, el) => acc + getNum(el.textContent), 0); // NEW LET
        // IFs //
		if (total) {
			const span = document.createElement("span");
			let target = $("#script-list-sort .list-option:nth-child(2)");
			span.textContent = ` (${(total).toLocaleString()})`;
			if ($("a", target)) {
				target = $("a", target);
			}
			target.appendChild(span);
		}
        // MODIFICATION START //
        if (totald) {
			const span = document.createElement("span");
			let target = $("#script-list-sort .list-option:nth-child(1)");
			span.textContent = ` (${(totald).toLocaleString()})`;
			if ($("a", target)) {
				target = $("a", target);
			}
			target.appendChild(span);
		}
	}
    // MODIFICATION END //

    // FUNCTIONS //
	function $(str, el) {
		return (el || document).querySelector(str);
	}

})();