Move Tag Posts Count

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

Stan na 18-06-2023. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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

(function() {
    'use strict';

// Function to move the tag's posts count after the tag name for each element
function moveTagPostsCountForAll() {
    var tagContainers = document.querySelectorAll('div[id^="tag_container"]'); // Find all tag container elements

    // Iterate through each tag container element
    tagContainers.forEach(function(tagContainer) {
        var tagLink = tagContainer.querySelector('a[id^="tag"]'); // Find the tag link element inside the container
        var postsCount = getCount(tagContainer.querySelector('span[role="tooltip"] span:nth-of-type(1)').innerHTML); // Find the posts count element inside the tooltip

        // Check if both the tag link and posts count elements exist
        if (tagLink && postsCount) {
            // Move the posts count element after the tag link
            tagLink.parentNode.insertBefore(postsCount, tagLink.nextSibling);
        }
    });
}

function getCount(details) {
  var re = new RegExp("Posts: (.+?)(<br>)", "g");
  var transformedNumber = transformNumber(re.exec(details)[1]);

  // Create a span element to wrap the transformed number and apply the gray color
  var span = document.createElement('span');
  span.style.color = 'gray';
  span.appendChild(document.createTextNode(' ' + transformedNumber));

  return span;
}

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
    });
}

// Call the function to move the tag's posts count after the tag name for all elements
moveTagPostsCountForAll();


})();