From 6c7d31fe94686de5e6c2ff7c7287bddb9d6689e6 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 5 Jun 2011 21:24:25 -0700 Subject: [PATCH] time preview --- 4chan_x.user.js | 49 ++++++++++++++++++++++++++++++------------------- script.coffee | 25 +++++++++++++++++-------- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a39a247b9..229e8a443 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -958,7 +958,7 @@ var arr, checked, description, dialog, hiddenNum, hiddenThreads, html, input, key, li, main, obj, ul, _i, _len, _ref, _ref2; hiddenThreads = $.getValue("hiddenThreads/" + g.BOARD + "/", {}); hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length; - html = "
Options X


Sauce flavors
Time Formatting
Donate
support throd | github | uso
"; + html = "
Options X


Sauce flavors
Time Formatting
Donate
support throd | github | uso
"; dialog = ui.dialog('options', { top: '25%', left: '25%' @@ -990,7 +990,9 @@ $.bind($('a[name=flavors]', dialog), 'click', options.flavors); $.bind($('a[name=time]', dialog), 'click', options.time); $.bind($('textarea[name=flavors]', dialog), 'change', $.cb.value); - return $.append(d.body, dialog); + $.bind($('input[name=time]', dialog), 'keyup', options.cb.time); + $.append(d.body, dialog); + return options.cb.time.call($('input[name=time]', dialog)); }, flavors: function() { var ta; @@ -1016,6 +1018,12 @@ $.deleteValue("hiddenThreads/" + g.BOARD + "/"); this.value = "hidden: 0"; return g.hiddenReplies = {}; + }, + time: function(e) { + $.setValue('time', this.value); + time.foo(); + time.date = new Date(); + return $('#timePreview').textContent = time.funk(time); } } }; @@ -1670,6 +1678,25 @@ }; time = { init: function() { + time.foo(); + return g.callbacks.push(function(root) { + var day, hour, min, month, s, timeEl, year, _, _ref; + if (root.className === 'inline') { + return; + } + s = $('span[id^=no]', root).previousSibling; + _ref = s.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); + timeEl = $.el('time', { + textContent: ' ' + time.funk(time) + ' ' + }); + return $.replace(s, timeEl); + }); + }, + foo: function() { var code; code = $.config('time').replace(/%(.)/g, function(s, c) { switch (c) { @@ -1689,23 +1716,7 @@ return s; } }); - time.funk = Function('time', "return '" + code + "'"); - return g.callbacks.push(function(root) { - var day, hour, min, month, s, timeEl, year, _, _ref; - if (root.className === 'inline') { - return; - } - s = $('span[id^=no]', root).previousSibling; - _ref = s.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); - timeEl = $.el('time', { - textContent: ' ' + time.funk(time) + ' ' - }); - return $.replace(s, timeEl); - }); + return time.funk = Function('time', "return '" + code + "'"); }, zeroPad: function(n) { if (n < 10) { diff --git a/script.coffee b/script.coffee index 215331c17..ec56073f6 100644 --- a/script.coffee +++ b/script.coffee @@ -738,7 +738,7 @@ options =