1313/* global W */
1414/* global jQuery */
1515/* global GM_info */
16+ /* global google */
1617
1718// /* eslint-disable */
1819/* eslint-disable no-unused-vars */
@@ -45,7 +46,8 @@ class GoogleLinkEnhancer {
4546 this . strings . badLink = 'Invalid Google link. Please remove it.' ;
4647 this . strings . tooFar = 'The Google linked place is more than {0} meters from the Waze place. Please verify the link is correct.' ;
4748
48- this . _urlBase = `${ this . _urlOrigin } /maps/api/place/details/json?fields=geometry,business_status&${ this . DEC ( 'YTJWNVBVRkplbUZUZVVObFltSkZVM0pYUlZKWk1VMVNXalUyWjBWQlpuQjBOM1JMTWxJMmFGWmZTUT09' ) } &` ;
49+ const attributionElem = document . createElement ( 'div' ) ;
50+ this . _placesService = new google . maps . places . PlacesService ( attributionElem ) ;
4951
5052 this . _initLZString ( ) ;
5153
@@ -174,7 +176,6 @@ class GoogleLinkEnhancer {
174176 }
175177
176178 enable ( ) {
177- return ; // TODO 2022-11-02 - remove this line when GLE issues are fixed.
178179 if ( ! this . _enabled ) {
179180 this . _modeObserver . observe ( $ ( '.edit-area #sidebarContent' ) [ 0 ] , { childList : true , subtree : false } ) ;
180181 this . _observeLinks ( ) ;
@@ -364,42 +365,32 @@ class GoogleLinkEnhancer {
364365 // console.log('link cache count: ' + Object.keys(this._linkCache).length, this._linkCache);
365366 }
366367
367- _getLinkInfoAsync ( id ) {
368- const link = this . _linkCache [ id ] ;
369- if ( link ) {
370- return Promise . resolve ( link ) ;
371- }
372- if ( this . _disableApiUntil ) {
373- if ( Date . now ( ) < this . _disableApiUntil ) {
374- return Promise . resolve ( { apiDisabled : true } ) ;
375- }
376- this . _disableApiUntil = null ;
377- }
368+ _getLinkInfoAsync ( placeId ) {
369+ const request = {
370+ placeId,
371+ fields : [ 'geometry' , 'business_status' ]
372+ } ;
373+ debugger ;
378374 return new Promise ( resolve => {
379- let fullUrl = this . _urlBase ;
380- if ( id . startsWith ( 'q=' ) || id . startsWith ( 'cid=' ) ) {
381- fullUrl += id ;
382- } else {
383- fullUrl += `place_id=${ id } ` ;
384- }
385- $ . getJSON ( fullUrl ) . then ( json => {
375+ this . _placesService . getDetails ( request , ( place , requestStatus ) => {
376+ debugger ;
386377 const res = { } ;
387- if ( json . status === 'OK' ) {
388- res . loc = json . result . geometry . location ;
389- if ( json . result . business_status === 'CLOSED_PERMANENTLY' ) {
378+ if ( requestStatus === google . maps . places . PlacesServiceStatus . OK ) {
379+ res . loc = place . geometry . location ;
380+ if ( place . business_status === 'CLOSED_PERMANENTLY' ) {
390381 res . permclosed = true ;
391- } else if ( json . result . business_status === 'CLOSED_TEMPORARILY' ) {
382+ } else if ( place . business_status === 'CLOSED_TEMPORARILY' ) {
392383 res . tempclosed = true ;
393384 }
394- this . _cacheLink ( id , res ) ;
395- } else if ( json . status === ' NOT_FOUND' ) {
385+ this . _cacheLink ( placeId , res ) ;
386+ } else if ( requestStatus === google . maps . places . PlacesServiceStatus . NOT_FOUND ) {
396387 res . notfound = true ;
397- this . _cacheLink ( id , res ) ;
388+ this . _cacheLink ( placeId , res ) ;
398389 } else if ( this . _disableApiUntil ) {
399390 res . apiDisabled = true ;
400391 } else {
401- res . error = json . status ;
402- res . errorMessage = json . error_message ;
392+ res . error = requestStatus ;
393+ // res.errorMessage = json.error_message;
403394 this . _disableApiUntil = Date . now ( ) + 10 * 1000 ; // Disable api calls for 10 seconds.
404395 console . error ( `${ GM_info . script . name } , Google Link Enhancer disabled for 10 seconds due to API error.` , res ) ;
405396 }
@@ -408,6 +399,51 @@ class GoogleLinkEnhancer {
408399 } ) ;
409400 }
410401
402+ // _getLinkInfoAsync(id) {
403+ // const link = this._linkCache[id];
404+ // if (link) {
405+ // return Promise.resolve(link);
406+ // }
407+ // if (this._disableApiUntil) {
408+ // if (Date.now() < this._disableApiUntil) {
409+ // return Promise.resolve({ apiDisabled: true });
410+ // }
411+ // this._disableApiUntil = null;
412+ // }
413+ // return new Promise(resolve => {
414+
415+ // let fullUrl = this._urlBase;
416+ // if (id.startsWith('q=') || id.startsWith('cid=')) {
417+ // fullUrl += id;
418+ // } else {
419+ // fullUrl += `place_id=${id}`;
420+ // }
421+ // $.getJSON(fullUrl).then(json => {
422+ // const res = {};
423+ // if (json.status === 'OK') {
424+ // res.loc = json.result.geometry.location;
425+ // if (json.result.business_status === 'CLOSED_PERMANENTLY') {
426+ // res.permclosed = true;
427+ // } else if (json.result.business_status === 'CLOSED_TEMPORARILY') {
428+ // res.tempclosed = true;
429+ // }
430+ // this._cacheLink(id, res);
431+ // } else if (json.status === 'NOT_FOUND') {
432+ // res.notfound = true;
433+ // this._cacheLink(id, res);
434+ // } else if (this._disableApiUntil) {
435+ // res.apiDisabled = true;
436+ // } else {
437+ // res.error = json.status;
438+ // res.errorMessage = json.error_message;
439+ // this._disableApiUntil = Date.now() + 10 * 1000; // Disable api calls for 10 seconds.
440+ // console.error(`${GM_info.script.name}, Google Link Enhancer disabled for 10 seconds due to API error.`, res);
441+ // }
442+ // resolve(res);
443+ // });
444+ // });
445+ // }
446+
411447 static _onMapMouseenter ( event ) {
412448 // If the point isn't destroyed yet, destroy it when mousing over the map.
413449 event . data . _destroyPoint ( ) ;
0 commit comments