WME Layer Counter

See how many layers you have active in WME.

目前為 2023-10-01 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         WME Layer Counter
// @namespace    https://greasyfork.org/en/scripts/476456-wme-layer-counter
// @author       DevlinDelFuego
// @version      2023.9.30.2
// @description  See how many layers you have active in WME.
// @match        *://*.waze.com/*editor*
// @exclude      *://*.waze.com/user/editor*
// @grant        none
// @require      https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
// @license      GPLv3
// ==/UserScript==

(function main() {
    'use strict';

    const SCRIPT_NAME = GM_info.script.name;
    const MAX_LAYERS = 81; // Maximum allowed layers
    const TOOLTIP_TEXT = 'Active Layers / Max Layers';
    const updateMessage = "<b>Changelog</b><br><br> - Initial Release. <br> Hope this helps those that need to know how many layers they are using. <br><br>";

    let _$layerCountElem = null;

    function createLayerCountElement() {
        _$layerCountElem = document.createElement('div');
        _$layerCountElem.id = 'layer-count-monitor';
        _$layerCountElem.className = 'toolbar-button';
        _$layerCountElem.style.cssText = 'font-weight: bold; font-size: 16px; border-radius: 10px; margin-left: 4px; background-color: white;';
        _$layerCountElem.setAttribute('data-toggle', 'tooltip');
        _$layerCountElem.setAttribute('data-placement', 'auto top');
        _$layerCountElem.setAttribute('title', '');

        const innerDiv = document.createElement('div');
        innerDiv.className = 'item-container';
        innerDiv.style.cssText = 'padding-left: 10px; padding-right: 10px; cursor: default;';

        innerDiv.appendChild(_$layerCountElem);
    }

    function updateLayerCount() {
        if (!_$layerCountElem) {
            createLayerCountElement();
        }
        const activeLayers = W.controller.map.layers.length;
        const layerCountText = `${activeLayers}/${MAX_LAYERS}`;

        _$layerCountElem.setAttribute('data-original-title', TOOLTIP_TEXT);
        _$layerCountElem.textContent = layerCountText;

        // Enable Bootstrap tooltip
        $('[data-toggle="tooltip"]').tooltip();
    }

    function injectLayerCountElement() {
        if (_$layerCountElem && _$layerCountElem.parentElement) {
            _$layerCountElem.parentElement.removeChild(_$layerCountElem);
        }
        updateLayerCount();

        const existingToolbarButtonParent = document.querySelector('.secondary-toolbar-actions');

        if (existingToolbarButtonParent && !existingToolbarButtonParent.querySelector('#layer-count-monitor')) {
            existingToolbarButtonParent.appendChild(_$layerCountElem);
        }
    }

    function init() {
        W.model.events.register('mergeend', null, updateLayerCount);
    }

    if (WazeWrap.Ready) {
        init();
    } else {
        document.addEventListener('WazeWrap.Ready', init);
    }

    const observer = new MutationObserver((mutationsList, observer) => {
        for (const mutation of mutationsList) {
            if (mutation.type === 'childList' && mutation.target.classList.contains('secondary-toolbar')) {
                injectLayerCountElement();
                observer.disconnect();
            }
        }
    });

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

    setInterval(updateLayerCount, 1000);

    // Initialize the script
    function initialize() {
        if (W?.userscripts?.state.isReady) {
            showScriptUpdate();
        } else {
            document.addEventListener('wme-ready', function () {
                showScriptUpdate();
            }, { once: true });
        }
    }

    // Call the initialize function
    initialize();

    // Show script update notification
    function showScriptUpdate() {
        WazeWrap.Interface.ShowScriptUpdate(
            'WME Layer Counter',
            GM_info.script.version,
            updateMessage,
            'https://greasyfork.org/en/scripts/476456-wme-layer-counter',
            '#'
        );
    }

})();