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/91276/WME%20LevelReset.js

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