From eba2ef90c982c7d0723441d7c96a7116062ceeb9 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 11 Oct 2011 23:26:09 +0200 Subject: [PATCH 1/3] Use Date.parse() on modern browsers. See what I did there? I implied that Firefox is the new IE and you should upgrade. --- 4chan_x.user.js | 16 ++++++++++------ script.coffee | 17 ++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 919f54ff2..fc49b2383 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2196,16 +2196,20 @@ return g.callbacks.push(Time.node); }, node: function(root) { - var day, hour, min, month, node, posttime, time, year, _, _ref; + var day, hour, min, month, node, parse, posttime, time, year, _, _ref; if (root.className === 'inline') { return; } node = (posttime = $('.posttime', root)) ? posttime : $('span[id]', root).previousSibling; - _ref = node.textContent.match(/(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/), _ = _ref[0], month = _ref[1], day = _ref[2], year = _ref[3], hour = _ref[4], min = _ref[5]; - year = "20" + year; - month -= 1; - hour = g.chanOffset + Number(hour); - Time.date = new Date(year, month, day, hour, min); + if (parse = Date.parse(node.textContent)) { + Time.date = new Date(parse + g.chanOffset * HOUR); + } else { + _ref = node.textContent.match(/(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/), _ = _ref[0], month = _ref[1], day = _ref[2], year = _ref[3], hour = _ref[4], min = _ref[5]; + year = "20" + year; + month -= 1; + hour = g.chanOffset + Number(hour); + Time.date = new Date(year, month, day, hour, min); + } time = $.el('time', { textContent: ' ' + Time.funk(Time) + ' ' }); diff --git a/script.coffee b/script.coffee index ec9615d5b..88668774b 100644 --- a/script.coffee +++ b/script.coffee @@ -1663,13 +1663,16 @@ Time = node: (root) -> return if root.className is 'inline' node = if posttime = $('.posttime', root) then posttime else $('span[id]', root).previousSibling - [_, month, day, year, hour, min] = - node.textContent.match /(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/ - year = "20#{year}" - month -= 1 #months start at 0 - hour = g.chanOffset + Number hour - Time.date = new Date year, month, day, hour, min - #XXX /b/ will have seconds cut off + if parse = Date.parse node.textContent + Time.date = new Date parse + g.chanOffset*HOUR + else # Firefox the Archaic cannot parse 4chan's time + [_, month, day, year, hour, min] = + node.textContent.match /(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/ + year = "20#{year}" + month -= 1 #months start at 0 + hour = g.chanOffset + Number hour + Time.date = new Date year, month, day, hour, min + #XXX /b/ will have seconds cut off time = $.el 'time', textContent: ' ' + Time.funk(Time) + ' ' From 448c6aad4eaa66e501beaba57a15fae325324031 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 12 Oct 2011 00:21:55 +0200 Subject: [PATCH 2/3] Function Time.parse() --- 4chan_x.user.js | 26 ++++++++++++++------------ script.coffee | 25 ++++++++++++++----------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index fc49b2383..76e834f2e 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2193,23 +2193,25 @@ Time = { init: function() { Time.foo(); - return g.callbacks.push(Time.node); - }, - node: function(root) { - var day, hour, min, month, node, parse, posttime, time, year, _, _ref; - if (root.className === 'inline') { - return; - } - node = (posttime = $('.posttime', root)) ? posttime : $('span[id]', root).previousSibling; - if (parse = Date.parse(node.textContent)) { - Time.date = new Date(parse + g.chanOffset * HOUR); - } else { + this.parse = Date.parse($('.posttime').textContent) ? function(node) { + return new Date(Date.parse(node.textContent) + g.chanOffset * HOUR); + } : function(node) { + var day, hour, min, month, year, _, _ref; _ref = node.textContent.match(/(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/), _ = _ref[0], month = _ref[1], day = _ref[2], year = _ref[3], hour = _ref[4], min = _ref[5]; year = "20" + year; month -= 1; hour = g.chanOffset + Number(hour); - Time.date = new Date(year, month, day, hour, min); + return new Date(year, month, day, hour, min); + }; + return g.callbacks.push(Time.node); + }, + node: function(root) { + var node, posttime, time; + if (root.className === 'inline') { + return; } + node = (posttime = $('.posttime', root)) ? posttime : $('span[id]', root).previousSibling; + Time.date = Time.parse(node); time = $.el('time', { textContent: ' ' + Time.funk(Time) + ' ' }); diff --git a/script.coffee b/script.coffee index 88668774b..5a512e945 100644 --- a/script.coffee +++ b/script.coffee @@ -1659,21 +1659,24 @@ revealSpoilers = Time = init: -> Time.foo() + + @parse = + if Date.parse $('.posttime').textContent + (node) -> new Date Date.parse(node.textContent) + g.chanOffset*HOUR + else # Firefox the Archaic cannot parse 4chan's time + (node) -> + [_, month, day, year, hour, min] = + node.textContent.match /(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/ + year = "20#{year}" + month -= 1 #months start at 0 + hour = g.chanOffset + Number hour + new Date year, month, day, hour, min + g.callbacks.push Time.node node: (root) -> return if root.className is 'inline' node = if posttime = $('.posttime', root) then posttime else $('span[id]', root).previousSibling - if parse = Date.parse node.textContent - Time.date = new Date parse + g.chanOffset*HOUR - else # Firefox the Archaic cannot parse 4chan's time - [_, month, day, year, hour, min] = - node.textContent.match /(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/ - year = "20#{year}" - month -= 1 #months start at 0 - hour = g.chanOffset + Number hour - Time.date = new Date year, month, day, hour, min - #XXX /b/ will have seconds cut off - + Time.date = Time.parse node time = $.el 'time', textContent: ' ' + Time.funk(Time) + ' ' $.replace node, time From b59f1ddc37926565d59a9f136520d0f5646c0caa Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 12 Oct 2011 00:59:24 +0200 Subject: [PATCH 3/3] Parse a string. --- 4chan_x.user.js | 2 +- script.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 76e834f2e..ff3000851 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2193,7 +2193,7 @@ Time = { init: function() { Time.foo(); - this.parse = Date.parse($('.posttime').textContent) ? function(node) { + this.parse = Date.parse('10/11/11(Tue)18:53') ? function(node) { return new Date(Date.parse(node.textContent) + g.chanOffset * HOUR); } : function(node) { var day, hour, min, month, year, _, _ref; diff --git a/script.coffee b/script.coffee index 5a512e945..adaf7f665 100644 --- a/script.coffee +++ b/script.coffee @@ -1661,7 +1661,7 @@ Time = Time.foo() @parse = - if Date.parse $('.posttime').textContent + if Date.parse '10/11/11(Tue)18:53' (node) -> new Date Date.parse(node.textContent) + g.chanOffset*HOUR else # Firefox the Archaic cannot parse 4chan's time (node) ->