diff --git a/4chan_x.js b/4chan_x.js index d0d201249..460957cdf 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -104,6 +104,7 @@ 'Anonymize': [false, 'Make everybody anonymous'], 'Keybinds': [false, 'Binds actions to keys'], 'Localize Time': [true, 'Show times based on your timezone'], + 'Localized am/pm': [false, 'Change localized time to the 12-hour clock convention'], 'Report Button': [true, 'Add report buttons'], 'Comment Expansion': [true, 'Expand too long comments'], 'Thread Expansion': [true, 'View all replies'], @@ -1640,7 +1641,7 @@ localize = { init: function() { return g.callbacks.push(function(root) { - var date, day, dotw, hour, min_sec, month, s, span, year, _, _i, _len, _ref, _ref2, _results; + var date, day, dotw, hour, meridiem, min_sec, month, s, span, year, _, _i, _len, _ref, _ref2, _results; _ref = $$('span[id^=no]', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -1650,13 +1651,18 @@ year = "20" + year; month -= 1; hour = g.chanOffset + Number(hour); + meridiem = ''; + if ($.config('Localized am/pm')) { + meridiem = hour < 12 ? ' a.m.' : ' p.m.'; + hour = hour === 0 ? 12 : hour > 12 ? hour - 12 : void 0; + } date = new Date(year, month, day, hour); year = date.getFullYear() - 2000; month = $.zeroPad(date.getMonth() + 1); day = $.zeroPad(date.getDate()); hour = $.zeroPad(date.getHours()); dotw = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][date.getDay()]; - _results.push(s.textContent = " " + month + "/" + day + "/" + year + "(" + dotw + ")" + hour + ":" + min_sec + " "); + _results.push(s.textContent = " " + month + "/" + day + "/" + year + "(" + dotw + ")" + hour + ":" + min_sec + meridiem + " "); } return _results; }); diff --git a/script.coffee b/script.coffee index 19c4fae5a..f85b9a4de 100644 --- a/script.coffee +++ b/script.coffee @@ -42,6 +42,7 @@ config = 'Anonymize': [false, 'Make everybody anonymous'] 'Keybinds': [false, 'Binds actions to keys'] 'Localize Time': [true, 'Show times based on your timezone'] + 'Localized am/pm': [false, 'Change localized time to the 12-hour clock convention'] 'Report Button': [true, 'Add report buttons'] 'Comment Expansion': [true, 'Expand too long comments'] 'Thread Expansion': [true, 'View all replies'] @@ -1329,6 +1330,10 @@ localize = year = "20#{year}" month -= 1 #months start at 0 hour = g.chanOffset + Number hour + meridiem = '' + if $.config 'Localized am/pm' + meridiem = if hour < 12 then ' a.m.' else ' p.m.' + hour = if hour is 0 then 12 else if hour > 12 then hour - 12 date = new Date year, month, day, hour year = date.getFullYear() - 2000 month = $.zeroPad date.getMonth() + 1 @@ -1343,7 +1348,7 @@ localize = 'Fri' 'Sat' ][date.getDay()] - s.textContent = " #{month}/#{day}/#{year}(#{dotw})#{hour}:#{min_sec} " + s.textContent = " #{month}/#{day}/#{year}(#{dotw})#{hour}:#{min_sec}#{meridiem} " titlePost = init: ->