WME GPS Traces Under Roads

Moves the GPS traces layer underneath the roads layer

// ==UserScript==
// @name         WME GPS Traces Under Roads
// @namespace    http://tampermonkey.net/
// @version      1.0.3
// @description  Moves the GPS traces layer underneath the roads layer
// @author       Honkson
// @license      MIT
// @match        https://*.waze.com/editor*
// @match        https://*.waze.com/*/editor*
// @exclude      https://*.waze.com/user/editor*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    function moveGPSLayer() {
        const gpsLayers = document.querySelectorAll('.olLayerDiv.olLayerGrid');
        let gpsLayer = null;
        let roadsLayer = null;

        gpsLayers.forEach(layer => {
            if (!gpsLayer && layer.innerHTML.includes('clientLayer=gps_points')) {
                gpsLayer = layer;
            }
            if (!roadsLayer && layer.innerHTML.includes('roads')) {
                roadsLayer = layer;
            }
        });

        if (gpsLayer && roadsLayer) {
            gpsLayer.style.zIndex = parseInt(getComputedStyle(roadsLayer).zIndex, 10) - 1;
        }
    }

    const observer = new MutationObserver(mutations => {
        for (let mutation of mutations) {
            for (let node of mutation.addedNodes) {
                if (
                    node.nodeType === 1 &&
                    node.tagName === 'IMG' &&
                    node.src.includes('clientLayer=gps_points')
                ) {
                    setTimeout(moveGPSLayer, 500);
                    return;
                }
            }
        }
    });

    const waitForMap = setInterval(() => {
        const container = document.querySelector('.olMapViewport');
        if (container) {
            clearInterval(waitForMap);
            observer.observe(container, { childList: true, subtree: true });
            moveGPSLayer();
        }
    }, 500);
})();