WME Coordinate Extractor

Extrae coordenadas con clic derecho en el editor de Waze.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         WME Coordinate Extractor
// @name:en      WME Coordinate Extractor
// @namespace    http://tampermonkey.net/
// @version      1.1.1
// @description  Extrae coordenadas con clic derecho en el editor de Waze.
// @description:en Extracts coordinates with a right-click in the Waze editor.
// @author       edarague
// @match        https://www.waze.com/*editor*
// @run-at       document-end
// @grant        none
// @license MIT
// ==/UserScript==
setTimeout(() => {
    const s = document.createElement('style');
    s.textContent = `
        .waze-coord-final {
            position: fixed !important;
            background: #0a0a0a !important;
            color: #00ff00 !important;
            padding: 14px 18px !important;
            border-radius: 6px !important;
            font-family: 'Courier New', monospace !important;
            font-size: 13px !important;
            font-weight: bold !important;
            z-index: 999999 !important;
            border: 2px solid #00ff00 !important;
            min-width: 250px !important;
            box-shadow: 0 4px 20px rgba(0,255,0,0.2) !important;
        }
        .waze-coord-coords {
            margin-bottom: 10px !important;
            font-size: 14px !important;
        }
        .waze-coord-actions {
            display: flex !important;
            gap: 8px !important;
        }
        .waze-coord-btn {
            flex: 1 !important;
            padding: 6px 8px !important;
            border-radius: 4px !important;
            border: 1px solid #00ff00 !important;
            background: transparent !important;
            color: #00ff00 !important;
            font-family: 'Courier New', monospace !important;
            font-size: 11px !important;
            font-weight: bold !important;
            cursor: pointer !important;
            text-align: center !important;
            transition: background 0.15s !important;
            text-decoration: none !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
            gap: 4px !important;
        }
        .waze-coord-btn:hover {
            background: #00ff00 !important;
            color: #0a0a0a !important;
        }
    `;
    document.head.appendChild(s);

    window.wazeCoordExtractor = {
        getCoords: () => {
            try {
                const t = document.body.innerText;
                const m = t.match(/(\d+\.\d{4,})\s+(-?\d+\.\d{4,})/);
                return m ? { lat: parseFloat(m[1]).toFixed(6), lng: parseFloat(m[2]).toFixed(6) } : null;
            } catch (e) { return null; }
        },
        showPopup: (c, x, y) => {
            const old = document.querySelector('.waze-coord-final');
            if (old) old.remove();

            const mapsUrl = `https://maps.google.com/?q=${c.lat},${c.lng}`;

            const p = document.createElement('div');
            p.className = 'waze-coord-final';
            p.innerHTML = `
                <div class="waze-coord-coords">📍 ${c.lat} ${c.lng}</div>
                <div class="waze-coord-actions">
                    <button class="waze-coord-btn" id="wce-copy">📋 Copiar</button>
                    <a class="waze-coord-btn" href="${mapsUrl}" target="_blank" id="wce-maps">🗺️ Maps</a>
                </div>
            `;

            p.style.left = Math.min(x + 15, window.innerWidth - 240) + 'px';
            p.style.top = Math.min(y + 15, window.innerHeight - 120) + 'px';

            document.body.appendChild(p);

            document.getElementById('wce-copy').addEventListener('click', (e) => {
                e.stopPropagation();
                navigator.clipboard.writeText(`${c.lat}, ${c.lng}`);
                const btn = document.getElementById('wce-copy');
                if (btn) btn.textContent = '✅ Copiado';
                setTimeout(() => p.remove(), 1500);
            });

            document.getElementById('wce-maps').addEventListener('click', (e) => {
                e.stopPropagation();
                setTimeout(() => p.remove(), 500);
            });

            setTimeout(() => { if (p.parentNode) p.remove(); }, 6000);
        }
    };

    document.addEventListener('contextmenu', (e) => {
        const c = window.wazeCoordExtractor.getCoords();
        if (c) { e.preventDefault(); window.wazeCoordExtractor.showPopup(c, e.clientX, e.clientY); }
    }, true);
}, 500);