WME Quick Zoom Button

Fügt einen Button für temporären Zoom hinzu damit man im Chat für alle sichtbar ist.

当前为 2025-05-15 提交的版本,查看 最新版本

// ==UserScript==
// @name         WME Quick Zoom Button
// @version      2025.05.15
// @description  Fügt einen Button für temporären Zoom hinzu damit man im Chat für alle sichtbar ist.
// @author       Hiwi234
// @namespace    https://gf.qytechs.cn/de/users/863740-horst-wittlich
// @match        https://www.waze.com/editor*
// @match        https://www.waze.com/*/editor*
// @match        https://beta.waze.com/editor*
// @match        https://beta.waze.com/*/editor*
// @grant        none
// @license      MIT          
// ==/UserScript==

(function() {
    'use strict';

    // Speichern der Benutzereinstellung im localStorage
    const STORAGE_KEY = 'wme-quick-zoom-auto';
    
    function getAutoZoomSetting() {
        return localStorage.getItem(STORAGE_KEY) === 'true';
    }

    function setAutoZoomSetting(value) {
        localStorage.setItem(STORAGE_KEY, value);
    }

    async function performQuickZoom() {
        const originalZoom = W.map.olMap.getZoom();
        W.map.olMap.zoomTo(4);
        
        return new Promise(resolve => {
            setTimeout(() => {
                W.map.olMap.zoomTo(originalZoom);
                resolve();
            }, 2000);
        });
    }

    async function initializeQuickZoom() {
        // Sidebar-Komponenten
        const { tabLabel, tabPane } = W.userscripts.registerSidebarTab("quick-zoom-script");

        // Tab-Label setzen
        tabLabel.innerText = 'QZ';
        tabLabel.title = 'Quick Zoom';

        // Container für vertikale Anordnung
        const container = document.createElement('div');
        container.style.display = 'flex';
        container.style.flexDirection = 'column';
        container.style.gap = '10px';
        container.style.padding = '10px';

        // Sidebar-Button erstellen
        const sidebarButton = document.createElement('button');
        sidebarButton.className = 'waze-btn waze-btn-small';
        sidebarButton.innerText = 'Quick Zoom';
        sidebarButton.title = 'Temporär auf Zoomstufe 4 zoomen';

        // Floating-Button erstellen
        const floatingButton = document.createElement('button');
        floatingButton.innerText = 'QZ';
        floatingButton.title = 'Quick Zoom';
        floatingButton.style.cssText = `
            position: fixed;
            bottom: 20px;
            left: 20px;
            z-index: 1000;
            background-color: white;
            border: 1px solid #ccc;
            padding: 8px 15px;
            border-radius: 20px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.2);
            cursor: pointer;
            font-weight: bold;
            transition: all 0.3s ease;
        `;

        // Hover-Effekt für den Floating-Button
        floatingButton.addEventListener('mouseenter', () => {
            floatingButton.style.backgroundColor = '#f0f0f0';
            floatingButton.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
        });

        floatingButton.addEventListener('mouseleave', () => {
            floatingButton.style.backgroundColor = 'white';
            floatingButton.style.boxShadow = '0 2px 4px rgba(0,0,0,0.2)';
        });

        let isZooming = false;
        const zoomHandler = async () => {
            if (!isZooming) {
                isZooming = true;
                await performQuickZoom();
                isZooming = false;
            }
        };

        // Event-Listener für beide Buttons
        sidebarButton.addEventListener('click', zoomHandler);
        floatingButton.addEventListener('click', zoomHandler);

        // Checkbox Container
        const checkboxContainer = document.createElement('div');
        checkboxContainer.style.display = 'flex';
        checkboxContainer.style.alignItems = 'center';
        checkboxContainer.style.gap = '5px';

        // Checkbox erstellen
        const checkbox = document.createElement('input');
        checkbox.type = 'checkbox';
        checkbox.id = 'auto-quick-zoom';
        checkbox.checked = getAutoZoomSetting();

        // Label für Checkbox
        const label = document.createElement('label');
        label.htmlFor = 'auto-quick-zoom';
        label.textContent = 'Automatisch beim Laden';
        label.style.fontSize = '12px';

        checkbox.addEventListener('change', (e) => {
            setAutoZoomSetting(e.target.checked);
        });

        // Elemente zusammenfügen
        checkboxContainer.appendChild(checkbox);
        checkboxContainer.appendChild(label);
        container.appendChild(sidebarButton);
        container.appendChild(checkboxContainer);
        tabPane.appendChild(container);
        document.body.appendChild(floatingButton);

        // Warten bis das Element im DOM verfügbar ist
        await W.userscripts.waitForElementConnected(tabPane);

        // Auto-Zoom ausführen wenn aktiviert
        if (getAutoZoomSetting()) {
            await performQuickZoom();
        }
    }

    // Warten auf WME Initialisierung
    if (W?.userscripts?.state.isReady) {
        initializeQuickZoom();
    } else {
        document.addEventListener("wme-ready", initializeQuickZoom, {
            once: true,
        });
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址