From 167acea2c2243ac9cd9487e80d26c3f18485d43e Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 9 Dec 2011 14:41:19 +0100 Subject: [PATCH] Set up update checking asap. --- 4chan_x.user.js | 27 +++++++++++++++++---------- script.coffee | 21 ++++++++++++--------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 9fc3b82fa..3b3d57df0 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3002,7 +3002,7 @@ Main = { init: function() { - var cutoff, hiddenThreads, id, lastChecked, now, pathname, temp, timestamp, _ref; + var cutoff, hiddenThreads, id, now, pathname, temp, timestamp, update, _ref; pathname = location.pathname.substring(1).split('/'); g.BOARD = pathname[0], temp = pathname[1]; if (temp === 'res') { @@ -3020,11 +3020,23 @@ return; } $.on(window, 'message', Main.message); - g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); - lastChecked = $.get('lastChecked', 0); now = Date.now(); - Main.reqUpdate = lastChecked < now - 1 * DAY; - if (Main.reqUpdate) { + if (conf['Check for Updates'] && $.get('lastUpdate', 0) < now - 6 * HOUR) { + update = function() { + $.off(d, 'DOMContentLoaded', update); + return $.add(d.head, $.el('script', { + src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js' + })); + }; + if (/interactive|complete/.test(d.readyState)) { + update(); + } else { + $.on(d, 'DOMContentLoaded', update); + } + $.set('lastUpdate', now); + } + g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); + if ($.get('lastChecked', 0) < now - 1 * DAY) { $.set('lastChecked', now); cutoff = now - 7 * DAY; hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); @@ -3072,11 +3084,6 @@ $.addStyle(Main.css); threading.init(); Favicon.init(); - if (Main.reqUpdate && conf['Check for Updates']) { - $.add(d.head, $.el('script', { - src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js' - })); - } if ((form = $('form[name=post]')) && (canPost = !!$('#recaptcha_response_field'))) { Recaptcha.init(); if (g.REPLY && conf['Auto Watch Reply'] && conf['Thread Watcher']) { diff --git a/script.coffee b/script.coffee index 1d94e2339..018ffea55 100644 --- a/script.coffee +++ b/script.coffee @@ -1797,7 +1797,7 @@ Time = @parse = if Date.parse '10/11/11(Tue)18:53' is 1318351980000 (node) -> new Date Date.parse(node.textContent) + chanOffset*HOUR - else # Firefox the Archaic cannot parse 4chan's time + else # Firefox and Opera do not parse 4chan's time format correctly (node) -> [_, month, day, year, hour, min] = node.textContent.match /(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/ @@ -2336,13 +2336,19 @@ Main = $.on window, 'message', Main.message - g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {} - - lastChecked = $.get 'lastChecked', 0 now = Date.now() - Main.reqUpdate = lastChecked < now - 1*DAY + if conf['Check for Updates'] and $.get('lastUpdate', 0) < now - 6*HOUR + update = -> + $.off d, 'DOMContentLoaded', update + $.add d.head, $.el 'script', src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js' + if /interactive|complete/.test d.readyState + update() + else + $.on d, 'DOMContentLoaded', update + $.set 'lastUpdate', now - if Main.reqUpdate + g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {} + if $.get('lastChecked', 0) < now - 1*DAY $.set 'lastChecked', now cutoff = now - 7*DAY @@ -2421,9 +2427,6 @@ Main = threading.init() Favicon.init() - if Main.reqUpdate and conf['Check for Updates'] - $.add d.head, $.el 'script', src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js' - #recaptcha may be blocked, eg by noscript if (form = $ 'form[name=post]') and (canPost = !!$ '#recaptcha_response_field') Recaptcha.init()