WME Auto Update URL

updates the url as the map is moved

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         WME Auto Update URL
// @namespace    https://fxzfun.com/
// @version      0.1
// @description  updates the url as the map is moved
// @author       FXZFun
// @match        https://*.waze.com/*/editor*
// @match        https://*.waze.com/editor*
// @exclude      https://*.waze.com/user/editor*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=waze.com
// @require      https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
// @license      GNU GPLv3
// ==/UserScript==

/* global W, OL, WazeWrap */

(function() {
    'use strict';

    (() => {
        var i = setInterval(function () {
            if (WazeWrap != null && WazeWrap.Ready) {
                clearInterval(i);
                setTimeout(function() {
                    addAutoUpdateUrl();
                }, 1000);
            }
        }, 1000);
    })();

    function addAutoUpdateUrl() {
        WazeWrap.Events.register("moveend", null, fxz_UpdateUrl);
        WazeWrap.Events.register("zoomend", null, fxz_UpdateUrl);
        WazeWrap.Events.register("selectionchanged", null, fxz_UpdateUrl);
    }

    function fxz_UpdateUrl() {
        var lonlat = new OL.LonLat(W.map.getCenter().lon, W.map.getCenter().lat);
        lonlat.transform(new OL.Projection('EPSG:900913'), new OL.Projection('EPSG:4326'));
        var zoom = W.map.getZoom();

        var segments = [];
        var venues = [];
        W.selectionManager.getSelectedFeatures().forEach(item => {
            if (item.model.type == "segment") {
                segments.push(item.model.attributes.id);
            } else if (item.model.type == "venue") {
                venues.push(item.model.attributes.id);
            }
        });

        var url = `?env=${W.app._urlParams.env}&lat=${lonlat.lat}&lon=${lonlat.lon}&zoomLevel=${zoom}`;
        if (segments.length > 0) url += "&segments=" + segments.join(",");
        if (venues.length > 0) url += "&venues=" + venues.join(",");

        history.replaceState(null, window.title, url);
    }
})();