WME Date Format Fix

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

目前為 2016-11-20 提交的版本,檢視 最新版本

  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.0.4
  7. // @grant none
  8. // ==/UserScript==
  9. (function() {
  10. function init() {
  11. if (typeof I18n === 'undefined') {
  12. 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. if (dateFormat && timeFormat) {
  23. return;
  24. }
  25. } catch (e) {
  26. // see http://www.cplusplus.com/reference/ctime/strftime/ for the supported format specifiers
  27. addFormat('en', '%a %b %d, %H:%M (%z)');
  28. addFormat('nl', '%a %d %b, %H:%M (%z)');
  29. addFormat('fr', '%a %d %b, %H:%M (%z)');
  30. }
  31. }
  32. function addFormat(locale, format) {
  33. if (I18n.translations[locale]) {
  34. if (!I18n.translations[locale].date) {
  35. I18n.translations[locale].date = {};
  36. }
  37. if (!I18n.translations[locale].date.formats) {
  38. I18n.translations[locale].date.formats = {};
  39. }
  40. I18n.translations[locale].date.formats.long = format;
  41. if (!I18n.translations[locale].time) {
  42. I18n.translations[locale].time = {};
  43. }
  44. if (!I18n.translations[locale].time.formats) {
  45. I18n.translations[locale].time.formats = {};
  46. }
  47. I18n.translations[locale].time.formats.long = format;
  48. }
  49. }
  50.  
  51. init();
  52. })();