amount of products on the product page

Shows the amount of products at the top of the products table, enlarges the order history field, adds item tax to table

As of 2021-02-22. See the latest version.

// ==UserScript==
// @name         amount of products on the product page
// @namespace    http://tampermonkey.net/
// @version      2
// @description  Shows the amount of products at the top of the products table, enlarges the order history field, adds item tax to table
// @author       Ruben Van Hee @ Lightspeedhq
// @run-at       document-end
// @match        https://*.webshopapp.com/admin/orders/*
// @match        https://*.shoplightspeed.com/admin/orders/*
// ==/UserScript==

!function(){
function itemCount(){
    var count = document.getElementsByClassName("order-product-item");
    count = count.length;
    console.log("there are " + count + " items in the order");
    document.querySelectorAll('h2.P1')[2].insertAdjacentHTML('beforeend', " (" + count + ")");
    document.getElementsByClassName('order-events')[0].style.height = "100%";
    let t;
    let url = location.origin + location.pathname+'.json';
    let e = new XMLHttpRequest();
    	e.open("GET", url, true),
    	e.onload = function(){
    	if ( e.status >= 200 && e.status < 400 ){
                t = JSON.parse( e.responseText );
                document.querySelectorAll('th[class="-auto tr"]')[0].parentNode.insertAdjacentHTML('beforeEnd','<th><span>VAT</span></th>');
                t.order.order_products.forEach((item,i) => {
                    document.querySelectorAll(`tr[data-id='${item.id}']`)[0].insertAdjacentHTML('beforeEnd','<td class="NoWrap">'+item.variant.tax.tax_format+'</td>');
                })
            }
        },
        e.send();
    setTimeout(function(){console.log(t);},1000);
    }
document.addEventListener("DOMContentLoaded", itemCount);  //calls function when loaded
}();