WME Utils - Google Link Enhancer

Adds some extra WME functionality related to Google place links.

当前为 2023-04-11 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/39208/1174440/WME%20Utils%20-%20Google%20Link%20Enhancer.js

  1. // ==UserScript==
  2. // @name WME Utils - Google Link Enhancer
  3. // @namespace WazeDev
  4. // @version 2023.04.11.002
  5. // @description Adds some extra WME functionality related to Google place links.
  6. // @author MapOMatic, WazeDev group
  7. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
  8. // @license GNU GPLv3
  9. // ==/UserScript==
  10.  
  11. /* global OpenLayers */
  12. /* global W */
  13. /* global google */
  14.  
  15. // /* eslint-disable */
  16. /* eslint-disable no-unused-vars */
  17. class GoogleLinkEnhancer {
  18. #DISABLE_CLOSED_PLACES = false; // Set to TRUE if the feature needs to be temporarily disabled, e.g. during the COVID-19 pandemic.
  19. #EXT_PROV_ELEM_QUERY = 'wz-list-item.external-provider';
  20. #EXT_PROV_ELEM_EDIT_QUERY = 'wz-list-item.external-provider-edit';
  21. #EXT_PROV_ELEM_CONTENT_QUERY = 'div.external-provider-content';
  22. #LINK_CACHE_NAME = 'gle_link_cache';
  23. #LINK_CACHE_CLEAN_INTERVAL_MIN = 1; // Interval to remove old links and save new ones.
  24. #LINK_CACHE_LIFESPAN_HR = 6; // Remove old links when they exceed this time limit.
  25.  
  26. #linkCache;
  27. #enabled = false;
  28. #disableApiUntil = null; // When a serious API error occurs (OVER_QUERY_LIMIT, REQUEST_DENIED), set this to a time in the future.
  29. #mapLayer = null;
  30. #distanceLimit = 400; // Default distance (meters) when Waze place is flagged for being too far from Google place.
  31. // Area place is calculated as #distanceLimit + <distance between centroid and furthest node>
  32. #showTempClosedPOIs = true;
  33. #placesService;
  34. #linkObserver;
  35. #modeObserver;
  36. #searchResultsObserver;
  37. #lzString;
  38. #cacheCleanIntervalID;
  39. #originalHeadAppendChildMethod;
  40. #ptFeature;
  41. #lineFeature;
  42. #timeoutID;
  43. strings = {
  44. permClosedPlace: 'Google indicates this place is permanently closed.\nVerify with other sources or your editor community before deleting.',
  45. tempClosedPlace: 'Google indicates this place is temporarily closed.',
  46. multiLinked: 'Linked more than once already. Please find and remove multiple links.',
  47. linkedToThisPlace: 'Already linked to this place',
  48. linkedNearby: 'Already linked to a nearby place',
  49. linkedToXPlaces: 'This is linked to {0} places',
  50. badLink: 'Invalid Google link. Please remove it.',
  51. tooFar: 'The Google linked place is more than {0} meters from the Waze place. Please verify the link is correct.'
  52. };
  53.  
  54. /* eslint-enable no-unused-vars */
  55. constructor() {
  56. const attributionElem = document.createElement('div');
  57. this.#placesService = new google.maps.places.PlacesService(attributionElem);
  58. this.#initLZString();
  59. const STORED_CACHE = localStorage.getItem(this.#LINK_CACHE_NAME);
  60. try {
  61. this.#linkCache = STORED_CACHE ? $.parseJSON(this.#lzString.decompressFromUTF16(STORED_CACHE)) : {};
  62. } catch (ex) {
  63. if (ex.name === 'SyntaxError') {
  64. // In case the cache is corrupted and can't be read.
  65. this.#linkCache = {};
  66. console.warn('GoogleLinkEnhancer:', 'An error occurred while loading the stored cache. A new cache was created.');
  67. } else {
  68. throw ex;
  69. }
  70. }
  71. if (this.#linkCache === null || this.#linkCache.length === 0) this.#linkCache = {};
  72.  
  73. this.#initLayer();
  74.  
  75. // NOTE: Arrow functions are necessary for calling methods on object instances.
  76. // This could be made more efficient by only processing the relevant places.
  77. W.model.events.register('mergeend', null, () => { this.#processPlaces(); });
  78. W.model.venues.on('objectschanged', () => { this.#processPlaces(); });
  79. W.model.venues.on('objectsremoved', () => { this.#processPlaces(); });
  80. W.model.venues.on('objectsadded', () => { this.#processPlaces(); });
  81.  
  82. // Watch for ext provider elements being added to the DOM, and add hover events.
  83. this.#linkObserver = new MutationObserver(mutations => {
  84. mutations.forEach(mutation => {
  85. for (let idx = 0; idx < mutation.addedNodes.length; idx++) {
  86. const nd = mutation.addedNodes[idx];
  87. if (nd.nodeType === Node.ELEMENT_NODE) {
  88. const $el = $(nd);
  89. const $subel = $el.find(this.#EXT_PROV_ELEM_QUERY);
  90. if ($el.is(this.#EXT_PROV_ELEM_QUERY)) {
  91. this.#addHoverEvent($el);
  92. this.#formatLinkElements();
  93. } else if ($subel.length) {
  94. for (let i = 0; i < $subel.length; i++) {
  95. this.#addHoverEvent($($subel[i]));
  96. }
  97. this.#formatLinkElements();
  98. }
  99. if ($el.is(this.#EXT_PROV_ELEM_EDIT_QUERY)) {
  100. this.#searchResultsObserver.observe($el.find('wz-autocomplete[placeholder="Search for a place"]')[0].shadowRoot, { childList: true, subtree: true });
  101. }
  102. }
  103. }
  104. for (let idx = 0; idx < mutation.removedNodes.length; idx++) {
  105. const nd = mutation.removedNodes[idx];
  106. if (nd.nodeType === Node.ELEMENT_NODE) {
  107. const $el = $(nd);
  108. if ($el.is(this.#EXT_PROV_ELEM_EDIT_QUERY)) {
  109. this.#searchResultsObserver.disconnect();
  110. }
  111. }
  112. }
  113. });
  114. });
  115.  
  116. // Watch for Google place search result list items being added to the DOM
  117. const that = this;
  118. this.#searchResultsObserver = new MutationObserver(mutations => {
  119. mutations.forEach(mutation => {
  120. for (let idx = 0; idx < mutation.addedNodes.length; idx++) {
  121. const nd = mutation.addedNodes[idx];
  122. if (nd.nodeType === Node.ELEMENT_NODE && $(nd).is('wz-menu-item.simple-item')) {
  123. $(nd).mouseenter(() => {
  124. // When mousing over a list item, find the Google place ID from the list that was stored previously.
  125. // Then add the point/line to the map.
  126. that.#addPoint($(nd).attr('item-id'));
  127. }).mouseleave(() => {
  128. // When leaving the list item, remove the point.
  129. that.#destroyPoint();
  130. });
  131. }
  132. }
  133. });
  134. });
  135.  
  136. // Watch the side panel for addition of the sidebar-layout div, which indicates a mode change.
  137. this.#modeObserver = new MutationObserver(mutations => {
  138. mutations.forEach(mutation => {
  139. for (let idx = 0; idx < mutation.addedNodes.length; idx++) {
  140. const nd = mutation.addedNodes[idx];
  141. if (nd.nodeType === Node.ELEMENT_NODE && $(nd).is('.sidebar-layout')) {
  142. this.#observeLinks();
  143. break;
  144. }
  145. }
  146. });
  147. });
  148.  
  149. // This is a special event that will be triggered when DOM elements are destroyed.
  150. /* eslint-disable wrap-iife, func-names, object-shorthand */
  151. (function($) {
  152. $.event.special.destroyed = {
  153. remove: function(o) {
  154. if (o.handler && o.type !== 'destroyed') {
  155. o.handler();
  156. }
  157. }
  158. };
  159. })(jQuery);
  160. /* eslint-enable wrap-iife, func-names, object-shorthand */
  161.  
  162. // In case a place is already selected on load.
  163. const selFeatures = W.selectionManager.getSelectedFeatures();
  164. if (selFeatures.length && selFeatures[0].model.type === 'venue') {
  165. this.#formatLinkElements();
  166. }
  167. }
  168.  
  169. #initLayer() {
  170. this.#mapLayer = new OpenLayers.Layer.Vector('Google Link Enhancements.', {
  171. uniqueName: '___GoogleLinkEnhancements',
  172. displayInLayerSwitcher: true,
  173. styleMap: new OpenLayers.StyleMap({
  174. default: {
  175. strokeColor: '${strokeColor}',
  176. strokeWidth: '${strokeWidth}',
  177. strokeDashstyle: '${strokeDashstyle}',
  178. pointRadius: '15',
  179. fillOpacity: '0'
  180. }
  181. })
  182. });
  183.  
  184. this.#mapLayer.setOpacity(0.8);
  185. W.map.addLayer(this.#mapLayer);
  186. }
  187.  
  188. enable() {
  189. if (!this.#enabled) {
  190. this.#modeObserver.observe($('.edit-area #sidebarContent')[0], { childList: true, subtree: false });
  191. this.#observeLinks();
  192. // Watch for JSONP callbacks. JSONP is used for the autocomplete results when searching for Google links.
  193. this.#addJsonpInterceptor();
  194. // Note: Using on() allows passing "this" as a variable, so it can be used in the handler function.
  195. $('#map').on('mouseenter', null, this, GoogleLinkEnhancer.#onMapMouseenter);
  196. $(window).on('unload', null, this, GoogleLinkEnhancer.#onWindowUnload);
  197. W.model.venues.on('objectschanged', this.#formatLinkElements, this);
  198. this.#processPlaces();
  199. this.#cleanAndSaveLinkCache();
  200. this.#cacheCleanIntervalID = setInterval(() => this.#cleanAndSaveLinkCache(), 1000 * 60 * this.#LINK_CACHE_CLEAN_INTERVAL_MIN);
  201. this.#enabled = true;
  202. }
  203. }
  204.  
  205. disable() {
  206. if (this.#enabled) {
  207. this.#modeObserver.disconnect();
  208. this.#linkObserver.disconnect();
  209. this.#searchResultsObserver.disconnect();
  210. this.#removeJsonpInterceptor();
  211. $('#map').off('mouseenter', GoogleLinkEnhancer.#onMapMouseenter);
  212. $(window).off('unload', null, this, GoogleLinkEnhancer.#onWindowUnload);
  213. W.model.venues.off('objectschanged', this.#formatLinkElements, this);
  214. if (this.#cacheCleanIntervalID) clearInterval(this.#cacheCleanIntervalID);
  215. this.#cleanAndSaveLinkCache();
  216. this.#enabled = false;
  217. }
  218. }
  219.  
  220. // The distance (in meters) before flagging a Waze place that is too far from the linked Google place.
  221. // Area places use distanceLimit, plus the distance from the centroid of the AP to its furthest node.
  222. get distanceLimit() {
  223. return this.#distanceLimit;
  224. }
  225.  
  226. set distanceLimit(value) {
  227. this.#distanceLimit = value;
  228. this.#processPlaces();
  229. }
  230.  
  231. get showTempClosedPOIs() {
  232. return this.#showTempClosedPOIs;
  233. }
  234.  
  235. set showTempClosedPOIs(value) {
  236. this.#showTempClosedPOIs = value;
  237. this.#processPlaces();
  238. }
  239.  
  240. static #onWindowUnload(evt) {
  241. evt.data.#cleanAndSaveLinkCache();
  242. }
  243.  
  244. #cleanAndSaveLinkCache() {
  245. if (!this.#linkCache) return;
  246. const now = new Date();
  247. Object.keys(this.#linkCache).forEach(id => {
  248. const link = this.#linkCache[id];
  249. // Bug fix:
  250. if (link.location) {
  251. link.loc = link.location;
  252. delete link.location;
  253. }
  254. // Delete link if older than X hours.
  255. if (!link.ts || (now - new Date(link.ts)) > this.#LINK_CACHE_LIFESPAN_HR * 3600 * 1000) {
  256. delete this.#linkCache[id];
  257. }
  258. });
  259. localStorage.setItem(this.#LINK_CACHE_NAME, this.#lzString.compressToUTF16(JSON.stringify(this.#linkCache)));
  260. // console.log('link cache count: ' + Object.keys(this.#linkCache).length, this.#linkCache);
  261. }
  262.  
  263. // Borrowed from WazeWrap
  264. static #distanceBetweenPoints(point1, point2) {
  265. const line = new OpenLayers.Geometry.LineString([point1, point2]);
  266. const length = line.getGeodesicLength(W.map.getProjectionObject());
  267. return length; // multiply by 3.28084 to convert to feet
  268. }
  269.  
  270. #isLinkTooFar(link, venue) {
  271. if (link.loc) {
  272. const linkPt = new OpenLayers.Geometry.Point(link.loc.lng, link.loc.lat);
  273. linkPt.transform(W.Config.map.projection.remote, W.map.getProjectionObject());
  274. let venuePt;
  275. let distanceLim = this.distanceLimit;
  276. if (venue.isPoint()) {
  277. venuePt = venue.geometry.getCentroid();
  278. } else {
  279. const bounds = venue.geometry.getBounds();
  280. const center = bounds.getCenterLonLat();
  281. venuePt = new OpenLayers.Geometry.Point(center.lon, center.lat);
  282. const topRightPt = new OpenLayers.Geometry.Point(bounds.right, bounds.top);
  283. distanceLim += GoogleLinkEnhancer.#distanceBetweenPoints(venuePt, topRightPt);
  284. }
  285. const distance = GoogleLinkEnhancer.#distanceBetweenPoints(linkPt, venuePt);
  286. return distance > distanceLim;
  287. }
  288. return false;
  289. }
  290.  
  291. #processPlaces() {
  292. return; // Disabled until we can find a fix.
  293. try {
  294. if (this.#enabled) {
  295. const that = this;
  296. // Get a list of already-linked id's
  297. const existingLinks = GoogleLinkEnhancer.#getExistingLinks();
  298. this.#mapLayer.removeAllFeatures();
  299. const drawnLinks = [];
  300. W.model.venues.getObjectArray().forEach(venue => {
  301. const promises = [];
  302. venue.attributes.externalProviderIDs.forEach(provID => {
  303. const id = provID.attributes.uuid;
  304.  
  305. // Check for duplicate links
  306. const linkInfo = existingLinks[id];
  307. if (linkInfo.count > 1) {
  308. const geometry = venue.isPoint() ? venue.geometry.getCentroid() : venue.geometry.clone();
  309. const width = venue.isPoint() ? '4' : '12';
  310. const color = '#fb8d00';
  311. const features = [new OpenLayers.Feature.Vector(geometry, {
  312. strokeWidth: width, strokeColor: color
  313. })];
  314. const lineStart = geometry.getCentroid();
  315. linkInfo.venues.forEach(linkVenue => {
  316. if (linkVenue !== venue
  317. && !drawnLinks.some(dl => (dl[0] === venue && dl[1] === linkVenue) || (dl[0] === linkVenue && dl[1] === venue))) {
  318. features.push(
  319. new OpenLayers.Feature.Vector(
  320. new OpenLayers.Geometry.LineString([lineStart, linkVenue.geometry.getCentroid()]),
  321. {
  322. strokeWidth: 4,
  323. strokeColor: color,
  324. strokeDashstyle: '12 12'
  325. }
  326. )
  327. );
  328. drawnLinks.push([venue, linkVenue]);
  329. }
  330. });
  331. that.#mapLayer.addFeatures(features);
  332. }
  333.  
  334. // Get Google link info, and store results for processing.
  335. promises.push(that.#getLinkInfoAsync(id));
  336. });
  337.  
  338. // Process all results of link lookups and add a highlight feature if needed.
  339. Promise.all(promises).then(results => {
  340. let strokeColor = null;
  341. let strokeDashStyle = 'solid';
  342. if (!that.#DISABLE_CLOSED_PLACES && results.some(res => res.permclosed)) {
  343. if (/^(\[|\()?(permanently )?closed(\]|\)| -)/i.test(venue.attributes.name)
  344. || /(\(|- |\[)(permanently )?closed(\)|\])?$/i.test(venue.attributes.name)) {
  345. strokeDashStyle = venue.isPoint() ? '2 6' : '2 16';
  346. }
  347. strokeColor = '#F00';
  348. } else if (results.some(res => that.#isLinkTooFar(res, venue))) {
  349. strokeColor = '#0FF';
  350. } else if (!that.#DISABLE_CLOSED_PLACES && that.#showTempClosedPOIs && results.some(res => res.tempclosed)) {
  351. if (/^(\[|\()?(temporarily )?closed(\]|\)| -)/i.test(venue.attributes.name)
  352. || /(\(|- |\[)(temporarily )?closed(\)|\])?$/i.test(venue.attributes.name)) {
  353. strokeDashStyle = venue.isPoint() ? '2 6' : '2 16';
  354. }
  355. strokeColor = '#FD3';
  356. } else if (results.some(res => res.notFound)) {
  357. strokeColor = '#F0F';
  358. }
  359. if (strokeColor) {
  360. const style = {
  361. strokeWidth: venue.isPoint() ? '4' : '12',
  362. strokeColor,
  363. strokeDashStyle
  364. };
  365. const geometry = venue.isPoint() ? venue.geometry.getCentroid() : venue.geometry.clone();
  366. that.#mapLayer.addFeatures([new OpenLayers.Feature.Vector(geometry, style)]);
  367. }
  368. });
  369. });
  370. }
  371. } catch (ex) {
  372. console.error('PIE (Google Link Enhancer) error:', ex);
  373. }
  374. }
  375.  
  376. #cacheLink(id, link) {
  377. link.ts = new Date();
  378. this.#linkCache[id] = link;
  379. // console.log('link cache count: ' + Object.keys(this.#linkCache).length, this.#linkCache);
  380. }
  381.  
  382. #getLinkInfoAsync(placeId) {
  383. return new Promise(resolve => {
  384. let link = this.#linkCache[placeId];
  385. if (!link) {
  386. const request = {
  387. placeId,
  388. fields: ['geometry', 'business_status']
  389. };
  390. this.#placesService.getDetails(request, (place, requestStatus) => {
  391. link = {};
  392. if (requestStatus === google.maps.places.PlacesServiceStatus.OK) {
  393. const loc = place.geometry.location;
  394. link.loc = { lng: loc.lng(), lat: loc.lat() };
  395. if (place.business_status === 'CLOSED_PERMANENTLY') {
  396. link.permclosed = true;
  397. } else if (place.business_status === 'CLOSED_TEMPORARILY') {
  398. link.tempclosed = true;
  399. }
  400. this.#cacheLink(placeId, link);
  401. } else if (requestStatus === google.maps.places.PlacesServiceStatus.NOT_FOUND) {
  402. link.notfound = true;
  403. this.#cacheLink(placeId, link);
  404. } else if (this.#disableApiUntil) {
  405. link.apiDisabled = true;
  406. } else {
  407. link.error = requestStatus;
  408. // res.errorMessage = json.error_message;
  409. this.#disableApiUntil = Date.now() + 10 * 1000; // Disable api calls for 10 seconds.
  410. console.error(`${GM_info.script.name}, Google Link Enhancer disabled for 10 seconds due to API error.`, link);
  411. }
  412. resolve(link);
  413. });
  414. } else {
  415. resolve(link);
  416. }
  417. });
  418. }
  419.  
  420. // _getLinkInfoAsync(id) {
  421. // const link = this.#linkCache[id];
  422. // if (link) {
  423. // return Promise.resolve(link);
  424. // }
  425. // if (this.#disableApiUntil) {
  426. // if (Date.now() < this.#disableApiUntil) {
  427. // return Promise.resolve({ apiDisabled: true });
  428. // }
  429. // this.#disableApiUntil = null;
  430. // }
  431. // return new Promise(resolve => {
  432.  
  433. // let fullUrl = this._urlBase;
  434. // if (id.startsWith('q=') || id.startsWith('cid=')) {
  435. // fullUrl += id;
  436. // } else {
  437. // fullUrl += `place_id=${id}`;
  438. // }
  439. // $.getJSON(fullUrl).then(json => {
  440. // const res = {};
  441. // if (json.status === 'OK') {
  442. // res.loc = json.result.geometry.location;
  443. // if (json.result.business_status === 'CLOSED_PERMANENTLY') {
  444. // res.permclosed = true;
  445. // } else if (json.result.business_status === 'CLOSED_TEMPORARILY') {
  446. // res.tempclosed = true;
  447. // }
  448. // this._cacheLink(id, res);
  449. // } else if (json.status === 'NOT_FOUND') {
  450. // res.notfound = true;
  451. // this._cacheLink(id, res);
  452. // } else if (this.#disableApiUntil) {
  453. // res.apiDisabled = true;
  454. // } else {
  455. // res.error = json.status;
  456. // res.errorMessage = json.error_message;
  457. // this.#disableApiUntil = Date.now() + 10 * 1000; // Disable api calls for 10 seconds.
  458. // console.error(`${GM_info.script.name}, Google Link Enhancer disabled for 10 seconds due to API error.`, res);
  459. // }
  460. // resolve(res);
  461. // });
  462. // });
  463. // }
  464.  
  465. static #onMapMouseenter(event) {
  466. // If the point isn't destroyed yet, destroy it when mousing over the map.
  467. event.data.#destroyPoint();
  468. }
  469.  
  470. static #getSelectedFeatures() {
  471. if (!W.selectionManager.getSelectedFeatures) {
  472. return W.selectionManager.selectedItems;
  473. }
  474. return W.selectionManager.getSelectedFeatures();
  475. }
  476.  
  477. async #formatLinkElements(callCount = 0) {
  478. const $links = $('#edit-panel').find(this.#EXT_PROV_ELEM_QUERY);
  479. const selFeatures = W.selectionManager.getSelectedFeatures();
  480. if (!$links.length) {
  481. // If links aren't available, continue calling this function for up to 3 seconds unless place has been deselected.
  482. if (callCount < 30 && selFeatures.length && selFeatures[0].model.type === 'venue') {
  483. setTimeout(() => this.#formatLinkElements(++callCount), 100);
  484. }
  485. } else {
  486. const existingLinks = GoogleLinkEnhancer.#getExistingLinks();
  487.  
  488. // fetch all links first
  489. const promises = [];
  490. const extProvElements = [];
  491. $links.each((ix, linkEl) => {
  492. const $linkEl = $(linkEl);
  493. extProvElements.push($linkEl);
  494.  
  495. const id = GoogleLinkEnhancer.#getIdFromElement($linkEl);
  496. if (!id) return;
  497.  
  498. promises.push(this.#getLinkInfoAsync(id));
  499. });
  500. await Promise.all(promises);
  501.  
  502. extProvElements.forEach($extProvElem => {
  503. const id = GoogleLinkEnhancer.#getIdFromElement($extProvElem);
  504.  
  505. if (!id) return;
  506.  
  507. const link = this.#linkCache[id];
  508. if (existingLinks[id] && existingLinks[id].count > 1 && existingLinks[id].isThisVenue) {
  509. setTimeout(() => {
  510. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '#FFA500' }).attr({
  511. title: this.strings.linkedToXPlaces.replace('{0}', existingLinks[id].count)
  512. });
  513. }, 50);
  514. }
  515. this.#addHoverEvent($extProvElem);
  516. if (link) {
  517. if (link.permclosed && !this.#DISABLE_CLOSED_PLACES) {
  518. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '#FAA' }).attr('title', this.strings.permClosedPlace);
  519. } else if (link.tempclosed && !this.#DISABLE_CLOSED_PLACES) {
  520. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '#FFA' }).attr('title', this.strings.tempClosedPlace);
  521. } else if (link.notFound) {
  522. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '#F0F' }).attr('title', this.strings.badLink);
  523. } else {
  524. const venue = GoogleLinkEnhancer.#getSelectedFeatures()[0].model;
  525. if (this.#isLinkTooFar(link, venue)) {
  526. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '#0FF' }).attr('title', this.strings.tooFar.replace('{0}', this.distanceLimit));
  527. } else { // reset in case we just deleted another provider
  528. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '' }).attr('title', '');
  529. }
  530. }
  531. }
  532. });
  533. }
  534. }
  535.  
  536. static #getExistingLinks() {
  537. const existingLinks = {};
  538. let thisVenue;
  539. if (GoogleLinkEnhancer.#getSelectedFeatures().length) {
  540. thisVenue = GoogleLinkEnhancer.#getSelectedFeatures()[0].model;
  541. }
  542. W.model.venues.getObjectArray().forEach(venue => {
  543. const isThisVenue = venue === thisVenue;
  544. const thisPlaceIDs = [];
  545. venue.attributes.externalProviderIDs.forEach(provID => {
  546. const id = provID.attributes.uuid;
  547. if (thisPlaceIDs.indexOf(id) === -1) {
  548. thisPlaceIDs.push(id);
  549. let link = existingLinks[id];
  550. if (link) {
  551. link.count++;
  552. link.venues.push(venue);
  553. } else {
  554. link = { count: 1, venues: [venue] };
  555. existingLinks[id] = link;
  556. if (provID.attributes.url != null) {
  557. const u = provID.attributes.url.replace('https://maps.google.com/?', '');
  558. link.url = u;
  559. }
  560. }
  561. link.isThisVenue = link.isThisVenue || isThisVenue;
  562. }
  563. });
  564. });
  565. return existingLinks;
  566. }
  567.  
  568. // Remove the POI point from the map.
  569. #destroyPoint() {
  570. if (this.#ptFeature) {
  571. this.#ptFeature.destroy();
  572. this.#ptFeature = null;
  573. this.#lineFeature.destroy();
  574. this.#lineFeature = null;
  575. }
  576. }
  577.  
  578. // Add the POI point to the map.
  579. #addPoint(id) {
  580. if (!id) return;
  581. const link = this.#linkCache[id];
  582. if (link) {
  583. if (!link.notFound) {
  584. const coord = link.loc;
  585. const poiPt = new OpenLayers.Geometry.Point(coord.lng, coord.lat);
  586. poiPt.transform(W.Config.map.projection.remote, W.map.getProjectionObject().projCode);
  587. const placeGeom = GoogleLinkEnhancer.#getSelectedFeatures()[0].geometry.getCentroid();
  588. const placePt = new OpenLayers.Geometry.Point(placeGeom.x, placeGeom.y);
  589. const ext = W.map.getExtent();
  590. const lsBounds = new OpenLayers.Geometry.LineString([
  591. new OpenLayers.Geometry.Point(ext.left, ext.bottom),
  592. new OpenLayers.Geometry.Point(ext.left, ext.top),
  593. new OpenLayers.Geometry.Point(ext.right, ext.top),
  594. new OpenLayers.Geometry.Point(ext.right, ext.bottom),
  595. new OpenLayers.Geometry.Point(ext.left, ext.bottom)]);
  596. let lsLine = new OpenLayers.Geometry.LineString([placePt, poiPt]);
  597.  
  598. // If the line extends outside the bounds, split it so we don't draw a line across the world.
  599. const splits = lsLine.splitWith(lsBounds);
  600. let label = '';
  601. if (splits) {
  602. let splitPoints;
  603. splits.forEach(split => {
  604. split.components.forEach(component => {
  605. if (component.x === placePt.x && component.y === placePt.y) splitPoints = split;
  606. });
  607. });
  608. lsLine = new OpenLayers.Geometry.LineString([splitPoints.components[0], splitPoints.components[1]]);
  609. let distance = GoogleLinkEnhancer.#distanceBetweenPoints(poiPt, placePt);
  610. let unitConversion;
  611. let unit1;
  612. let unit2;
  613. if (W.model.isImperial) {
  614. distance *= 3.28084;
  615. unitConversion = 5280;
  616. unit1 = ' ft';
  617. unit2 = ' mi';
  618. } else {
  619. unitConversion = 1000;
  620. unit1 = ' m';
  621. unit2 = ' km';
  622. }
  623. if (distance > unitConversion * 10) {
  624. label = Math.round(distance / unitConversion) + unit2;
  625. } else if (distance > 1000) {
  626. label = (Math.round(distance / (unitConversion / 10)) / 10) + unit2;
  627. } else {
  628. label = Math.round(distance) + unit1;
  629. }
  630. }
  631.  
  632. this.#destroyPoint(); // Just in case it still exists.
  633. this.#ptFeature = new OpenLayers.Feature.Vector(poiPt, { poiCoord: true }, {
  634. pointRadius: 6,
  635. strokeWidth: 30,
  636. strokeColor: '#FF0',
  637. fillColor: '#FF0',
  638. strokeOpacity: 0.5
  639. });
  640. this.#lineFeature = new OpenLayers.Feature.Vector(lsLine, {}, {
  641. strokeWidth: 3,
  642. strokeDashstyle: '12 8',
  643. strokeColor: '#FF0',
  644. label,
  645. labelYOffset: 45,
  646. fontColor: '#FF0',
  647. fontWeight: 'bold',
  648. labelOutlineColor: '#000',
  649. labelOutlineWidth: 4,
  650. fontSize: '18'
  651. });
  652. W.map.getLayerByUniqueName('venues').addFeatures([this.#ptFeature, this.#lineFeature]);
  653. this.#timeoutDestroyPoint();
  654. }
  655. } else {
  656. this.#getLinkInfoAsync(id).then(res => {
  657. if (res.error || res.apiDisabled) {
  658. // API was temporarily disabled. Ignore for now.
  659. } else {
  660. this.#addPoint(id);
  661. }
  662. });
  663. }
  664. }
  665.  
  666. // Destroy the point after some time, if it hasn't been destroyed already.
  667. #timeoutDestroyPoint() {
  668. if (this.#timeoutID) clearTimeout(this.#timeoutID);
  669. this.#timeoutID = setTimeout(() => this.#destroyPoint(), 4000);
  670. }
  671.  
  672. static #getIdFromElement($el) {
  673. const providerIndex = $el.parent().children().toArray().indexOf($el[0]);
  674. return W.selectionManager.getSelectedFeatures()[0].model.getExternalProviderIDs()[providerIndex]?.attributes.uuid;
  675. }
  676.  
  677. #addHoverEvent($el) {
  678. $el.hover(() => this.#addPoint(GoogleLinkEnhancer.#getIdFromElement($el)), () => this.#destroyPoint());
  679. }
  680.  
  681. #observeLinks() {
  682. this.elem = document.querySelector('#edit-panel');
  683. this.#linkObserver.observe(document.querySelector('#edit-panel'), { childList: true, subtree: true });
  684. }
  685.  
  686. // The JSONP interceptor is used to watch the head element for the addition of JSONP functions
  687. // that process Google link search results. Those functions are overridden by our own so we can
  688. // process the results before sending them on to the original function.
  689. #addJsonpInterceptor() {
  690. // The idea for this function was hatched here:
  691. // https://stackoverflow.com/questions/6803521/can-google-maps-places-autocomplete-api-be-used-via-ajax/9856786
  692.  
  693. // The head element, where the Google Autocomplete code will insert a tag
  694. // for a javascript file.
  695. const head = $('head')[0];
  696. // The name of the method the Autocomplete code uses to insert the tag.
  697. const method = 'appendChild';
  698. // The method we will be overriding.
  699. const originalMethod = head[method];
  700. this.#originalHeadAppendChildMethod = originalMethod;
  701. const that = this;
  702. /* eslint-disable func-names, prefer-rest-params */ // Doesn't work as an arrow function (at least not without some modifications)
  703. head[method] = function() {
  704. // Check that the element is a javascript tag being inserted by Google.
  705. if (arguments[0] && arguments[0].src && arguments[0].src.match(/GetPredictions/)) {
  706. // Regex to extract the name of the callback method that the JSONP will call.
  707. const callbackMatchObject = (/callback=([^&]+)&|$/).exec(arguments[0].src);
  708.  
  709. // Regex to extract the search term that was entered by the user.
  710. const searchTermMatchObject = (/\?1s([^&]+)&/).exec(arguments[0].src);
  711.  
  712. // const searchTerm = unescape(searchTermMatchObject[1]);
  713. if (callbackMatchObject && searchTermMatchObject) {
  714. // The JSONP callback method is in the form "abc.def" and each time has a different random name.
  715. const names = callbackMatchObject[1].split('.');
  716. // Store the original callback method.
  717. const originalCallback = names[0] && names[1] && window[names[0]] && window[names[0]][names[1]];
  718.  
  719. if (originalCallback) {
  720. const newCallback = function() { // Define your own JSONP callback
  721. if (arguments[0] && arguments[0].predictions) {
  722. // SUCCESS!
  723.  
  724. // The autocomplete results
  725. const data = arguments[0];
  726.  
  727. // console.log('GLE: ' + JSON.stringify(data));
  728. that._lastSearchResultPlaceIds = data.predictions.map(pred => pred.place_id);
  729.  
  730. // Call the original callback so the WME dropdown can do its thing.
  731. originalCallback(data);
  732. }
  733. };
  734.  
  735. // Add copy of all the attributes of the old callback function to the new callback function.
  736. // This prevents the autocomplete functionality from throwing an error.
  737. Object.keys(originalCallback).forEach(key => {
  738. newCallback[key] = originalCallback[key];
  739. });
  740. window[names[0]][names[1]] = newCallback; // Override the JSONP callback
  741. }
  742. }
  743. }
  744. // Insert the element into the dom, regardless of whether it was being inserted by Google.
  745. return originalMethod.apply(this, arguments);
  746. };
  747. /* eslint-enable func-names, prefer-rest-params */
  748. }
  749.  
  750. #removeJsonpInterceptor() {
  751. $('head')[0].appendChild = this.#originalHeadAppendChildMethod;
  752. }
  753.  
  754. /* eslint-disable */ // Disabling eslint since this is copied code.
  755. #initLZString() {
  756. // LZ Compressor
  757. // Copyright (c) 2013 Pieroxy <pieroxy@pieroxy.net>
  758. // This work is free. You can redistribute it and/or modify it
  759. // under the terms of the WTFPL, Version 2
  760. // LZ-based compression algorithm, version 1.4.4
  761. this.#lzString = (function () {
  762. // private property
  763. const f = String.fromCharCode;
  764. const keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  765. const keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
  766. const baseReverseDic = {};
  767.  
  768. function getBaseValue(alphabet, character) {
  769. if (!baseReverseDic[alphabet]) {
  770. baseReverseDic[alphabet] = {};
  771. for (let i = 0; i < alphabet.length; i++) {
  772. baseReverseDic[alphabet][alphabet.charAt(i)] = i;
  773. }
  774. }
  775. return baseReverseDic[alphabet][character];
  776. }
  777. var LZString = {
  778. compressToBase64: function (input) {
  779. if (input === null) return "";
  780. const res = LZString._compress(input, 6, function (a) {
  781. return keyStrBase64.charAt(a);
  782. });
  783. switch (res.length % 4) { // To produce valid Base64
  784. default: // When could this happen ?
  785. case 0:
  786. return res;
  787. case 1:
  788. return res + "===";
  789. case 2:
  790. return res + "==";
  791. case 3:
  792. return res + "=";
  793. }
  794. },
  795. decompressFromBase64: function (input) {
  796. if (input === null) return "";
  797. if (input === "") return null;
  798. return LZString._decompress(input.length, 32, function (index) {
  799. return getBaseValue(keyStrBase64, input.charAt(index));
  800. });
  801. },
  802. compressToUTF16: function (input) {
  803. if (input === null) return "";
  804. return LZString._compress(input, 15, function (a) {
  805. return f(a + 32);
  806. }) + " ";
  807. },
  808. decompressFromUTF16: function (compressed) {
  809. if (compressed === null) return "";
  810. if (compressed === "") return null;
  811. return LZString._decompress(compressed.length, 16384, function (index) {
  812. return compressed.charCodeAt(index) - 32;
  813. });
  814. },
  815.  
  816. compress: function (uncompressed) {
  817. return LZString._compress(uncompressed, 16, function (a) {
  818. return f(a);
  819. });
  820. },
  821. _compress: function (uncompressed, bitsPerChar, getCharFromInt) {
  822. if (uncompressed === null) return "";
  823. let i, value,
  824. context_dictionary = {},
  825. context_dictionaryToCreate = {},
  826. context_c = "",
  827. context_wc = "",
  828. context_w = "",
  829. context_enlargeIn = 2, // Compensate for the first entry which should not count
  830. context_dictSize = 3,
  831. context_numBits = 2,
  832. context_data = [],
  833. context_data_val = 0,
  834. context_data_position = 0,
  835. ii;
  836. for (ii = 0; ii < uncompressed.length; ii += 1) {
  837. context_c = uncompressed.charAt(ii);
  838. if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
  839. context_dictionary[context_c] = context_dictSize++;
  840. context_dictionaryToCreate[context_c] = true;
  841. }
  842. context_wc = context_w + context_c;
  843. if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) {
  844. context_w = context_wc;
  845. } else {
  846. if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
  847. if (context_w.charCodeAt(0) < 256) {
  848. for (i = 0; i < context_numBits; i++) {
  849. context_data_val = (context_data_val << 1);
  850. if (context_data_position === bitsPerChar - 1) {
  851. context_data_position = 0;
  852. context_data.push(getCharFromInt(context_data_val));
  853. context_data_val = 0;
  854. } else {
  855. context_data_position++;
  856. }
  857. }
  858. value = context_w.charCodeAt(0);
  859. for (i = 0; i < 8; i++) {
  860. context_data_val = (context_data_val << 1) | (value & 1);
  861. if (context_data_position === bitsPerChar - 1) {
  862. context_data_position = 0;
  863. context_data.push(getCharFromInt(context_data_val));
  864. context_data_val = 0;
  865. } else {
  866. context_data_position++;
  867. }
  868. value = value >> 1;
  869. }
  870. } else {
  871. value = 1;
  872. for (i = 0; i < context_numBits; i++) {
  873. context_data_val = (context_data_val << 1) | value;
  874. if (context_data_position === bitsPerChar - 1) {
  875. context_data_position = 0;
  876. context_data.push(getCharFromInt(context_data_val));
  877. context_data_val = 0;
  878. } else {
  879. context_data_position++;
  880. }
  881. value = 0;
  882. }
  883. value = context_w.charCodeAt(0);
  884. for (i = 0; i < 16; i++) {
  885. context_data_val = (context_data_val << 1) | (value & 1);
  886. if (context_data_position === bitsPerChar - 1) {
  887. context_data_position = 0;
  888. context_data.push(getCharFromInt(context_data_val));
  889. context_data_val = 0;
  890. } else {
  891. context_data_position++;
  892. }
  893. value = value >> 1;
  894. }
  895. }
  896. context_enlargeIn--;
  897. if (context_enlargeIn === 0) {
  898. context_enlargeIn = Math.pow(2, context_numBits);
  899. context_numBits++;
  900. }
  901. delete context_dictionaryToCreate[context_w];
  902. } else {
  903. value = context_dictionary[context_w];
  904. for (i = 0; i < context_numBits; i++) {
  905. context_data_val = (context_data_val << 1) | (value & 1);
  906. if (context_data_position === bitsPerChar - 1) {
  907. context_data_position = 0;
  908. context_data.push(getCharFromInt(context_data_val));
  909. context_data_val = 0;
  910. } else {
  911. context_data_position++;
  912. }
  913. value = value >> 1;
  914. }
  915. }
  916. context_enlargeIn--;
  917. if (context_enlargeIn === 0) {
  918. context_enlargeIn = Math.pow(2, context_numBits);
  919. context_numBits++;
  920. }
  921. // Add wc to the dictionary.
  922. context_dictionary[context_wc] = context_dictSize++;
  923. context_w = String(context_c);
  924. }
  925. }
  926. // Output the code for w.
  927. if (context_w !== "") {
  928. if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
  929. if (context_w.charCodeAt(0) < 256) {
  930. for (i = 0; i < context_numBits; i++) {
  931. context_data_val = (context_data_val << 1);
  932. if (context_data_position === bitsPerChar - 1) {
  933. context_data_position = 0;
  934. context_data.push(getCharFromInt(context_data_val));
  935. context_data_val = 0;
  936. } else {
  937. context_data_position++;
  938. }
  939. }
  940. value = context_w.charCodeAt(0);
  941. for (i = 0; i < 8; i++) {
  942. context_data_val = (context_data_val << 1) | (value & 1);
  943. if (context_data_position === bitsPerChar - 1) {
  944. context_data_position = 0;
  945. context_data.push(getCharFromInt(context_data_val));
  946. context_data_val = 0;
  947. } else {
  948. context_data_position++;
  949. }
  950. value = value >> 1;
  951. }
  952. } else {
  953. value = 1;
  954. for (i = 0; i < context_numBits; i++) {
  955. context_data_val = (context_data_val << 1) | value;
  956. if (context_data_position === bitsPerChar - 1) {
  957. context_data_position = 0;
  958. context_data.push(getCharFromInt(context_data_val));
  959. context_data_val = 0;
  960. } else {
  961. context_data_position++;
  962. }
  963. value = 0;
  964. }
  965. value = context_w.charCodeAt(0);
  966. for (i = 0; i < 16; i++) {
  967. context_data_val = (context_data_val << 1) | (value & 1);
  968. if (context_data_position === bitsPerChar - 1) {
  969. context_data_position = 0;
  970. context_data.push(getCharFromInt(context_data_val));
  971. context_data_val = 0;
  972. } else {
  973. context_data_position++;
  974. }
  975. value = value >> 1;
  976. }
  977. }
  978. context_enlargeIn--;
  979. if (context_enlargeIn === 0) {
  980. context_enlargeIn = Math.pow(2, context_numBits);
  981. context_numBits++;
  982. }
  983. delete context_dictionaryToCreate[context_w];
  984. } else {
  985. value = context_dictionary[context_w];
  986. for (i = 0; i < context_numBits; i++) {
  987. context_data_val = (context_data_val << 1) | (value & 1);
  988. if (context_data_position === bitsPerChar - 1) {
  989. context_data_position = 0;
  990. context_data.push(getCharFromInt(context_data_val));
  991. context_data_val = 0;
  992. } else {
  993. context_data_position++;
  994. }
  995. value = value >> 1;
  996. }
  997. }
  998. context_enlargeIn--;
  999. if (context_enlargeIn === 0) {
  1000. context_enlargeIn = Math.pow(2, context_numBits);
  1001. context_numBits++;
  1002. }
  1003. }
  1004. // Mark the end of the stream
  1005. value = 2;
  1006. for (i = 0; i < context_numBits; i++) {
  1007. context_data_val = (context_data_val << 1) | (value & 1);
  1008. if (context_data_position === bitsPerChar - 1) {
  1009. context_data_position = 0;
  1010. context_data.push(getCharFromInt(context_data_val));
  1011. context_data_val = 0;
  1012. } else {
  1013. context_data_position++;
  1014. }
  1015. value = value >> 1;
  1016. }
  1017. // Flush the last char
  1018. while (true) {
  1019. context_data_val = (context_data_val << 1);
  1020. if (context_data_position === bitsPerChar - 1) {
  1021. context_data.push(getCharFromInt(context_data_val));
  1022. break;
  1023. } else context_data_position++;
  1024. }
  1025. return context_data.join('');
  1026. },
  1027. decompress: function (compressed) {
  1028. if (compressed === null) return "";
  1029. if (compressed === "") return null;
  1030. return LZString._decompress(compressed.length, 32768, function (index) {
  1031. return compressed.charCodeAt(index);
  1032. });
  1033. },
  1034. _decompress: function (length, resetValue, getNextValue) {
  1035. let dictionary = [],
  1036. next,
  1037. enlargeIn = 4,
  1038. dictSize = 4,
  1039. numBits = 3,
  1040. entry = "",
  1041. result = [],
  1042. i,
  1043. w,
  1044. bits, resb, maxpower, power,
  1045. c,
  1046. data = {
  1047. val: getNextValue(0),
  1048. position: resetValue,
  1049. index: 1
  1050. };
  1051. for (i = 0; i < 3; i += 1) {
  1052. dictionary[i] = i;
  1053. }
  1054. bits = 0;
  1055. maxpower = Math.pow(2, 2);
  1056. power = 1;
  1057. while (power !== maxpower) {
  1058. resb = data.val & data.position;
  1059. data.position >>= 1;
  1060. if (data.position === 0) {
  1061. data.position = resetValue;
  1062. data.val = getNextValue(data.index++);
  1063. }
  1064. bits |= (resb > 0 ? 1 : 0) * power;
  1065. power <<= 1;
  1066. }
  1067. switch (next = bits) {
  1068. case 0:
  1069. bits = 0;
  1070. maxpower = Math.pow(2, 8);
  1071. power = 1;
  1072. while (power !== maxpower) {
  1073. resb = data.val & data.position;
  1074. data.position >>= 1;
  1075. if (data.position === 0) {
  1076. data.position = resetValue;
  1077. data.val = getNextValue(data.index++);
  1078. }
  1079. bits |= (resb > 0 ? 1 : 0) * power;
  1080. power <<= 1;
  1081. }
  1082. c = f(bits);
  1083. break;
  1084. case 1:
  1085. bits = 0;
  1086. maxpower = Math.pow(2, 16);
  1087. power = 1;
  1088. while (power !== maxpower) {
  1089. resb = data.val & data.position;
  1090. data.position >>= 1;
  1091. if (data.position === 0) {
  1092. data.position = resetValue;
  1093. data.val = getNextValue(data.index++);
  1094. }
  1095. bits |= (resb > 0 ? 1 : 0) * power;
  1096. power <<= 1;
  1097. }
  1098. c = f(bits);
  1099. break;
  1100. case 2:
  1101. return "";
  1102. }
  1103. dictionary[3] = c;
  1104. w = c;
  1105. result.push(c);
  1106. while (true) {
  1107. if (data.index > length) {
  1108. return "";
  1109. }
  1110. bits = 0;
  1111. maxpower = Math.pow(2, numBits);
  1112. power = 1;
  1113. while (power !== maxpower) {
  1114. resb = data.val & data.position;
  1115. data.position >>= 1;
  1116. if (data.position === 0) {
  1117. data.position = resetValue;
  1118. data.val = getNextValue(data.index++);
  1119. }
  1120. bits |= (resb > 0 ? 1 : 0) * power;
  1121. power <<= 1;
  1122. }
  1123. switch (c = bits) {
  1124. case 0:
  1125. bits = 0;
  1126. maxpower = Math.pow(2, 8);
  1127. power = 1;
  1128. while (power !== maxpower) {
  1129. resb = data.val & data.position;
  1130. data.position >>= 1;
  1131. if (data.position === 0) {
  1132. data.position = resetValue;
  1133. data.val = getNextValue(data.index++);
  1134. }
  1135. bits |= (resb > 0 ? 1 : 0) * power;
  1136. power <<= 1;
  1137. }
  1138. dictionary[dictSize++] = f(bits);
  1139. c = dictSize - 1;
  1140. enlargeIn--;
  1141. break;
  1142. case 1:
  1143. bits = 0;
  1144. maxpower = Math.pow(2, 16);
  1145. power = 1;
  1146. while (power !== maxpower) {
  1147. resb = data.val & data.position;
  1148. data.position >>= 1;
  1149. if (data.position === 0) {
  1150. data.position = resetValue;
  1151. data.val = getNextValue(data.index++);
  1152. }
  1153. bits |= (resb > 0 ? 1 : 0) * power;
  1154. power <<= 1;
  1155. }
  1156. dictionary[dictSize++] = f(bits);
  1157. c = dictSize - 1;
  1158. enlargeIn--;
  1159. break;
  1160. case 2:
  1161. return result.join('');
  1162. }
  1163. if (enlargeIn === 0) {
  1164. enlargeIn = Math.pow(2, numBits);
  1165. numBits++;
  1166. }
  1167. if (dictionary[c]) {
  1168. entry = dictionary[c];
  1169. } else {
  1170. if (c === dictSize) {
  1171. entry = w + w.charAt(0);
  1172. } else {
  1173. return null;
  1174. }
  1175. }
  1176. result.push(entry);
  1177. // Add w+entry[0] to the dictionary.
  1178. dictionary[dictSize++] = w + entry.charAt(0);
  1179. enlargeIn--;
  1180. w = entry;
  1181. if (enlargeIn === 0) {
  1182. enlargeIn = Math.pow(2, numBits);
  1183. numBits++;
  1184. }
  1185. }
  1186. }
  1187. };
  1188. return LZString;
  1189. })();
  1190. }
  1191. /* eslint-enable */
  1192. }