Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions SDKGoogleLinkEnhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ==UserScript==
// @name WME Utils - SDK Google Link Enhancer
// @namespace WazeDev
// @version 2026.03.23.00
// @version 2026.03.26.1
// @description Adds some extra WME functionality related to Google place links.
// @author WazeDev group
// @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
Expand Down Expand Up @@ -253,7 +253,8 @@ const SDKGoogleLinkEnhancer = (() => {
})(jQuery);
/* eslint-enable wrap-iife, func-names, object-shorthand */
// In case a place is already selected on load.
const currentSelection = this.sdk.Editing.getSelection();
let currentSelection;
try { currentSelection = this.sdk.Editing.getSelection(); } catch (e) { currentSelection = null; }
if (currentSelection?.ids?.length && currentSelection.objectType === "venue") {
this.#formatLinkElements();
}
Expand Down Expand Up @@ -289,7 +290,8 @@ const SDKGoogleLinkEnhancer = (() => {
#onWmeSelectionChanged() {
if (this.#enabled) {
this.#destroyPoint();
const selected = this.sdk.Editing.getSelection();
let selected;
try { selected = this.sdk.Editing.getSelection(); } catch (e) { return; }
if (selected?.objectType === "venue") {
// The setTimeout is necessary (in beta WME currently, at least) to allow the
// panel UI DOM to update after a place is selected.
Expand Down Expand Up @@ -616,7 +618,8 @@ const SDKGoogleLinkEnhancer = (() => {
.attr("title", this.strings.badLink);
}
else {
const selection = this.sdk.Editing.getSelection();
let selection;
try { selection = this.sdk.Editing.getSelection(); } catch (e) { selection = null; }
if (selection?.objectType === "venue") {
const venue = this.sdk.DataModel.Venues.getById({ venueId: selection.ids[0] });
if (venue && this.#isLinkTooFar(link, venue)) {
Expand Down Expand Up @@ -645,7 +648,8 @@ const SDKGoogleLinkEnhancer = (() => {
throw new Error(msg);
}
const existingLinks = {};
const thisVenue = sdk.Editing.getSelection();
let thisVenue;
try { thisVenue = sdk.Editing.getSelection(); } catch (e) { return {}; }
if (thisVenue?.objectType !== "venue")
return {};
for (const venue of sdk.DataModel.Venues.getAll()) {
Expand Down Expand Up @@ -690,7 +694,8 @@ const SDKGoogleLinkEnhancer = (() => {
if (!link.notFound) {
const coord = link.loc;
const poiPt = this.trf.point([coord.lng, coord.lat]);
const selection = this.sdk.Editing.getSelection();
let selection;
try { selection = this.sdk.Editing.getSelection(); } catch (e) { selection = null; }
let placeGeom;
if (selection?.objectType === "venue") {
const v = this.sdk.DataModel.Venues.getById({ venueId: selection.ids[0] });
Expand Down Expand Up @@ -784,7 +789,8 @@ const SDKGoogleLinkEnhancer = (() => {
}
#getIdFromElement($el) {
const providerIndex = $el.parent().children().toArray().indexOf($el[0]);
const selection = this.sdk.Editing.getSelection();
let selection;
try { selection = this.sdk.Editing.getSelection(); } catch (e) { return null; }
if (!selection || selection.objectType !== "venue") return null;
const venue = this.sdk.DataModel.Venues.getById({ venueId: selection.ids[0] });
return venue?.externalProviderIds?.[providerIndex] ?? null;
Expand Down