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/91211/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 none
  11. // ==/UserScript==
  12.  
  13.  
  14. // initialize LevelReset and do some checks
  15. function LevelReset_bootstrap() {
  16. LevelReset_init();
  17. }
  18.  
  19. function LevelReset_init() {
  20. // Check initialisation
  21. if (typeof Waze == 'undefined' || typeof I18n == 'undefined') {
  22. setTimeout(LevelReset_init, 660);
  23. console.log('LevelReset: Waze object unavailable, map still loading');
  24. return;
  25. }
  26.  
  27. //console.log('LevelReset: Waze - ', Waze);
  28.  
  29. function onScreen(obj) {
  30. if (obj.geometry) {
  31. return(Waze.map.getExtent().intersectsBounds(obj.geometry.getBounds()));
  32. }
  33. return(false);
  34. }
  35.  
  36. var UpdateObject = require("Waze/Action/UpdateObject"),
  37. strt = '',
  38. fwy_lvl = 5,
  39. rmp_lvl = 4,
  40. maj_lvl = 3,
  41. min_lvl = 2,
  42. pri_lvl = 1,
  43. absolute = false,
  44. fwy_cnt = 0,
  45. rmp_cnt = 0,
  46. maj_cnt = 0,
  47. min_cnt = 0,
  48. pri_cnt = 0,
  49. relockObject = null,
  50. userlevel = Waze.loginManager.user.normalizedLevel,
  51. relockTab = document.createElement('li'),
  52. userInfo = document.getElementById('user-info'),
  53. navTabs = userInfo.querySelector('.nav-tabs'),
  54. tabContent = userInfo.querySelector('.tab-content'),
  55. relockContent = document.createElement('div'),
  56. relockTitle = document.createElement('h4'),
  57. relockSubTitle = document.createElement('h4'),
  58. relockScanbutton = document.createElement('input'),
  59. relockAllbutton = document.createElement('input'),
  60. relockSub = document.createElement('p'),
  61. resultsCntr = document.createElement('div'),
  62. warningCntr = document.createElement('div'),
  63. readable = {'pri':'Primary Streets (L2)','min':'Minor Highways (L3)', 'maj':'Major Highways (L4)', 'rmp':'Ramps (L5)', 'fwy':'Freeways (L6)'};
  64.  
  65. // Begin building
  66. relockContent.id = 'sidepanel-relockTab';
  67. relockContent.className = 'tab-pane';
  68. relockTitle.appendChild(document.createTextNode('Relock segments'));
  69. relockTitle.style.marginBottom = '5px';
  70. relockContent.appendChild(relockTitle);
  71. relockTab.innerHTML = '<a href="#sidepanel-relockTab" data-toggle="tab" title="Relock segments">Re - <span class="icon-lock" id="lockcolor" style="color:green"></span></a>';
  72.  
  73. // fill tab
  74. 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.';
  75. relockSub.style.cssText = 'font-size:85%';
  76. relockSubTitle.innerHTML = 'Results';
  77. relockScanbutton.type = 'button';
  78. relockScanbutton.value = 'Rescan area';
  79. relockScanbutton.style.cssText = 'margin: 10px 3px 0 0';
  80. relockScanbutton.onclick = function() {
  81. scanArea();
  82. };
  83. relockAllbutton.type = 'button';
  84. relockAllbutton.value = 'Relock All';
  85. relockAllbutton.style.cssText = 'margin: 10px 3px 0 5px';
  86. relockAllbutton.onclick = function() {
  87. relockAll();
  88. };
  89.  
  90. // Remember to save
  91. 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';
  92. warningCntr.innerHTML = 'Remember to save these changes!';
  93. warningCntr.id = 'warningCntr';
  94.  
  95. // add to stage
  96. navTabs.appendChild(relockTab);
  97. tabContent.appendChild(relockContent);
  98. relockContent.appendChild(relockSub);
  99. relockContent.appendChild(relockSubTitle);
  100. relockContent.appendChild(resultsCntr);
  101. relockContent.appendChild(relockScanbutton);
  102. relockContent.appendChild(relockAllbutton);
  103. relockContent.appendChild(warningCntr);
  104.  
  105. // Some functions
  106. function relock(obj, key) {
  107. $.each(obj[key], function( id, value ) {
  108. Waze.model.actionManager.add(value);
  109. });
  110. $('#warningCntr:hidden').fadeIn('fast');
  111. scanArea();
  112. }
  113.  
  114. function relockAll() {
  115. // only lock "all" until the current editors level is reached, then stop...
  116. var lvlCnt = 2;
  117.  
  118. $.each(relockObject, function( key, value ) {
  119. // Check for value length & user level
  120. if(value.length !== 0 && userlevel >= lvlCnt) {
  121. // loop trough each segment (updateObject)
  122. $.each(value, function( id, obj ) {
  123. Waze.model.actionManager.add(obj);
  124. });
  125. }
  126. lvlCnt++;
  127. });
  128. $('#warningCntr:hidden').fadeIn('fast');
  129. scanArea();
  130. }
  131.  
  132. function scanArea() {
  133. // Object with array of roadtypes, to collect each wrongly locked segment, for later use
  134. relockObject = {'pri':[], 'min':[], 'maj':[], 'rmp':[], 'fwy':[]};
  135. var foundBadlocks = false;
  136. var count = 0;
  137.  
  138. // Do a count on how many segments are in need of a correct lock (limit to 150 to save CPU)
  139. // Count also depends on the users editor level
  140. Object.forEach(Waze.model.segments.objects, function(k, v) {
  141. if (count < 150 && v.type == "segment" && onScreen(v) && v.isGeometryEditable()) {
  142. // Primary (Lock 2)
  143. if (v.attributes.roadType == 2 && (v.attributes.lockRank < pri_lvl || (absolute && v.attributes.lockRank != pri_lvl))) {
  144. strt = Waze.model.streets.get(v.attributes.primaryStreetID);
  145. relockObject.pri.push(new UpdateObject(v, {lockRank: pri_lvl}));
  146. count++;
  147. foundBadlocks = true;
  148. }
  149. // Minor Highway
  150. if (v.attributes.roadType == 7 && (v.attributes.lockRank < min_lvl || (absolute && v.attributes.lockRank != min_lvl))) {
  151. strt = Waze.model.streets.get(v.attributes.primaryStreetID);
  152. relockObject.min.push(new UpdateObject(v, {lockRank: min_lvl}));
  153. count++;
  154. foundBadlocks = true;
  155. }
  156. // Major Highway
  157. if (v.attributes.roadType == 6 && (v.attributes.lockRank < maj_lvl || (absolute && v.attributes.lockRank != maj_lvl))) {
  158. strt = Waze.model.streets.get(v.attributes.primaryStreetID);
  159. relockObject.maj.push(new UpdateObject(v, {lockRank: maj_lvl}));
  160. count++;
  161. foundBadlocks = true;
  162. }
  163. // Ramps
  164. if (v.attributes.roadType == 4 && (v.attributes.lockRank < rmp_lvl || (absolute && v.attributes.lockRank != rmp_lvl))) {
  165. strt = Waze.model.streets.get(v.attributes.primaryStreetID);
  166. relockObject.rmp.push(new UpdateObject(v, {lockRank: rmp_lvl}));
  167. count++;
  168. foundBadlocks = true;
  169. }
  170. // Freeways
  171. if (v.attributes.roadType == 3 && (v.attributes.lockRank < fwy_lvl || (absolute && v.attributes.lockRank != fwy_lvl))) {
  172. strt = Waze.model.streets.get(v.attributes.primaryStreetID);
  173. relockObject.fwy.push(new UpdateObject(v, {lockRank: fwy_lvl}));
  174. count++;
  175. foundBadlocks = true;
  176. }
  177. }
  178. });
  179.  
  180. // Build result to users tabpanel
  181. resultsCntr.innerHTML = '';
  182. var lvlCnt = 2; // start at 2 (pri) because we can't lock lower then 1 :-)
  183.  
  184. $.each(relockObject, function( key, value ) {
  185. var __cntr = document.createElement('div'),
  186. __keyLeft = document.createElement('div'),
  187. __lckRight = document.createElement('div'),
  188. __cntRight = document.createElement('div'),
  189. __cleardiv = document.createElement("div");
  190.  
  191. // Begin building
  192. __keyLeft.style.cssText = 'float:left';
  193. __keyLeft.innerHTML = readable[key];
  194. __lckRight.className = ((value.length !==0) ? 'icon-lock' : '');
  195. __cntRight.style.cssText = 'float:right';
  196. __cntRight.innerHTML = ((value.length !==0) ? '<b>'+value.length+'</b>' : '-');
  197. __cleardiv.style.cssText ='clear:both;';
  198.  
  199. // only add relock function if the editor's level allows it...
  200. if (userlevel >= lvlCnt) {
  201. __lckRight.style.cssText = 'width:15px;float:right;padding:3px 0 0 8px;cursor:pointer;' + ((value.length!== 0) ? 'color:red' : '' );
  202. __lckRight.onclick = function() {
  203. relock(relockObject, key);
  204. };
  205. } else {
  206. // Grey out options to make it more visible
  207. __lckRight.className = '';
  208. __keyLeft.style.cssText = 'float:left;color:#777';
  209. __cntRight.style.cssText = 'float:right;color:#777';
  210. __lckRight.style.cssText = 'float:right;padding:3px 0 0 8px;color:#777;width:15px';
  211. }
  212.  
  213. // Add to stage
  214. __cntr.appendChild(__keyLeft);
  215. __cntr.appendChild(__lckRight);
  216. __cntr.appendChild(__cntRight);
  217. __cntr.appendChild(__cleardiv);
  218. resultsCntr.appendChild(__cntr);
  219. lvlCnt++;
  220. });
  221.  
  222. // Color the small lock icon red, if errors are found, so people can decide what to do...
  223. if (foundBadlocks)
  224. $('#lockcolor').css('color', 'red');
  225. else
  226. $('#lockcolor').css('color', 'green');
  227. }
  228.  
  229. // Do a default scan once at startup
  230. scanArea();
  231.  
  232. // Register some eventlisteners
  233. Waze.map.events.register("moveend", null, scanArea);
  234. Waze.model.actionManager.events.register("afteraction", null, scanArea);
  235. Waze.model.actionManager.events.register("afterundoaction", null, scanArea);
  236. Waze.model.actionManager.events.register("noActions", null, scanArea);
  237. }
  238. setTimeout(LevelReset_bootstrap, 2000);