FMC Expand Toggle

Fixes expand all button to allow for collapse all

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

Advertisement:

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

Advertisement:

// ==UserScript==
// @name         FMC Expand Toggle
// @namespace    http://tampermonkey.net/
// @version      1.11
// @description  Fixes expand all button to allow for collapse all
// @author       geesmavi
// @include      https://trans-logistics.amazon.com/fmc/*
// @include      https://trans-logistics-eu.amazon.com/fmc/*
// @icon         https://www.google.com/s2/favicons?domain=amazon.com
// @grant        GM_addStyle
// @run-at document-start
// ==/UserScript==

(function() {
    'use strict';
    GM_addStyle(`
        .comment-visibility-toggle {
        user-select: none;
        }
    `);

    // restarts detailsToggleObserver on url change
    let lastUrl = location.href;
    new MutationObserver(() => {
        const url = location.href;
        if (url !== lastUrl) {
            lastUrl = url;
            detailsToggleObserver.observe(document, {
                childList: true,
                subtree: true
            });
        }
    }).observe(document, {subtree: true, childList: true});

    // watches page for dashboard-details-toggle which loads after page load
    // if element exists starts the detailsToggler
    const detailsToggleObserver = new MutationObserver((mutations, obs) => {
        const detailsToggle = document.querySelector('th.dashboard-details-toggle');
        if (detailsToggle) {
            const fmcShown = document.querySelector('.fmc-shown');
            if (fmcShown) {
                detailsToggle.classList.remove('child-row-expand-trigger');
                detailsToggle.classList.add('child-row-collapse-trigger');
            }
            detailsToggler(detailsToggle);
            obs.disconnect();
            return;
        }
    });

    detailsToggleObserver.observe(document, {
        childList: true,
        subtree: true
    });

    // swaps the expand/collapse classes of given element
    function detailsToggler(element) {
            const removeClass = function(removedClass) {
                element.classList.remove(removedClass);
                return;
            };
            const addClass = function(addedClass) {
                element.classList.add(addedClass);
                return;
            };

            element.addEventListener("click", function() {
                switch(true){
                    case element.classList.contains('child-row-expand-trigger'):
                        removeClass('child-row-expand-trigger');
                        addClass('child-row-collapse-trigger');
                        break;
                    case element.classList.contains('child-row-collapse-trigger'):
                        removeClass('child-row-collapse-trigger');
                        addClass('child-row-expand-trigger');
                        break;
                    default:
                        break;
                }

                return;
            });
        };
})();