SH Add Chapter Numbers

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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