WME URLoc

Updates page's URL to current WME location

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey 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 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.

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

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

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 URLoc
// @version      2024.02.24.001
// @description  Updates page's URL to current WME location
// @author       turbopirate (corrected by_chk update)
// @include      /^https:\/\/(www|beta)\.waze\.com(\/\w{2,3}|\/\w{2,3}-\w{2,3}|\/\w{2,3}-\w{2,3}-\w{2,3})?\/editor\b/
// @grant        none
// @namespace https://greasyfork.org/users/166361
// ==/UserScript==
 
(function() {
    'use strict';
 
    let wazeapi = W || window.W;
    let last = {};
 
    let updateURL = () => {
        if (wazeapi.map.getCenter() && (last.lat !== wazeapi.map.getCenter().lat || last.lon !== wazeapi.map.getCenter().lon || last.zoom !== wazeapi.map.getZoom())) {
            let lonlat=(new OpenLayers.LonLat(wazeapi.map.getCenter().lon, wazeapi.map.getCenter().lat)).transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
            let lon = Math.round(lonlat.lon * 100000) / 100000;
            let lat = Math.round(lonlat.lat * 100000) / 100000;
            let urloc = `${window.location.protocol}//${window.location.host}${window.location.pathname}?env=row&lon=${lon}&lat=${lat}&zoomLevel=${wazeapi.map.getZoom()}`;
            window.history.pushState({path:urloc}, document.title, urloc);
            last.lat = wazeapi.map.getCenter().lat;
            last.lon = wazeapi.map.getCenter().lon;
            last.zoom = wazeapi.map.getZoom();
        }
 
        setTimeout(updateURL, 500);
    };
 
    let waitWaze = () => {
        wazeapi = W || window.W;
 
        if (wazeapi && wazeapi.map) {
            last.lat = wazeapi.map.getCenter().lat;
            last.lon = wazeapi.map.getCenter().lon;
            last.zoom = wazeapi.map.getZoom();
 
            setTimeout(updateURL, 500);
            return;
        }
 
        setTimeout(waitWaze, 500);
        console.log("URLOC: Waiting...");
    };
 
    if (window.history.pushState)
        waitWaze();
    else
        console.error("URLOC: Your browser is not supported!");
})();