WME Date Format Fix

Fixes the date format if it is still missing or allows you to override the default date format

  1. // ==UserScript==
  2. // @name WME Date Format Fix
  3. // @namespace http://www.tomputtemans.com/
  4. // @description Fixes the date format if it is still missing or allows you to override the default date format
  5. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
  6. // @version 0.1.3
  7. // @grant none
  8. // ==/UserScript==
  9. (function() {
  10. function init() {
  11. if (typeof I18n === 'undefined') {
  12. console.log('No internationalisation object found yet, snoozing');
  13. setTimeout(init, 300);
  14. return;
  15. }
  16. fixDateFormat();
  17. }
  18. function fixDateFormat() {
  19. try {
  20. var dateFormat = I18n.translations.en.date.formats.long;
  21. var timeFormat = I18n.translations.en.time.formats.long;
  22. var datetimeFormat = I18n.translations[locale].date.formats.default;
  23. if (dateFormat && timeFormat && datetimeFormat) {
  24. return;
  25. }
  26. } catch (e) {
  27. // see http://www.cplusplus.com/reference/ctime/strftime/ for the supported format specifiers
  28. addFormat(I18n.currentLocale(), '%a %b %d, %Y', '%a %b %d %Y, %H:%M');
  29. addFormat('en', '%a %b %d, %Y', '%a %b %d %Y, %H:%M');
  30. addFormat('nl', '%a %d %b, %Y', '%a %d %b %Y, %H:%M');
  31. addFormat('fr', '%a %d %b, %Y', '%a %d %b %Y, %H:%M');
  32. addFormat('cs', '%e. %m., %Y', '%e. %m. %Y, %H.%M');
  33. addFormat('sk', '%e. %m., %Y', '%e. %m. %Y, %H.%M');
  34. }
  35. if (I18n.currentLocale() == 'en-GB' && I18n.translations['en-GB'].update_requests.panel.reported == 'Reported on') {
  36. I18n.translations['en-GB'].update_requests.panel.reported = 'Reported on: %{date}';
  37. }
  38. }
  39. function addFormat(locale, dateFormat, datetimeFormat) {
  40. if (!I18n.translations[locale]) {
  41. return;
  42. }
  43.  
  44. if (!I18n.translations[locale].date) {
  45. I18n.translations[locale].date = {};
  46. }
  47. if (!I18n.translations[locale].date.formats) {
  48. I18n.translations[locale].date.formats = {};
  49. }
  50. I18n.translations[locale].date.formats.long = datetimeFormat;
  51. I18n.translations[locale].date.formats.default = dateFormat;
  52.  
  53. if (!I18n.translations[locale].time) {
  54. I18n.translations[locale].time = {};
  55. }
  56. if (!I18n.translations[locale].time.formats) {
  57. I18n.translations[locale].time.formats = {};
  58. }
  59. I18n.translations[locale].time.formats.long = datetimeFormat;
  60. }
  61.  
  62. init();
  63. })();