SH Add Chapter Numbers

Add chapter numbers (release order) to all TOC items on a Scribble Hub series page.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         SH Add Chapter Numbers
// @namespace    ultrabenosaurus.ScribbleHub
// @version      0.2
// @description  Add chapter numbers (release order) to all TOC items on a Scribble Hub series page.
// @author       Ultrabenosaurus
// @license      GNU AGPLv3
// @source       https://greasyfork.org/en/users/437117-ultrabenosaurus?sort=name
// @match        https://www.scribblehub.com/series/*
// @icon         https://www.google.com/s2/favicons?domain=scribblehub.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    UBPaginationClick();
    // run again after a delay for compatibility with my SH Auto Show Bookmark script
    setTimeout(UBPaginationClick, 1500);

})();

function UBPaginationClick(){
    if( 0 != document.querySelectorAll('div.wi_fic_table.toc:not(.ub-numbered)').length) {
        document.querySelectorAll('div.wi_fic_table.toc:not(.ub-numbered) li.toc_w[order]').forEach(function(element) {
            var linkText = element.querySelectorAll('a')[0].textContent;
            element.querySelectorAll('a')[0].textContent = "(" + element.attributes.order.value + ") " + linkText;
            linkText = null;
        });
        document.querySelectorAll('div.wi_fic_table.toc')[0].classList.add("ub-numbered");

        if( 0 != document.querySelectorAll('ul#pagination-mesh-toc li').length ){
            document.querySelectorAll('ul#pagination-mesh-toc li a').forEach(function(pagBtn) {
                if(pagBtn){
                    pagBtn.addEventListener("click", function(){
                        console.log("click");
                        setTimeout(UBPaginationClick, 800);
                    }, false);
                }
                pagBtn = null;
            });
        }
    }
}