WME Open DeFlock

Adds a direct link to this location on the DeFlock map.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         WME Open DeFlock
// @namespace    https://greatest.deepsurf.us/en/users/1365511-robosphinx
// @version      2026.05.18.001
// @description  Adds a direct link to this location on the DeFlock map.
// @author       robosphinx
// @match        *://*.waze.com/*editor*
// @exclude      *://*.waze.com/user/editor*
// @grant        none
// @license      GPLv3
// @grant        none
// @grant        GM_info
// ==/UserScript==

// Format: https://maps.deflock.org/?lat=[lat2.4]&lng=[lon2.4]&zoom=16.00
// Link updating idea ripped from gncnpk search for closure

(function() {
    'use strict';

    const SCRIPT_LONG_NAME = GM_info.script.name;
    const SCRIPT_SHORT_NAME = "WME-ODF";
    const SCRIPT_VERSION = GM_info.script.version;

    let successfulStartup = true;

    // Projection conversion ripped from traffic light checker by jushag
    let _humanProj = null;
    let _wmeProj = null;
    let link;

    function getOLProjections() {
        if (!_humanProj) _humanProj = new OpenLayers.Projection("EPSG:4326");
        if (!_wmeProj) _wmeProj = W.map.getProjectionObject();
        return { humanProj: _humanProj, wmeProj: _wmeProj };
    }
    // Finish Projection conversion ripped from traffic light checker by jushag

    function fancyLogMessage(tag, message) {
        if (tag == "ERROR") {
            console.error(SCRIPT_SHORT_NAME + ": " + tag + ": " + message);
        }
        else {
            console.log(SCRIPT_SHORT_NAME + ": " + tag + ": " + message);
        }
    }

    function addTheLink() {
        link = document.createElement("a");
        link.className = "wz-map-black-link";
        // link.style = "margin-left: auto;";
        link.target = "_blank";
        link.innerHTML = "DeFlock";
        $(".wz-map-ol-footer")[0].appendChild(link);
        updateTheLink();
        fancyLogMessage("DEBUG", "Startup - added link!");
    }

    function updateTheLink() {
        let center = W.map.getCenter();
        const { humanProj, wmeProj } = getOLProjections();
        const projected = new OpenLayers.LonLat(center.lon, center.lat).transform( wmeProj, humanProj );
        let wmeZoom = W.map.getZoom();
        let flockLink = `https://maps.deflock.org/?lat=${projected.lat}&lng=${projected.lon}&zoom=${wmeZoom-1}`;
        link.href = flockLink;
        fancyLogMessage("DEBUG", `Map move - updated link to ${flockLink}`);
    }

    function init() {
        const wmeSDK = getWmeSdk({ scriptId: SCRIPT_SHORT_NAME, scriptName: SCRIPT_LONG_NAME });
        fancyLogMessage("INFO", SCRIPT_LONG_NAME + " " + SCRIPT_VERSION + " started");
        addTheLink();

        // Event registration ripped from tl checker, too
        if (wmeSDK?.Events?.on) {
            wmeSDK.Events.on({
                eventName: "wme-map-move-end",
                eventHandler: updateTheLink
            });

            wmeSDK.Events.on({
                eventName: "wme-map-zoom-changed",
                eventHandler: updateTheLink
            });
        }
        else if (W?.map?.events?.register) {
            W.map.events.register("moveend", null, updateTheLink);
            W.map.events.register("zoomend", null, updateTheLink);
        }
        // Finish Event registration ripped from tl checker, too
        else {
            successfulStartup = false;
        }

        if (successfulStartup) {
            fancyLogMessage("INFO", SCRIPT_LONG_NAME + " initialized!");
        }
        else {
            fancyLogMessage("ERROR", SCRIPT_LONG_NAME + " could not initialize.");
        }
    }

    function bootstrap() {
        if (typeof W === 'object' && W.userscripts?.state.isReady) {
            init();
        } else {
            document.addEventListener('wme-ready', init, { once: true });
        }
    }

    bootstrap();
})();