WME Invalidated Camera Mass Eraser

Allow delete visible, unvalidated and in your managed area all speed camera in 1 click!

目前为 2014-10-04 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name WME Invalidated Camera Mass Eraser
  3. // @namespace @UCME_Myriades
  4. // @description Allow delete visible, unvalidated and in your managed area all speed camera in 1 click!
  5. // @include https://www.waze.com/editor/*
  6. // @include https://www.waze.com/*/editor/*
  7. // @icon
  8. // @version 0.5
  9. // @grant WME_GB_Myriades
  10. // ==/UserScript==
  11.  
  12. var wme_ucme_script_name = 'WME Unvalidated Camera Mass Eraser';
  13. wme_ucme_version = GM_info.script.version;
  14. var wme_ucme_script_url = 'https://greasyfork.org/scripts/2377-wme-invalidated-camera-mass-eraser';
  15.  
  16. /* bootstrap, will call initialiseHighlights() */
  17. function UCME_bootstrap(){
  18. UCME_addLog('init');
  19. if (typeof(unsafeWindow) === "undefined"){
  20. unsafeWindow = ( function () {
  21. var dummyElem = document.createElement('p');
  22. dummyElem.setAttribute('onclick', 'return window;');
  23. return dummyElem.onclick();
  24. }) ();
  25. }
  26. /* begin running the code! */
  27. window.setTimeout(UCME_init, 500);
  28. }
  29.  
  30. /* helper function */
  31. function getId(node) {
  32. return document.getElementById(node);
  33. }
  34.  
  35. function UCME_addLog(UCME_text){
  36. console.log('WME_UCME_' + wme_ucme_version + ' : ' + UCME_text);
  37. }
  38.  
  39. function UCME_del_cams(){
  40. UCME_addLog('del cams called');
  41. if(UCME_waze_Map.camerasLayer.visibility === false)return;
  42. UCME_addLog('cam layer ok');
  43. if(UCME_waze_controler.zoom < 1)return;
  44. UCME_addLog('zoom ok');
  45. var delCams = 0;
  46. for(var cams in UCME_waze_cameras.objects){
  47. var the_cam = UCME_waze_cameras.objects[cams];
  48. // if(!the_cam.onScreen(the_cam)){
  49. // UCME_addLog('Cam n° : ' + cams + ' not on screen -> not deleted');
  50. // continue;
  51. // }
  52. if(the_cam.attributes.validated === true){
  53. UCME_addLog('Cam n° : ' + cams + ' already validated -> not deleted');
  54. continue;
  55. }
  56. if(the_cam.state == 'Delete'){
  57. UCME_addLog('Cam n° : ' + cams + ' already deleted -> do not delete again');
  58. continue;
  59. }
  60. if(the_cam.attributes.permissions == -1){
  61. UCME_addLog('Cam n° : ' + cams + ' is in editable area -> OK deleted');
  62. delCams++;
  63. UCME_waze_model.actionManager.add(new DeleteObject(UCME_waze_cameras.objects[cams]));
  64. }
  65. else
  66. UCME_addLog('Cam n° : ' + cams + ' is NOT in editable area -> not deleted');
  67. }
  68. UCME_addLog('Deleted cams : ' + delCams);
  69. }
  70.  
  71. function UCME_html(){
  72. WME_UCME_addon = document.createElement('div');
  73. WME_UCME_addon.id = 'UCME_btn';
  74. WME_UCME_addon.innerHTML = '<input type="button" id="_UCME_btn" value="Delete unvalidated cameras" /><hr>';
  75. UCME_userInfos.appendChild(WME_UCME_addon);
  76. // Event
  77. getId('_UCME_btn').onclick = UCME_del_cams;
  78. UCME_addLog('HTML renderred');
  79. }
  80.  
  81. function UCME_init(){
  82. // Waze object needed
  83. UCME_Waze = unsafeWindow.W;
  84. if(typeof(UCME_Waze) === 'undefined'){
  85. UCME_addLog('unsafeWindow.W NOK');
  86. window.setTimeout(UCME_init, 500);
  87. return;
  88. }
  89. UCME_waze_loginmanager = UCME_Waze.loginManager;
  90. if(typeof(UCME_waze_loginmanager) === 'undefined'){
  91. UCME_addLog('login manager NOK');
  92. window.setTimeout(UCME_init, 500);
  93. return;
  94. }
  95. UCME_waze_user = UCME_waze_loginmanager.user;
  96. if(typeof(UCME_waze_user) === 'undefined' || UCME_waze_user === null){
  97. UCME_addLog('user NOK');
  98. window.setTimeout(UCME_init, 500);
  99. return;
  100. }
  101. if(UCME_waze_user.rank < 2){
  102. UCME_addLog('User rank is not high enough. Exiting script.');
  103. return;
  104. }
  105. UCME_addLog('User rank OK : ' + eval(UCME_waze_user.rank + 1));
  106. UCME_waze_controler = UCME_Waze.controller;
  107. if(typeof(UCME_waze_controler) === 'undefined'){
  108. UCME_addLog('UCME_waze_controler NOK');
  109. window.setTimeout(UCME_init, 500);
  110. return;
  111. }
  112. UCME_waze_Map = UCME_Waze.map;
  113. if(typeof(UCME_waze_Map) === 'undefined'){
  114. UCME_addLog('map NOK');
  115. window.setTimeout(UCME_init, 500);
  116. return;
  117. }
  118. UCME_waze_model = UCME_Waze.model;
  119. if(typeof(UCME_waze_model) === 'undefined'){
  120. UCME_addLog('model NOK');
  121. window.setTimeout(UCME_init, 500);
  122. return;
  123. }
  124. UCME_waze_cameras = UCME_waze_model.cameras;
  125. if(typeof(UCME_waze_cameras) === 'undefined'){
  126. UCME_addLog('cameras NOK');
  127. window.setTimeout(UCME_init, 500);
  128. return;
  129. }
  130. // New WME compatibility
  131. if(typeof(unsafeWindow.require) === "undefined"){
  132. UCME_addLog('require NOK');
  133. window.setTimeout(UCME_init, 500);
  134. return;
  135. }
  136. require = unsafeWindow.require;
  137. DeleteObject = require("Waze/Action/DeleteObject");
  138. UCME_addLog('Waze OK');
  139. // Waze GUI needed
  140. UCME_userInfos = getId('user-details');
  141. if(typeof(UCME_userInfos) === 'undefined'){
  142. UCME_addLog('userInfos NOK');
  143. window.setTimeout(UCME_init, 500);
  144. return;
  145. }
  146. // Then do the job
  147. // HTML
  148. UCME_html();
  149. }
  150.  
  151. /* engage! =================================================================== */
  152. UCME_bootstrap();
  153. /* end ======================================================================= */