WME Date Format Fix

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        WME Date Format Fix
// @namespace   http://www.tomputtemans.com/
// @description Fixes the date format if it is still missing or allows you to override the default date format
// @include     /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
// @version     0.1.3
// @grant       none
// ==/UserScript==
(function() {
  function init() {
    if (typeof I18n === 'undefined') {
      console.log('No internationalisation object found yet, snoozing');
      setTimeout(init, 300);
      return;
    }
    fixDateFormat();
  }
  
  function fixDateFormat() {
    try {
      var dateFormat = I18n.translations.en.date.formats.long;
      var timeFormat = I18n.translations.en.time.formats.long;
      var datetimeFormat = I18n.translations[locale].date.formats.default;
      if (dateFormat && timeFormat && datetimeFormat) {
        return;
      }
    } catch (e) {
      // see http://www.cplusplus.com/reference/ctime/strftime/ for the supported format specifiers
      addFormat(I18n.currentLocale(), '%a %b %d, %Y', '%a %b %d %Y, %H:%M');
      addFormat('en', '%a %b %d, %Y', '%a %b %d %Y, %H:%M');
      addFormat('nl', '%a %d %b, %Y', '%a %d %b %Y, %H:%M');
      addFormat('fr', '%a %d %b, %Y', '%a %d %b %Y, %H:%M');
      addFormat('cs', '%e. %m., %Y', '%e. %m. %Y, %H.%M');
      addFormat('sk', '%e. %m., %Y', '%e. %m. %Y, %H.%M');
    }
    if (I18n.currentLocale() == 'en-GB' && I18n.translations['en-GB'].update_requests.panel.reported == 'Reported on') {
      I18n.translations['en-GB'].update_requests.panel.reported = 'Reported on: %{date}';
    }
  }
  
  function addFormat(locale, dateFormat, datetimeFormat) {
    if (!I18n.translations[locale]) {
      return;
    }

    if (!I18n.translations[locale].date) {
      I18n.translations[locale].date = {};
    }
    if (!I18n.translations[locale].date.formats) {
      I18n.translations[locale].date.formats = {};
    }
    I18n.translations[locale].date.formats.long = datetimeFormat;
    I18n.translations[locale].date.formats.default = dateFormat;

    if (!I18n.translations[locale].time) {
      I18n.translations[locale].time = {};
    }
    if (!I18n.translations[locale].time.formats) {
      I18n.translations[locale].time.formats = {};
    }
    I18n.translations[locale].time.formats.long = datetimeFormat;
  }

  init();
})();