Greasy Fork 还支持 简体中文。

WME Fix Map Object

Temporary fix for the changes made in the WME internal data structure that breaks any script that interacts with the map

目前為 2019-12-04 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name WME Fix Map Object
  3. // @namespace http://www.tomputtemans.com/
  4. // @description Temporary fix for the changes made in the WME internal data structure that breaks any script that interacts with the map
  5. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
  6. // @version 1.0.0
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. /* global W */
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. var recoveredProperties = new Map();
  16.  
  17. function init() {
  18. if (typeof W === 'undefined' ||
  19. typeof W.map === 'undefined' ||
  20. typeof W.map.olMap === 'undefined') {
  21. setTimeout(init, 100);
  22. return;
  23. }
  24. W.map = new Proxy(W.map, {
  25. 'get': function(target, property) {
  26. checkProperty(property);
  27. return Reflect.get(...arguments);
  28. }
  29. });
  30. recoverProperties();
  31. console.log("Fix Map Object: The following properties have been recovered: ", Array.from(recoveredProperties.keys()).sort());
  32. }
  33. init();
  34.  
  35. function recoverProperties() {
  36. // Go through all properties, including the prototype chain
  37. for (var mapProperty in W.map.getOLMap()) {
  38. if (!W.map[mapProperty]) {
  39. recoveredProperties.set(mapProperty, 0);
  40. W.map[mapProperty] = W.map.getOLMap()[mapProperty];
  41. }
  42. }
  43. }
  44.  
  45. function checkProperty(propertyName) {
  46. if (recoveredProperties.has(propertyName)) {
  47. var timesCalled = recoveredProperties.get(propertyName);
  48. if (timesCalled >= 10) {
  49. return;
  50. }
  51. console.groupCollapsed("Fix Map Object: Removed property W.map." + propertyName + " accessed. Expand for stack trace.");
  52. console.trace();
  53. console.groupEnd();
  54. if (timesCalled == 9) {
  55. console.warn("Fix Map Object: No longer reporting on removed property W.map." + propertyName + " (limit reached)");
  56. }
  57. recoveredProperties.set(propertyName, timesCalled + 1);
  58. }
  59. }
  60. })();