WME LevelReset

Script version of the WME LevelReset tool, to make relocking segments to their appropriate lock level easy & quick.

目前为 2015-12-02 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/14414/91193/WME%20LevelReset.js

  1. // ==UserScript==
  2. // @name WME LevelReset
  3. // @namespace broosgert@gmail.com
  4. // @version 0.1
  5. // @description Script version of the WME LevelReset tool, to make relocking segments to their appropriate lock level easy & quick.
  6. // @author Broos Gert '2015
  7. // @match https://editor-beta.waze.com/*editor/*
  8. // @match https://www.waze.com/*editor/*
  9. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAA+VBMVEX///93PgHX19fTgQfFZgLLcwTrxYDDgA3nqBj5+fmwr6+Yl5f8/PzExMTl5eX114vv7+/e3t68vLzOzs6saRKARQSLTgeioqK2tbX72XfU1NT515fxz4b54b3RmySYWAv31aTpwIHgrn9/f3/75qPZsEvuuC/utx3psVP13KizbhXuuVj745bfoEzzwzDxwDXTjknpxqDPfhzWih7PhUaObErowqDJchrmqCfprRjbmUvblCLZjAv71WnhnyTfmA7hrmbjsm7qxpPv06vYljj305776MvLkD3XkjFwcHCMi4v6zk/6z1P2wVDYqzr3y3j2xWnrrl761X3u0VhGAAABv0lEQVQ4jZWTXXuaMBiGY7bZQUhIoBaKsIK0KkVqtd+2tJ2gnVJs9f//mAW78uHYwe6TXE+em/flJAD8D0RVdF3HTKqvGcaMAiAQVYd1vaEASikhhFKA1ZoeA8Iwct2lCAnAxl/zdcAMbeGipbtwMQM62xFEFUJtoWEIsbh0CVTF3QGqqrjax2cq4kkkFQFjTJD2eYeXBoa4uoEoBOU/RhBUWHWHJukUCZ9JQFCnWkVAQJRQniREyvGPANA/YzazRhBKwjSOg+DZmdoRZ+r8XAfxr5eo1AfzuW1HljXfYkX2zJ5b8TQXXtbWzPff38x2hvn27qf+zFrHubC39tppGoabjczZHIZpmra9/jgXTn2vnSTJaxgecsLwNRkmsueflgV5eLZarU4y+Lk6G9YIg8HxB4PBYEfY3woZQ0529rjQ3y+Evid3ez9K9LpmWTjqe2b3Ti5xlwlHhRDYzdvvFW5NOyiEAy48Pu2VeHps2sFBIUwi5/6hWeLh3okmhdCajJyLLxUunNGktS0lgdLW+agz/lZh3Bmdt6ggZS/NUBqX152brxVuOteXDZVRafsUrxq1XGHIBb6CwHoY4Tt+A1eiQ8S/AAv7AAAAAElFTkSuQmCC
  10. // @grant GM_info
  11. // @license MIT/BSD/X11
  12. // ==/UserScript==
  13. // initialize LevelReset and do some checks
  14. function LevelReset_bootstrap() {
  15. LevelReset_init();
  16. }
  17.  
  18. function LevelReset_init() {
  19. // Check initialisation
  20. if (typeof Waze == 'undefined' || typeof I18n == 'undefined') {
  21. setTimeout(LevelReset_init, 660);
  22. console.log('LevelReset: Waze object unavailable, map still loading');
  23. return;
  24. }
  25.  
  26. console.log('LevelReset: Waze - ', Waze);
  27.  
  28. function onScreen(obj) {
  29. if (obj.geometry) {
  30. return(Waze.map.getExtent().intersectsBounds(obj.geometry.getBounds()));
  31. }
  32. return(false);
  33. }
  34.  
  35. var UpdateObject = require("Waze/Action/UpdateObject"),
  36. strt = '',
  37. fwy_lvl = 5,
  38. rmp_lvl = 4,
  39. maj_lvl = 3,
  40. min_lvl = 2,
  41. pri_lvl = 1,
  42. absolute = false,
  43. fwy_cnt = 0,
  44. rmp_cnt = 0,
  45. maj_cnt = 0,
  46. min_cnt = 0,
  47. pri_cnt = 0,
  48. userlevel = Waze.loginManager.user.normalizedLevel,
  49. relockTab = document.createElement('li'),
  50. userInfo = document.getElementById('user-info'),
  51. navTabs = userInfo.querySelector('.nav-tabs'),
  52. tabContent = userInfo.querySelector('.tab-content'),
  53. relockContent = document.createElement('div'),
  54. relockTitle = document.createElement('h4'),
  55. relockSubTitle = document.createElement('h4'),
  56. relockScanbutton = document.createElement('input'),
  57. relockAllbutton = document.createElement('input'),
  58. relockSub = document.createElement('p'),
  59. resultsCntr = document.createElement('div'),
  60. warningCntr = document.createElement('div'),
  61. readable = {'pri':'Primary Streets (L2)','min':'Minor Highways (L3)', 'maj':'Major Highways (L4)', 'rmp':'Ramps (L5)', 'fwy':'Freeways (L6)'};
  62.  
  63. // Begin building
  64. relockContent.id = 'sidepanel-relockTab';
  65. relockContent.className = 'tab-pane';
  66. relockTitle.appendChild(document.createTextNode('Relock segments'));
  67. relockTitle.style.marginBottom = '5px';
  68. relockContent.appendChild(relockTitle);
  69. relockTab.innerHTML = '<a href="#sidepanel-relockTab" data-toggle="tab" title="Relock segments">Re - <span class="icon-lock" id="lockcolor" style="color:green"></span></a>';
  70.  
  71. // fill tab
  72. relockSub.innerHTML = 'Your on-screen area is automatically scanned when you load or pan around. Pressing the lock behind each type will relock only those results, or you can choose to relock all.<br/><br/>You can only relock segments lower or equal to your current editor level.';
  73. relockSub.style.cssText = 'font-size:85%';
  74. relockSubTitle.innerHTML = 'Results';
  75. relockScanbutton.type = 'button';
  76. relockScanbutton.value = 'Rescan area';
  77. relockScanbutton.style.cssText = 'margin: 10px 3px 0 0';
  78. relockScanbutton.onclick = function() {
  79. scanArea();
  80. };
  81. relockAllbutton.type = 'button';
  82. relockAllbutton.value = 'Relock All';
  83. relockAllbutton.style.cssText = 'margin: 10px 3px 0 5px';
  84. relockAllbutton.onclick = function() {
  85. relockAll();
  86. };
  87.  
  88. // Remember to save
  89. warningCntr.style.cssText = 'margin-top:15px;border:1px solid #FFBB00;background:#FFE599;color:#664C00;border-radius:5px;padding:10px 5px;text-align:center;font-weight:bold;display:none';
  90. warningCntr.innerHTML = 'Remember to save these changes!';
  91. warningCntr.id = 'warningCntr';
  92.  
  93. // add to stage
  94. navTabs.appendChild(relockTab);
  95. tabContent.appendChild(relockContent);
  96. relockContent.appendChild(relockSub);
  97. relockContent.appendChild(relockSubTitle);
  98. relockContent.appendChild(resultsCntr);
  99. relockContent.appendChild(relockScanbutton);
  100. relockContent.appendChild(relockAllbutton);
  101. relockContent.appendChild(warningCntr);
  102.  
  103. // Some functions
  104. function relock(obj, key) {
  105. $.each(obj[key], function( id, value ) {
  106. Waze.model.actionManager.add(value);
  107. });
  108. scanArea();
  109. $('#warningCntr:hidden').fadeIn('fast');
  110. }
  111.  
  112. function relockAll() {
  113. $('#warningCntr:hidden').fadeIn('fast');
  114. }
  115.  
  116. function scanArea() {
  117. // Object with array of roadtypes, to collect each wrongly locked segment, for later use
  118. var relockObject = {'pri':[], 'min':[], 'maj':[], 'rmp':[], 'fwy':[]};
  119. var foundBadlocks = false;
  120. var count = 0;
  121.  
  122. // Do a count on how many segments are in need of a correct lock (limit to 150 to save CPU)
  123. // Count also depends on the users editor level
  124. Object.forEach(Waze.model.segments.objects, function(k, v) {
  125. if (count < 150 && v.type == "segment" && onScreen(v) && v.isGeometryEditable()) {
  126. // Primary (Lock 2)
  127. if (v.attributes.roadType == 2 && (v.attributes.lockRank < pri_lvl || (absolute && v.attributes.lockRank != pri_lvl))) {
  128. strt = Waze.model.streets.get(v.attributes.primaryStreetID);
  129. relockObject.pri.push(new UpdateObject(v, {lockRank: pri_lvl}));
  130. count++;
  131. foundBadlocks = true;
  132. }
  133. // Minor Highway
  134. if (v.attributes.roadType == 7 && (v.attributes.lockRank < min_lvl || (absolute && v.attributes.lockRank != min_lvl))) {
  135. strt = Waze.model.streets.get(v.attributes.primaryStreetID);
  136. relockObject.min.push(new UpdateObject(v, {lockRank: min_lvl}));
  137. count++;
  138. foundBadlocks = true;
  139. }
  140. // Major Highway
  141. if (v.attributes.roadType == 6 && (v.attributes.lockRank < maj_lvl || (absolute && v.attributes.lockRank != maj_lvl))) {
  142. strt = Waze.model.streets.get(v.attributes.primaryStreetID);
  143. relockObject.maj.push(new UpdateObject(v, {lockRank: maj_lvl}));
  144. count++;
  145. foundBadlocks = true;
  146. }
  147. // Ramps
  148. if (v.attributes.roadType == 4 && (v.attributes.lockRank < rmp_lvl || (absolute && v.attributes.lockRank != rmp_lvl))) {
  149. strt = Waze.model.streets.get(v.attributes.primaryStreetID);
  150. relockObject.rmp.push(new UpdateObject(v, {lockRank: rmp_lvl}));
  151. count++;
  152. foundBadlocks = true;
  153. }
  154. // Freeways
  155. if (v.attributes.roadType == 3 && (v.attributes.lockRank < fwy_lvl || (absolute && v.attributes.lockRank != fwy_lvl))) {
  156. strt = Waze.model.streets.get(v.attributes.primaryStreetID);
  157. relockObject.fwy.push(new UpdateObject(v, {lockRank: fwy_lvl}));
  158. count++;
  159. foundBadlocks = true;
  160. }
  161. }
  162. });
  163.  
  164. // Build result to users tabpanel
  165. resultsCntr.innerHTML = '';
  166. var lvlCnt = 2; // start at 2 (pri)
  167.  
  168. $.each(relockObject, function( key, value ) {
  169. var __cntr = document.createElement('div'),
  170. __keyLeft = document.createElement('div'),
  171. __lckRight = document.createElement('div'),
  172. __cntRight = document.createElement('div'),
  173. __cleardiv = document.createElement("div");
  174.  
  175. // Begin building
  176. __keyLeft.style.cssText = 'float:left';
  177. __keyLeft.innerHTML = readable[key];
  178. __lckRight.className = ((value.length !==0) ? 'icon-lock' : '');
  179. __cntRight.style.cssText = 'float:right';
  180. __cntRight.innerHTML = ((value.length !==0) ? '<b>'+value.length+'</b>' : '-');
  181. __cleardiv.style.cssText ='clear:both;';
  182.  
  183. // only add relock function if the editor's level allows it...
  184. if (userlevel >= lvlCnt) {
  185. __lckRight.style.cssText = 'width:15px;float:right;padding:3px 0 0 8px;cursor:pointer;' + ((value.length!== 0) ? 'color:red' : '' );
  186. __lckRight.onclick = function() {
  187. relock(relockObject, key);
  188. };
  189. } else {
  190. // Grey out options to make it more visible
  191. __lckRight.className = '';
  192. __keyLeft.style.cssText = 'float:left;color:#777';
  193. __cntRight.style.cssText = 'float:right;color:#777';
  194. __lckRight.style.cssText = 'float:right;padding:3px 0 0 8px;color:#777;width:15px';
  195. }
  196.  
  197. // Add to stage
  198. __cntr.appendChild(__keyLeft);
  199. __cntr.appendChild(__lckRight);
  200. __cntr.appendChild(__cntRight);
  201. __cntr.appendChild(__cleardiv);
  202. resultsCntr.appendChild(__cntr);
  203. lvlCnt++;
  204. });
  205.  
  206. // Color the small lock icon red, if errors are found, so people can decide what to do...
  207. if (foundBadlocks)
  208. $('#lockcolor').css('color', 'red');
  209. else
  210. $('#lockcolor').css('color', 'green');
  211. }
  212.  
  213. // Do a default scan once at startup
  214. scanArea();
  215.  
  216. // Register some eventlisteners
  217. Waze.map.events.register("moveend", null, scanArea);
  218. Waze.model.actionManager.events.register("afteraction", null, scanArea);
  219. Waze.model.actionManager.events.register("afterundoaction", null, scanArea);
  220. Waze.model.actionManager.events.register("noActions", null, scanArea);
  221. }
  222. setTimeout(LevelReset_bootstrap, 3000);