WME Open DeFlock

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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();
})();