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 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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://greasyfork.org/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,
        });
    }
})();