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 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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.0.5
// @grant       none
// ==/UserScript==
(function() {
  function init() {
    if (typeof I18n === 'undefined') {
      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;
      if (dateFormat && timeFormat) {
        return;
      }
    } catch (e) {
      // see http://www.cplusplus.com/reference/ctime/strftime/ for the supported format specifiers
      addFormat('en', '%a %b %d %Y, %H:%M');
      addFormat('nl', '%a %d %b %Y, %H:%M');
      addFormat('fr', '%a %d %b %Y, %H:%M');
    }
  }
  
  function addFormat(locale, format) {
    if (I18n.translations[locale]) {
      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 = format;
      
      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 = format;
    }
  }

  init();
})();