report button for partnerhub

Adds a small button in footer toolbar to open the reporting tool in the same coords you are.

  1. // ==UserScript==
  2. // @name report button for partnerhub
  3. // @description Adds a small button in footer toolbar to open the reporting tool in the same coords you are.
  4. // @namespace https://greasyfork.org/en/users/715686-aseele-h
  5. // @version 2023.11.23
  6.  
  7. // @author aseele
  8. // @include https://www.waze.com/editor*
  9. // @include https://www.waze.com/*/editor*
  10. // @include https://beta.waze.com/editor*
  11. // @include https://beta.waze.com/*/editor*
  12. // @exclude https://www.waze.com/user/*
  13. // @exclude https://www.waze.com/*/user/*
  14. // @grant none
  15. // @icon none
  16. // @run-at document-body
  17. // ==/UserScript==
  18.  
  19. (function() {
  20.  
  21. 'use strict';
  22.  
  23. var icon_svg = "data:image/svg+xml,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' clip-rule='evenodd' stroke-linejoin='round' stroke-miterlimit='2'%3E%3Cpath d='M32 8c0-4.415-3.585-8-8-8H8C3.585 0 0 3.585 0 8v16c0 4.415 3.585 8 8 8h16c4.415 0 8-3.585 8-8V8z' fill='%236500ff'/%3E%3Cg fill='%23fff' fill-rule='nonzero'%3E%3Cpath d='M7.07 14.518h.912l1.481-4.358 1.482 4.358h.912L13.96 8.41h-1.111l-1.438 4.497-1.482-4.514h-.895L7.55 12.907 6.113 8.41H4.968l2.101 6.108zM15.044 14.475h1.042v-4.332l1.886 2.842h.034l1.904-2.86v4.35h1.059V8.41H19.84l-1.835 2.868-1.834-2.868h-1.128v6.065zM22.52 14.475h4.512v-.953h-3.454v-1.629h3.023v-.953h-3.023V9.363h3.41V8.41H22.52v6.065z'/%3E%3C/g%3E%3Cpath d='M8.856 23.607c2.205 0 3.909-1.654 3.909-3.725v-.02c0-2.072-1.684-3.705-3.888-3.705-2.205 0-3.909 1.653-3.909 3.725v.02c0 2.072 1.684 3.705 3.888 3.705zm.02-2.113c-.918 0-1.5-.765-1.5-1.612v-.02c0-.837.572-1.593 1.48-1.593.919 0 1.5.766 1.5 1.613v.02c0 .837-.57 1.592-1.48 1.592zM13.418 23.454h2.388v-2.041h.51l1.347 2.04h2.725l-1.663-2.428c.867-.419 1.408-1.143 1.408-2.184v-.02c0-.735-.224-1.266-.653-1.695-.5-.5-1.306-.816-2.572-.816h-3.49v7.144zm2.388-3.746V18.31h1.041c.551 0 .908.225.908.684v.02c0 .44-.347.694-.918.694h-1.03zM22.542 23.454h2.388V18.33h2.102V16.31h-6.593v2.02h2.103v5.124z' fill='%23fff' fill-rule='nonzero'/%3E%3C/svg%3E";
  24.  
  25. function generateURL() {
  26. var segment = W.selectionManager.getSegmentSelection().segments[0];
  27. var projI = new OpenLayers.Projection("EPSG:900913");
  28. var projE = new OpenLayers.Projection("EPSG:4326");
  29. var center_lonlat = (new OpenLayers.LonLat(W.map.olMap.center.lon,W.map.olMap.center.lat)).transform(projI,projE);
  30. var lat = Math.round(center_lonlat.lat * 1000000) / 1000000;
  31. var lon = Math.round(center_lonlat.lon * 1000000) / 1000000;
  32. return `https://www.waze.com/partnerhub/map-tool/alerts?lon=${lon}&lat=${lat}`;
  33. }
  34. function openRT() {
  35. var rtUrl = generateURL();
  36. window.open(rtUrl, "_blank");
  37. }
  38.  
  39. function init_OPEN_REPORTING_TOOL() {
  40. try {
  41. var toolbarWrap = document.querySelector('.WazeControlPermalink');
  42. if (toolbarWrap !== null) {
  43. //toolbarWrap.insertAdjacentHTML('afterend', `<div class="WazeControlORT" id="WME_ORT" style="margin:0 5px;"><a href="#" id="btn-openrt"><img src="${icon_svg}" width="18" height="18" alt="Open Reporting Tool" title="Open Reporting Tool" /></a></div>`);
  44. //toolbarWrap.insertAdjacentHTML('afterend', '<div class="WazeControlORT" id="WME_ORT" style="margin:0 5px;"><a href="#" id="btn-openrt">REPORT</a></div>');
  45. toolbarWrap.insertAdjacentHTML('afterend', '<div class="WazeControlORT" id="WME_ORT" style="margin:0 5px;"><a href="#" id="btn-openrt"><strong>report</strong></a></div>');
  46.  
  47. document.getElementById("btn-openrt").addEventListener("click", openRT, false);
  48. console.info('%c%s','background:green;color:white;padding:5px 10px;','[SUCCESS] WME OPEN REPORTING TOOL >> INITIALIZED');
  49. } else {
  50. setTimeout(init_OPEN_REPORTING_TOOL, 1000);
  51. console.error('%c%s','background:red;color:white;padding:5px 10px;','[ERROR] OPEN REPORTING TOOL >> Could not find necessary Waze map objets. Trying again...');
  52. }
  53. } catch (err) {
  54. setTimeout(init_OPEN_REPORTING_TOOL, 1000);
  55. console.error('%c%s','background:red;color:white;padding:5px 10px;','[ERROR] WME OPEN REPORTING TOOL >> Failed to initialize.');
  56. console.error('%c%s','background:red;color:white;padding:5px 10px;','[ERROR] WME OPEN REPORTING TOOL >> Error details: ', err);
  57. }
  58. }
  59.  
  60. init_OPEN_REPORTING_TOOL();
  61.  
  62. })();