WME Auto Update URL

updates the url as the map is moved

目前為 2022-12-07 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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);
    }
})();