Greasy Fork 支持简体中文。

WME Auto Update URL

updates the url as the map is moved

  1. // ==UserScript==
  2. // @name WME Auto Update URL
  3. // @namespace https://fxzfun.com/
  4. // @version 0.1
  5. // @description updates the url as the map is moved
  6. // @author FXZFun
  7. // @match https://*.waze.com/*/editor*
  8. // @match https://*.waze.com/editor*
  9. // @exclude https://*.waze.com/user/editor*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=waze.com
  11. // @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
  12. // @license GNU GPLv3
  13. // ==/UserScript==
  14.  
  15. /* global W, OL, WazeWrap */
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. (() => {
  21. var i = setInterval(function () {
  22. if (WazeWrap != null && WazeWrap.Ready) {
  23. clearInterval(i);
  24. setTimeout(function() {
  25. addAutoUpdateUrl();
  26. }, 1000);
  27. }
  28. }, 1000);
  29. })();
  30.  
  31. function addAutoUpdateUrl() {
  32. WazeWrap.Events.register("moveend", null, fxz_UpdateUrl);
  33. WazeWrap.Events.register("zoomend", null, fxz_UpdateUrl);
  34. WazeWrap.Events.register("selectionchanged", null, fxz_UpdateUrl);
  35. }
  36.  
  37. function fxz_UpdateUrl() {
  38. var lonlat = new OL.LonLat(W.map.getCenter().lon, W.map.getCenter().lat);
  39. lonlat.transform(new OL.Projection('EPSG:900913'), new OL.Projection('EPSG:4326'));
  40. var zoom = W.map.getZoom();
  41.  
  42. var segments = [];
  43. var venues = [];
  44. W.selectionManager.getSelectedFeatures().forEach(item => {
  45. if (item.model.type == "segment") {
  46. segments.push(item.model.attributes.id);
  47. } else if (item.model.type == "venue") {
  48. venues.push(item.model.attributes.id);
  49. }
  50. });
  51.  
  52. var url = `?env=${W.app._urlParams.env}&lat=${lonlat.lat}&lon=${lonlat.lon}&zoomLevel=${zoom}`;
  53. if (segments.length > 0) url += "&segments=" + segments.join(",");
  54. if (venues.length > 0) url += "&venues=" + venues.join(",");
  55.  
  56. history.replaceState(null, window.title, url);
  57. }
  58. })();