From b0b252493f35e2c17c1e66974d4b05590537751d Mon Sep 17 00:00:00 2001 From: James Campos Date: Wed, 14 Sep 2011 14:22:02 -0700 Subject: [PATCH 1/3] check for script updates --- 4chan_x.user.js | 36 +++++++++++++++++++++++++++--------- latest.js | 1 + script.coffee | 28 +++++++++++++++++++++------- 3 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 latest.js diff --git a/4chan_x.user.js b/4chan_x.user.js index f05d6c6f5..97470a2ea 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -60,7 +60,7 @@ */ (function() { - var $, $$, DAY, Favicon, HOUR, MINUTE, NAMESPACE, Recaptcha, SECOND, Time, anonymize, conf, config, cooldown, d, expandComment, expandThread, firstRun, g, getTitle, imgExpand, imgGif, imgHover, imgPreloading, key, keybinds, log, main, nav, nodeInserted, options, qr, quoteBacklink, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, threadHiding, threadStats, threading, titlePost, ui, unread, updater, val, watcher; + var $, $$, DAY, Favicon, HOUR, MINUTE, Main, NAMESPACE, Recaptcha, SECOND, Time, VERSION, anonymize, conf, config, cooldown, d, expandComment, expandThread, firstRun, g, getTitle, imgExpand, imgGif, imgHover, imgPreloading, key, keybinds, log, nav, nodeInserted, options, qr, quoteBacklink, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, threadHiding, threadStats, threading, titlePost, ui, unread, updater, val, watcher; var __slice = Array.prototype.slice; config = { main: { @@ -73,7 +73,8 @@ 'Comment Expansion': [true, 'Expand too long comments'], 'Thread Expansion': [true, 'View all replies'], 'Index Navigation': [true, 'Navigate to previous / next thread'], - 'Reply Navigation': [false, 'Navigate to top / bottom of thread'] + 'Reply Navigation': [false, 'Navigate to top / bottom of thread'], + 'Check for Updates': [true, 'Check for updated versions of 4chan x (disabled on master)'] }, Hiding: { 'Reply Hiding': [true, 'Hide single replies'], @@ -187,6 +188,7 @@ } })(null, config); NAMESPACE = 'AEOS.4chan_x.'; + VERSION = 'master'; SECOND = 1000; MINUTE = 60 * SECOND; HOUR = 60 * MINUTE; @@ -1272,7 +1274,6 @@ init: function() { var iframe; g.callbacks.push(qr.node); - $.bind(window, 'message', qr.message); $.bind($('#recaptcha_challenge_field_holder'), 'DOMNodeInserted', qr.captchaNode); qr.captchaTime = Date.now(); qr.spoiler = $('.postarea label') ? '' : ''; @@ -2832,10 +2833,10 @@ return $.unbind(window, 'click', firstRun.close); } }; - main = { + Main = { init: function() { var callback, canPost, cutoff, form, hiddenThreads, id, lastChecked, now, op, pathname, table, temp, timestamp, tzOffset, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref, _ref2, _ref3, _ref4, _ref5; - $.unbind(window, 'load', main.init); + $.unbind(window, 'load', Main.init); pathname = location.pathname.substring(1).split('/'); g.BOARD = pathname[0], temp = pathname[1]; if (temp === 'res') { @@ -2855,6 +2856,7 @@ if (!$('#navtopr')) { return; } + $.bind(window, 'message', Main.message); Favicon.init(); g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); tzOffset = (new Date()).getTimezoneOffset() / 60; @@ -2865,6 +2867,12 @@ lastChecked = $.get('lastChecked', 0); now = Date.now(); if (lastChecked < now - 1 * DAY) { + $.set('lastChecked', now); + if (conf['Check for Updates'] && VERSION !== 'master') { + $.add($.el('script', { + src: 'https://raw.github.com/aeosynth/4chan-x/stable/latest.js' + })); + } cutoff = now - 7 * DAY; hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); for (id in hiddenThreads) { @@ -2882,9 +2890,8 @@ } $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); - $.set('lastChecked', now); } - $.addStyle(main.css); + $.addStyle(Main.css); if ((form = $('form[name=post]')) && (canPost = !!$('#recaptcha_response_field'))) { Recaptcha.init(); if (g.REPLY && conf['Auto Watch Reply'] && conf['Thread Watcher']) { @@ -3016,6 +3023,17 @@ return firstRun.init(); } }, + message: function(e) { + var data, origin; + origin = e.origin, data = e.data; + if (origin === 'http://sys.4chan.org') { + return qr.message(data); + } else { + if (data !== VERSION) { + return alert('new version of 4chan x available on github!'); + } + } + }, css: '\ /* dialog styling */\ div.dialog {\ @@ -3226,8 +3244,8 @@ ' }; if (d.body) { - main.init(); + Main.init(); } else { - $.bind(window, 'load', main.init); + $.bind(window, 'load', Main.init); } }).call(this); diff --git a/latest.js b/latest.js new file mode 100644 index 000000000..41c3a21f3 --- /dev/null +++ b/latest.js @@ -0,0 +1 @@ +window.postMessage('master', '*'); diff --git a/script.coffee b/script.coffee index f671b62f2..0a57c3628 100644 --- a/script.coffee +++ b/script.coffee @@ -10,6 +10,7 @@ config = 'Thread Expansion': [true, 'View all replies'] 'Index Navigation': [true, 'Navigate to previous / next thread'] 'Reply Navigation': [false, 'Navigate to top / bottom of thread'] + 'Check for Updates': [true, 'Check for updated versions of 4chan x (disabled on master)'] Hiding: 'Reply Hiding': [true, 'Hide single replies'] 'Thread Hiding': [true, 'Hide entire threads'] @@ -111,6 +112,7 @@ conf = {} ) null, config NAMESPACE = 'AEOS.4chan_x.' +VERSION = 'master' SECOND = 1000 MINUTE = 60*SECOND HOUR = 60*MINUTE @@ -969,7 +971,6 @@ qr = # email reverts init: -> g.callbacks.push qr.node - $.bind window, 'message', qr.message $.bind $('#recaptcha_challenge_field_holder'), 'DOMNodeInserted', qr.captchaNode qr.captchaTime = Date.now() @@ -2183,9 +2184,9 @@ firstRun = $.rm $ '#overlay' $.unbind window, 'click', firstRun.close -main = +Main = init: -> - $.unbind window, 'load', main.init + $.unbind window, 'load', Main.init pathname = location.pathname.substring(1).split('/') [g.BOARD, temp] = pathname if temp is 'res' @@ -2203,6 +2204,7 @@ main = if not $ '#navtopr' return + $.bind window, 'message', Main.message Favicon.init() g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {} tzOffset = (new Date()).getTimezoneOffset() / 60 @@ -2213,6 +2215,11 @@ main = lastChecked = $.get 'lastChecked', 0 now = Date.now() if lastChecked < now - 1*DAY + $.set 'lastChecked', now + + if conf['Check for Updates'] and VERSION isnt 'master' + $.add $.el 'script', src: 'https://raw.github.com/aeosynth/4chan-x/stable/latest.js' + cutoff = now - 7*DAY hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} @@ -2226,9 +2233,8 @@ main = $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies - $.set 'lastChecked', now - $.addStyle main.css + $.addStyle Main.css #recaptcha may be blocked, eg by noscript if (form = $ 'form[name=post]') and (canPost = !!$ '#recaptcha_response_field') @@ -2348,6 +2354,14 @@ main = unless $.get 'firstrun' firstRun.init() + message: (e) -> + {origin, data} = e + if origin is 'http://sys.4chan.org' + qr.message data + else + if data isnt VERSION + alert 'new version of 4chan x available on github!' + css: ' /* dialog styling */ div.dialog { @@ -2559,6 +2573,6 @@ main = #XXX Opera will load early if script is saved w/o .user if d.body - main.init() + Main.init() else - $.bind window, 'load', main.init + $.bind window, 'load', Main.init From 8926d5a45e5ad8dd6350dc9e5758ac8f64cbb99f Mon Sep 17 00:00:00 2001 From: James Campos Date: Wed, 14 Sep 2011 14:24:53 -0700 Subject: [PATCH 2/3] derp --- 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 97470a2ea..653c3f9c6 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2869,7 +2869,7 @@ if (lastChecked < now - 1 * DAY) { $.set('lastChecked', now); if (conf['Check for Updates'] && VERSION !== 'master') { - $.add($.el('script', { + $.add(d.head, $.el('script', { src: 'https://raw.github.com/aeosynth/4chan-x/stable/latest.js' })); } diff --git a/script.coffee b/script.coffee index 0a57c3628..955e18995 100644 --- a/script.coffee +++ b/script.coffee @@ -2218,7 +2218,7 @@ Main = $.set 'lastChecked', now if conf['Check for Updates'] and VERSION isnt 'master' - $.add $.el 'script', src: 'https://raw.github.com/aeosynth/4chan-x/stable/latest.js' + $.add d.head, $.el 'script', src: 'https://raw.github.com/aeosynth/4chan-x/stable/latest.js' cutoff = now - 7*DAY hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} From c3156eaac145315b7037a65fc5a09379240cd581 Mon Sep 17 00:00:00 2001 From: James Campos Date: Wed, 14 Sep 2011 14:31:29 -0700 Subject: [PATCH 3/3] another derp --- 4chan_x.user.js | 5 ++--- script.coffee | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 653c3f9c6..ccfa3e9a6 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1376,11 +1376,10 @@ $.bind($('#dummy', qr.el), 'keydown', qr.captchaKeydown); return $.add(d.body, qr.el); }, - message: function(e) { - var data, duration, fileCount; + message: function(data) { + var duration, fileCount; $('iframe[name=iframe]').src = 'about:blank'; fileCount = $('#files', qr.el).childElementCount; - data = e.data; if (data) { data = JSON.parse(data); $.extend($('#error', qr.el), data); diff --git a/script.coffee b/script.coffee index 955e18995..87d7d5385 100644 --- a/script.coffee +++ b/script.coffee @@ -1084,11 +1084,10 @@ qr = $.add d.body, qr.el - message: (e) -> + message: (data) -> $('iframe[name=iframe]').src = 'about:blank' fileCount = $('#files', qr.el).childElementCount - {data} = e if data # error message data = JSON.parse data $.extend $('#error', qr.el), data