Superbuy show/hide order numbers

Button to show and hide order and item numbers on Superbuy

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Superbuy show/hide order numbers
// @namespace    https://tharglet.me.uk/
// @version      2.0
// @description  Button to show and hide order and item numbers on Superbuy
// @author       tharglet
// @match        https://www.superbuy.com/order
// @match        https://www.superbuy.com/order?*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=superbuy.com
// @grant        GM_addStyle
// @license      CC BY-NC-ND 4.0
// ==/UserScript==
GM_addStyle(`
.hideshow-hide {
  display: none;
}

#hideshow_toggle_button {
  margin-left: 10px;
  margin-top: 10px;
  padding: 5px 10px;
  background-color: white;
  border: 1px gray solid;
}`);

(function() {
    'use strict';

    // Initialise spans
    const tableHeaders = document.querySelectorAll('.user_orderlist thead > tr > td');
    console.log(tableHeaders);
    for (let tableHeader of tableHeaders) {
        for (let element of tableHeader.childNodes) {
            if (element.nodeType == Node.TEXT_NODE) {
                if(element.textContent.indexOf('Order No') > -1) {
                    const replacementNode = document.createElement('span');
                    replacementNode.classList.add('hideshow-order-no');
                    replacementNode.innerHTML = element.textContent;
                    element.parentNode.insertBefore(replacementNode, element);
                    element.parentNode.removeChild(element);
                }
            }
        }
    }

    // Initialise button
    const toggleButtonContainer = document.createElement('template');
    toggleButtonContainer.innerHTML = '<button id="hideshow_toggle_button">Hide Order IDs</button>';
    const statusList = document.getElementsByClassName('status-list')[0];
    statusList.after(toggleButtonContainer.content.firstChild);
    document.getElementById('hideshow_toggle_button').addEventListener('click', (event) => {
        toggleOrderIds();
    });

    const toggleOrderIds = () => {
        const showHideButton = document.getElementById('hideshow_toggle_button');
        const hide = showHideButton.textContent.startsWith('Hide');
        toggleElements(document.getElementsByClassName('hideshow-order-no'), hide);
        toggleElements(document.getElementsByClassName('tno'), hide);
        toggleElements(document.querySelectorAll('.user_orderlist_primg > span'), hide);
        if(hide) {
            showHideButton.textContent = 'Show Order IDs';
        } else {
            showHideButton.textContent = 'Hide Order IDs';
        }
    }

    const toggleElements = (elements, isHide) => {
        for(let element of elements) {
            if(isHide) {
                element.classList.add('hideshow-hide');
            } else {
                element.classList.remove('hideshow-hide');
            }
        }
    }

    })();