WME Error Details

Display the error messages received from Waze in the web console

  1. // ==UserScript==
  2. // @name WME Error Details
  3. // @author Tom 'Glodenox' Puttemans
  4. // @namespace http://www.tomputtemans.com/
  5. // @description Display the error messages received from Waze in the web console
  6. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
  7. // @version 0.1.1
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. // Replace the send method with a function that adds a listener to the load event
  13. // This way we can monitor the results
  14. XMLHttpRequest.prototype.reallySend = XMLHttpRequest.prototype.send;
  15. XMLHttpRequest.prototype.send = function(body) {
  16. this.addEventListener('load', function() {
  17. if (this.status != 200) {
  18. try {
  19. var response = JSON.parse(this.response);
  20. log(response);
  21. response.errorList.forEach(function(error) {
  22. log('Error code ' + error.code + ': ' + error.details);
  23. });
  24. } catch (e) {
  25. log(this.response);
  26. }
  27. }
  28. });
  29. this.reallySend(body);
  30. };
  31.  
  32. function log(message) {
  33. if (typeof message === 'string') {
  34. console.log('%c' + GM_info.script.name + ' (v' + GM_info.script.version + '): %c' + message, 'color:black', 'color:#d97e00');
  35. } else {
  36. console.log('%c' + GM_info.script.name + ' (v' + GM_info.script.version + ')', 'color:black', message);
  37. }
  38. }
  39. })();