Move Tag Posts Count

Moves the tag's posts count after the tag name on a webpage with specific elements.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Move Tag Posts Count
// @version      1.6
// @description  Moves the tag's posts count after the tag name on a webpage with specific elements.
// @match      https://chan.sankakucomplex.com/post*
// @match      https://chan.sankakucomplex.com/*/post*
// @match      https://chan.sankakucomplex.com/*/post/*
// @match      https://chan.sankakucomplex.com/?*tags*
// @grant        none
// @license      MIT
// @namespace https://greasyfork.org/users/1104432

// ==/UserScript==

(function() {
    'use strict';

    document.querySelectorAll('div[id^="tag_container"]').forEach(div => {
        const span = document.createElement('span')

        span.style.color = 'grey'
        span.innerHTML = ' ' + transformNumber(div.querySelector('.tooltip').innerHTML.match(/Posts: <span data-count="(\d*)">/i)[1])
        div.insertBefore(span, div.querySelector('a').nextSibling)
    });

    function transformNumber(numberString) {

        const numberParts = numberString.trim().split(/(\d+\.?\d*)([KMB])?/);
        let number = parseFloat(numberParts[1]);
        const suffix = numberParts[2];

        if (suffix === 'K') {
            number *= 1000;
        } else if (suffix === 'M') {
            number *= 1000000;
        }

        return number.toLocaleString("ro-RO", {
            useGrouping: true
        });
    }
})();