WME HN Tool

Highlights un-nudged house numbers

当前为 2015-12-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WME HN Tool
  3. // @description Highlights un-nudged house numbers
  4. // @version 1.20.1
  5. // @author SAR85
  6. // @copyright SAR85
  7. // @license CC BY-NC-ND
  8. // @grant none
  9. // @include https://www.waze.com/editor/*
  10. // @include https://www.waze.com/*/editor/*
  11. // @include https://editor-beta.waze.com/*
  12. // @namespace https://greasyfork.org/users/9321
  13. // @require https://greasyfork.org/scripts/9794-wlib/code/wLib.js?version=76145
  14. // ==/UserScript==
  15.  
  16. /* global W */
  17. /* global wLib */
  18.  
  19. (function () {
  20. var hnMarkerLayer,
  21. messageBar;
  22. function highlightUntouched(retryCount) {
  23. 'use strict';
  24. var i, n, marker, hnMarkers;
  25. retryCount = retryCount || 0;
  26. hnMarkers = hnMarkerLayer.markers;
  27. if (hnMarkers.length === 0) {
  28. if (retryCount < 1000) {
  29. setTimeout(function () {
  30. highlightUntouched(++retryCount);
  31. }, 10);
  32. } else {
  33. console.debug('HN Tool: HN markers not found. Giving up.');
  34. return;
  35. }
  36. }
  37. for (i = 0, n = hnMarkers.length; i < n; i++) {
  38. marker = hnMarkers[i];
  39. if (marker.model && null === marker.model.updatedBy) {
  40. marker.icon.$div.find('.uneditable-number').css('background-color', '#FFAD85');
  41. marker.inputWrapper.css('background-color', '#FFAD85');
  42. }
  43. }
  44. }
  45. function checkForHNLayer() {
  46. 'use strict';
  47. var layers = W.map.getLayersByName('houseNumberMarkers');
  48. if (layers.length > 0) {
  49. hnMarkerLayer = layers[0];
  50. highlightUntouched();
  51. }
  52. }
  53. function updateAlert() {
  54. 'use strict';
  55. var hnVersion = '1.20.1',
  56. alertOnUpdate = true,
  57. versionChanges = 'WME Highlight HNs has been updated to ' + hnVersion + '.\n';
  58. versionChanges += 'Changes:\n';
  59. versionChanges += '[*]Highlighting is re-applied after editing HNs.\n';
  60. if (alertOnUpdate && window.localStorage && window.localStorage.hnVersion !== hnVersion) {
  61. window.localStorage.hnVersion = hnVersion;
  62. alert(versionChanges);
  63. }
  64. }
  65. function hnInit() {
  66. 'use strict';
  67. W.map.events.register('addlayer', this, checkForHNLayer);
  68. W.vent.on('operationDone', checkForHNLayer);
  69. messageBar = new wLib.Interface.MessageBar({
  70. messagePrefix: 'WME HN Tool:'
  71. });
  72. console.debug('HN Tool: Initialized.');
  73. updateAlert();
  74. }
  75. function hnBootstrap(count) {
  76. 'use strict';
  77. count = count || 0;
  78. if ('undefined' !== typeof wLib && 'undefined' !== typeof W &&
  79. 'undefined' !== typeof W.map && 'undefined' !== typeof W.map.events &&
  80. 'undefined' !== typeof W.map.events.register &&
  81. 'undefined' !== typeof W.vent &&
  82. 'undefined' !== typeof W.vent.on) {
  83. console.debug('HN Tool: Initializing...');
  84. window.setTimeout(hnInit, 100);
  85. } else if (count < 10) {
  86. console.debug('HN Tool: Bootstrap failed. Trying again...');
  87. window.setTimeout(function () {
  88. hnBootstrap(++count);
  89. }, 1000);
  90. } else {
  91. console.error('HN Tool: Bootstrap error.');
  92. }
  93. }
  94. console.debug('HN Tool: Bootstrap...');
  95. window.setTimeout(hnBootstrap, 100);
  96. } ());