From d131621b9efbba06036ea7858ef3a6c81e507986 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 18 Oct 2011 16:09:34 +0200 Subject: [PATCH 1/6] Init time offset and g.hiddenReplies earlier. --- 4chan_x.user.js | 13 ++++++------- script.coffee | 12 ++++++------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 3e674a0d6..a521120e1 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -518,6 +518,11 @@ } else { g.PAGENUM = parseInt(temp) || 0; } + g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); + g.chanOffset = 5 - new Date().getTimezoneOffset() / 60; + if ($.isDST()) { + g.chanOffset--; + } $$ = function(selector, root) { if (root == null) { root = d.body; @@ -2963,7 +2968,7 @@ }; Main = { init: function() { - var cutoff, hiddenThreads, id, lastChecked, nodes, now, timestamp, tzOffset, _ref; + var cutoff, hiddenThreads, id, lastChecked, nodes, now, timestamp, _ref; $.unbind(document, 'DOMContentLoaded', Main.init); if (location.hostname === 'sys.4chan.org') { QR.sys(); @@ -2978,12 +2983,6 @@ } $.bind(window, 'message', Main.message); Favicon.init(); - g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); - tzOffset = (new Date()).getTimezoneOffset() / 60; - g.chanOffset = 5 - tzOffset; - if ($.isDST()) { - g.chanOffset--; - } lastChecked = $.get('lastChecked', 0); now = Date.now(); if (lastChecked < now - 1 * DAY) { diff --git a/script.coffee b/script.coffee index e13e34908..01bba707c 100644 --- a/script.coffee +++ b/script.coffee @@ -378,6 +378,12 @@ if temp is 'res' else g.PAGENUM = parseInt(temp) or 0 +g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {} +# GMT -8 is given as +480; would GMT +8 be -480 ? +g.chanOffset = 5 - new Date().getTimezoneOffset() / 60 +# 4chan = EST = GMT -5 +g.chanOffset-- if $.isDST() + $$ = (selector, root=d.body) -> Array::slice.call root.querySelectorAll selector @@ -2248,12 +2254,6 @@ Main = $.bind window, 'message', Main.message Favicon.init() - g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {} - tzOffset = (new Date()).getTimezoneOffset() / 60 - # GMT -8 is given as +480; would GMT +8 be -480 ? - g.chanOffset = 5 - tzOffset - # 4chan = EST = GMT -5 - g.chanOffset-- if $.isDST() lastChecked = $.get 'lastChecked', 0 now = Date.now() From b3c4dc3d8b3c40fb9a29af7f4993bbd7f2529355 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 18 Oct 2011 18:03:46 +0200 Subject: [PATCH 2/6] Remove unnecessary (e)s. --- 4chan_x.user.js | 36 ++++++++++++++++++------------------ script.coffee | 36 ++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a521120e1..c56782b70 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -275,7 +275,7 @@ return style.right = clientWidth - clientX + 45; } }, - hoverend: function(e) { + hoverend: function() { return ui.el.parentNode.removeChild(ui.el); } }; @@ -689,7 +689,7 @@ return _results; }, cb: { - toggle: function(e) { + toggle: function() { var thread; thread = this.parentNode; return expandThread.toggle(thread); @@ -799,12 +799,12 @@ }); }, cb: { - hide: function(e) { + hide: function() { var reply; reply = this.parentNode.nextSibling; return replyHiding.hide(reply); }, - show: function(e) { + show: function() { var div, table; div = this.parentNode; table = div.nextSibling; @@ -1360,7 +1360,7 @@ options.time.call(time); return options.backlink.call(back); }, - clearHidden: function(e) { + clearHidden: function() { $["delete"]("hiddenReplies/" + g.BOARD + "/"); $["delete"]("hiddenThreads/" + g.BOARD + "/"); this.textContent = "hidden: 0"; @@ -1376,14 +1376,14 @@ $.set(this.name, key); return conf[this.name] = key; }, - time: function(e) { + time: function() { $.set('time', this.value); conf['time'] = this.value; Time.foo(); Time.date = new Date(); return $('#timePreview').textContent = Time.funk(Time); }, - backlink: function(e) { + backlink: function() { $.set('backlink', this.value); conf['backlink'] = this.value; return $('#backlinkPreview').textContent = conf['backlink'].replace(/%id/, '123456789'); @@ -1827,12 +1827,12 @@ return _results; }, cb: { - hide: function(e) { + hide: function() { var thread; thread = this.parentNode.parentNode; return threadHiding.hide(thread); }, - show: function(e) { + show: function() { var thread; thread = this.parentNode.parentNode; return threadHiding.show(thread); @@ -2099,10 +2099,10 @@ return _results; }, cb: { - toggle: function(e) { + toggle: function() { return watcher.toggle(this.parentNode); }, - x: function(e) { + x: function() { var board, id, _, _ref; _ref = this.nextElementSibling.getAttribute('href').substring(1).split('/'), board = _ref[0], _ = _ref[1], id = _ref[2]; return watcher.unwatch(board, id); @@ -2664,7 +2664,7 @@ return Favicon.update(); } }, - scroll: function(e) { + scroll: function() { var bottom, height, i, reply, _len, _ref; updater.focus = true; height = d.body.clientHeight; @@ -2769,7 +2769,7 @@ return $.bind(thumb, 'mouseout', ui.hoverend); }); }, - mouseover: function(e) { + mouseover: function() { ui.el = $.el('img', { id: 'iHover', src: this.parentNode.href @@ -2832,7 +2832,7 @@ e.preventDefault(); return imgExpand.toggle(this); }, - all: function(e) { + all: function() { var thumb, _i, _j, _len, _len2, _ref, _ref2, _results, _results2; imgExpand.on = this.checked; if (imgExpand.on) { @@ -2853,7 +2853,7 @@ return _results2; } }, - typeChange: function(e) { + typeChange: function() { var klass; switch (this.value) { case 'full': @@ -2899,13 +2899,13 @@ thumb.hidden = true; return $.add(a, img); }, - error: function(e) { + error: function() { var req, thumb; thumb = this.previousSibling; imgExpand.contract(thumb); if (navigator.appName !== 'Opera') { req = $.ajax(this.src, null, 'head'); - return req.onreadystatechange = function(e) { + return req.onreadystatechange = function() { if (this.status !== 404) { return setTimeout(imgExpand.retry, 10000, thumb); } @@ -2942,7 +2942,7 @@ delform = $('form[name=delform]'); return $.prepend(delform, controls); }, - resize: function(e) { + resize: function() { return imgExpand.style.innerHTML = ".fitheight img[md5] + img {max-height:" + d.body.clientHeight + "px;}"; } }; diff --git a/script.coffee b/script.coffee index 01bba707c..ec8467fff 100644 --- a/script.coffee +++ b/script.coffee @@ -197,7 +197,7 @@ ui = style.left = null style.right = clientWidth - clientX + 45 - hoverend: (e) -> + hoverend: -> ui.el.parentNode.removeChild ui.el ### @@ -486,7 +486,7 @@ expandThread = $.replace span, a cb: - toggle: (e) -> + toggle: -> thread = @parentNode expandThread.toggle thread @@ -566,11 +566,11 @@ replyHiding = replyHiding.hide reply cb: - hide: (e) -> + hide: -> reply = @parentNode.nextSibling replyHiding.hide reply - show: (e) -> + show: -> div = @parentNode table = div.nextSibling replyHiding.show table @@ -994,7 +994,7 @@ options = options.time.call time options.backlink.call back - clearHidden: (e) -> + clearHidden: -> #'hidden' might be misleading; it's the number of IDs we're *looking* for, # not the number of posts actually hidden on the page. $.delete "hiddenReplies/#{g.BOARD}/" @@ -1008,13 +1008,13 @@ options = @value = key $.set @name, key conf[@name] = key - time: (e) -> + time: -> $.set 'time', @value conf['time'] = @value Time.foo() Time.date = new Date() $('#timePreview').textContent = Time.funk Time - backlink: (e) -> + backlink: -> $.set 'backlink', @value conf['backlink'] = @value $('#backlinkPreview').textContent = conf['backlink'].replace /%id/, '123456789' @@ -1367,10 +1367,10 @@ threadHiding = threadHiding.hideHide thread cb: - hide: (e) -> + hide: -> thread = @parentNode.parentNode threadHiding.hide thread - show: (e) -> + show: -> thread = @parentNode.parentNode threadHiding.show thread @@ -1596,9 +1596,9 @@ watcher = favicon.src = Favicon.empty cb: - toggle: (e) -> + toggle: -> watcher.toggle @parentNode - x: (e) -> + x: -> [board, _, id] = @nextElementSibling .getAttribute('href').substring(1).split('/') watcher.unwatch board, id @@ -1971,7 +1971,7 @@ unread = if unread.replies.length is 1 Favicon.update() - scroll: (e) -> + scroll: -> updater.focus = true height = d.body.clientHeight for reply, i in unread.replies @@ -2043,7 +2043,7 @@ imgHover = $.bind thumb, 'mouseover', imgHover.mouseover $.bind thumb, 'mousemove', ui.hover $.bind thumb, 'mouseout', ui.hoverend - mouseover: (e) -> + mouseover: -> ui.el = $.el 'img' id: 'iHover' src: @parentNode.href @@ -2082,7 +2082,7 @@ imgExpand = return if e.shiftKey or e.altKey or e.ctrlKey or e.button isnt 0 e.preventDefault() imgExpand.toggle @ - all: (e) -> + all: -> imgExpand.on = @checked if imgExpand.on #expand for thumb in $$ 'img[md5]:not([hidden])' @@ -2090,7 +2090,7 @@ imgExpand = else #contract for thumb in $$ 'img[md5][hidden]' imgExpand.contract thumb - typeChange: (e) -> + typeChange: -> switch @value when 'full' klass = '' @@ -2125,13 +2125,13 @@ imgExpand = thumb.hidden = true $.add a, img - error: (e) -> + error: -> thumb = @previousSibling imgExpand.contract thumb #navigator.online is not x-browser/os yet if navigator.appName isnt 'Opera' req = $.ajax @src, null, 'head' - req.onreadystatechange = (e) -> setTimeout imgExpand.retry, 10000, thumb if @status isnt 404 + req.onreadystatechange = -> setTimeout imgExpand.retry, 10000, thumb if @status isnt 404 else unless g.dead setTimeout imgExpand.retry, 10000, thumb retry: (thumb) -> @@ -2157,7 +2157,7 @@ imgExpand = delform = $ 'form[name=delform]' $.prepend delform, controls - resize: (e) -> + resize: -> imgExpand.style.innerHTML = ".fitheight img[md5] + img {max-height:#{d.body.clientHeight}px;}" firstRun = From b48130433918a4f44b5ed1cc298be561b9841a7d Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 18 Oct 2011 19:07:40 +0200 Subject: [PATCH 3/6] Less declarations in ui.drag(e) --- 4chan_x.user.js | 16 ++++------------ script.coffee | 16 ++++++++++------ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index c56782b70..4f9661067 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -232,19 +232,11 @@ drag: function(e) { var bottom, left, right, style, top; left = e.clientX - ui.dx; - if (left < 10) { - left = '0'; - } else if (ui.width - left < 10) { - left = null; - } - right = left ? null : 0; top = e.clientY - ui.dy; - if (top < 10) { - top = '0'; - } else if (ui.height - top < 10) { - top = null; - } - bottom = top ? null : 0; + left = left < 10 ? 0 : ui.width - left < 10 ? null : left; + top = top < 10 ? 0 : ui.height - top < 10 ? null : top; + right = left === null ? 0 : null; + bottom = top === null ? 0 : null; style = ui.el.style; style.top = top; style.right = right; diff --git a/script.coffee b/script.coffee index ec8467fff..0db57fb60 100644 --- a/script.coffee +++ b/script.coffee @@ -152,13 +152,17 @@ ui = ui.height = d.body.clientHeight - el.offsetHeight drag: (e) -> left = e.clientX - ui.dx - if left < 10 then left = '0' - else if ui.width - left < 10 then left = null - right = if left then null else 0 top = e.clientY - ui.dy - if top < 10 then top = '0' - else if ui.height - top < 10 then top = null - bottom = if top then null else 0 + left = + if left < 10 then 0 + else if ui.width - left < 10 then null + else left + top = + if top < 10 then 0 + else if ui.height - top < 10 then null + else top + right = if left is null then 0 else null + bottom = if top is null then 0 else null #using null instead of '' is 4% faster #these 4 statements are 40% faster than 1 style.cssText {style} = ui.el From 28e0b834662d25ed4dac53be8a6704bec9780ca4 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 27 Oct 2011 20:45:04 +0200 Subject: [PATCH 4/6] Init features ASAP. --- 4chan_x.user.js | 132 +++++++++++++++++++++++++----------------------- script.coffee | 125 ++++++++++++++++++++++++--------------------- 2 files changed, 138 insertions(+), 119 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 2d257d664..a913b3611 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -61,7 +61,7 @@ */ (function() { - var $, $$, DAY, Favicon, HOUR, MINUTE, Main, NAMESPACE, QR, SECOND, Time, anonymize, conf, config, d, expandComment, expandThread, filter, firstRun, flatten, g, getTitle, imgExpand, imgGif, imgHover, imgPreloading, key, keybinds, log, nav, options, pathname, quoteBacklink, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, temp, threadHiding, threadStats, threading, titlePost, ui, unread, updater, val, watcher; + var $, $$, DAY, Favicon, HOUR, MINUTE, Main, NAMESPACE, QR, SECOND, Time, anonymize, conf, config, d, expandComment, expandThread, filter, firstRun, flatten, g, getTitle, imgExpand, imgGif, imgHover, imgPreloading, key, keybinds, log, nav, options, 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: { @@ -502,19 +502,6 @@ val = conf[key]; conf[key] = $.get(key, val); } - pathname = location.pathname.substring(1).split('/'); - g.BOARD = pathname[0], temp = pathname[1]; - if (temp === 'res') { - g.REPLY = temp; - g.THREAD_ID = pathname[2]; - } else { - g.PAGENUM = parseInt(temp) || 0; - } - g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); - g.chanOffset = 5 - new Date().getTimezoneOffset() / 60; - if ($.isDST()) { - g.chanOffset--; - } $$ = function(selector, root) { if (root == null) { root = d.body; @@ -688,7 +675,7 @@ } }, toggle: function(thread) { - var a, backlink, num, prev, table, threadID, _i, _len, _ref, _ref2, _results; + var a, backlink, num, pathname, prev, table, threadID, _i, _len, _ref, _ref2, _results; threadID = thread.firstChild.id; pathname = "/" + g.BOARD + "/res/" + threadID; a = $('.omittedposts', thread); @@ -1803,7 +1790,7 @@ init: function() { var a, hiddenThreads, op, thread, _i, _len, _ref, _results; hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); - _ref = $$('div.thread'); + _ref = $$('.thread'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { thread = _ref[_i]; @@ -2188,15 +2175,20 @@ }; Time = { init: function() { + var chanOffset; Time.foo(); + chanOffset = 5 - new Date().getTimezoneOffset() / 60; + if ($.isDST()) { + chanOffset--; + } this.parse = Date.parse('10/11/11(Tue)18:53') ? function(node) { - return new Date(Date.parse(node.textContent) + g.chanOffset * HOUR); + return new Date(Date.parse(node.textContent) + 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); + hour = chanOffset + Number(hour); return new Date(year, month, day, hour, min); }; return g.callbacks.push(Time.node); @@ -2397,7 +2389,7 @@ return this.classList.toggle('inlined'); }, add: function(q, id) { - var el, inline, root, threadID; + var el, inline, pathname, root, threadID; root = q.parentNode.nodeName === 'FONT' ? q.parentNode : q.nextSibling ? q.nextSibling : q; if (el = $.id(id)) { inline = quoteInline.table(id, el.innerHTML); @@ -2961,24 +2953,25 @@ }; Main = { init: function() { - var cutoff, hiddenThreads, id, lastChecked, nodes, now, timestamp, _ref; - $.unbind(document, 'DOMContentLoaded', Main.init); + var cutoff, hiddenThreads, id, lastChecked, now, pathname, reqUpdate, temp, timestamp, _ref; if (location.hostname === 'sys.4chan.org') { QR.sys(); return; } - if (conf['404 Redirect'] && d.title === '4chan - 404' && /^\d+$/.test(g.THREAD_ID)) { - redirect(); - return; - } - if (!$('#navtopr')) { - return; - } $.bind(window, 'message', Main.message); - Favicon.init(); + pathname = location.pathname.substring(1).split('/'); + g.BOARD = pathname[0], temp = pathname[1]; + if (temp === 'res') { + g.REPLY = temp; + g.THREAD_ID = pathname[2]; + } else { + g.PAGENUM = parseInt(temp) || 0; + } + g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); lastChecked = $.get('lastChecked', 0); now = Date.now(); - if (lastChecked < now - 1 * DAY) { + reqUpdate = lastChecked < now - 1 * DAY; + if (reqUpdate) { $.set('lastChecked', now); cutoff = now - 7 * DAY; hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); @@ -2998,19 +2991,14 @@ $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); } - $.addStyle(Main.css); - threading.init(); if (conf['Filter']) { filter.init(); } if (conf['Reply Hiding']) { replyHiding.init(); } - if (conf['Image Expansion']) { - imgExpand.init(); - } - if (conf['Image Auto-Gif']) { - imgGif.init(); + if (conf['Anonymize']) { + anonymize.init(); } if (conf['Time Formatting']) { Time.init(); @@ -3018,18 +3006,12 @@ if (conf['Sauce']) { sauce.init(); } - if (conf['Reveal Spoilers'] && $('.postarea label')) { - revealSpoilers.init(); - } - if (conf['Anonymize']) { - anonymize.init(); + if (conf['Image Auto-Gif']) { + imgGif.init(); } if (conf['Image Hover']) { imgHover.init(); } - if (conf['Quick Reply']) { - QR.init(); - } if (conf['Report Button']) { reportButton.init(); } @@ -3045,6 +3027,39 @@ if (conf['Indicate OP quote']) { quoteOP.init(); } + if (g.REPLY) { + if (conf['Image Preloading']) { + imgPreloading.init(); + } + } + if (d.body) { + return Main.onLoad(); + } else { + return $.bind(d, 'DOMContentLoaded', Main.onLoad); + } + }, + onLoad: function() { + var nodes; + $.unbind(document, 'DOMContentLoaded', Main.onLoad); + if (conf['404 Redirect'] && d.title === '4chan - 404' && /^\d+$/.test(g.THREAD_ID)) { + redirect(); + return; + } + if (!$('#navtopr')) { + return; + } + $.addStyle(Main.css); + threading.init(); + Favicon.init(); + if (conf['Image Expansion']) { + imgExpand.init(); + } + if (conf['Reveal Spoilers'] && $('.postarea label')) { + revealSpoilers.init(); + } + if (conf['Quick Reply']) { + QR.init(); + } if (conf['Thread Watcher']) { watcher.init(); } @@ -3055,34 +3070,31 @@ if (conf['Thread Updater']) { updater.init(); } - if (conf['Image Preloading']) { - imgPreloading.init(); - } - if (conf['Post in Title']) { - titlePost.init(); - } if (conf['Thread Stats']) { threadStats.init(); } - if (conf['Unread Count']) { - unread.init(); - } if (conf['Reply Navigation']) { nav.init(); } + if (conf['Post in Title']) { + titlePost.init(); + } + if (conf['Unread Count']) { + unread.init(); + } } else { if (conf['Thread Hiding']) { threadHiding.init(); } - if (conf['Index Navigation']) { - nav.init(); - } if (conf['Thread Expansion']) { expandThread.init(); } if (conf['Comment Expansion']) { expandComment.init(); } + if (conf['Index Navigation']) { + nav.init(); + } } nodes = $$('.op, a + table'); g.callbacks.forEach(function(callback) { @@ -3380,9 +3392,5 @@ }\ ' }; - if (d.body) { - Main.init(); - } else { - $.bind(d, 'DOMContentLoaded', Main.init); - } + Main.init(); }).call(this); diff --git a/script.coffee b/script.coffee index ec126ce42..7ef332b3a 100644 --- a/script.coffee +++ b/script.coffee @@ -374,20 +374,6 @@ else for key, val of conf conf[key] = $.get key, val -pathname = location.pathname.substring(1).split('/') -[g.BOARD, temp] = pathname -if temp is 'res' - g.REPLY = temp - g.THREAD_ID = pathname[2] -else - g.PAGENUM = parseInt(temp) or 0 - -g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {} -# GMT -8 is given as +480; would GMT +8 be -480 ? -g.chanOffset = 5 - new Date().getTimezoneOffset() / 60 -# 4chan = EST = GMT -5 -g.chanOffset-- if $.isDST() - $$ = (selector, root=d.body) -> Array::slice.call root.querySelectorAll selector @@ -1359,7 +1345,7 @@ threading = threadHiding = init: -> hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} - for thread in $$ 'div.thread' + for thread in $$ '.thread' op = thread.firstChild a = $.el 'a', textContent: '[ - ]' @@ -1669,16 +1655,21 @@ Time = init: -> Time.foo() + # GMT -8 is given as +480; would GMT +8 be -480 ? + chanOffset = 5 - new Date().getTimezoneOffset() / 60 + # 4chan = EST = GMT -5 + chanOffset-- if $.isDST() + @parse = if Date.parse '10/11/11(Tue)18:53' - (node) -> new Date Date.parse(node.textContent) + g.chanOffset*HOUR + (node) -> new Date Date.parse(node.textContent) + 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 + hour = chanOffset + Number hour new Date year, month, day, hour, min g.callbacks.push Time.node @@ -2245,22 +2236,27 @@ firstRun = Main = init: -> - $.unbind document, 'DOMContentLoaded', Main.init if location.hostname is 'sys.4chan.org' QR.sys() return - if conf['404 Redirect'] and d.title is '4chan - 404' and /^\d+$/.test g.THREAD_ID - redirect() - return - if not $ '#navtopr' - return $.bind window, 'message', Main.message - Favicon.init() + + pathname = location.pathname.substring(1).split('/') + [g.BOARD, temp] = pathname + if temp is 'res' + g.REPLY = temp + g.THREAD_ID = pathname[2] + else + g.PAGENUM = parseInt(temp) or 0 + + g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {} lastChecked = $.get 'lastChecked', 0 now = Date.now() - if lastChecked < now - 1*DAY + reqUpdate = lastChecked < now - 1*DAY + + if reqUpdate $.set 'lastChecked', now cutoff = now - 7*DAY @@ -2277,22 +2273,16 @@ Main = $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies - $.addStyle Main.css #major features - threading.init() - if conf['Filter'] filter.init() if conf['Reply Hiding'] replyHiding.init() - if conf['Image Expansion'] - imgExpand.init() - - if conf['Image Auto-Gif'] - imgGif.init() + if conf['Anonymize'] + anonymize.init() if conf['Time Formatting'] Time.init() @@ -2300,18 +2290,12 @@ Main = if conf['Sauce'] sauce.init() - if conf['Reveal Spoilers'] and $('.postarea label') - revealSpoilers.init() - - if conf['Anonymize'] - anonymize.init() + if conf['Image Auto-Gif'] + imgGif.init() if conf['Image Hover'] imgHover.init() - if conf['Quick Reply'] - QR.init() - if conf['Report Button'] reportButton.init() @@ -2327,6 +2311,38 @@ Main = if conf['Indicate OP quote'] quoteOP.init() + if g.REPLY + if conf['Image Preloading'] + imgPreloading.init() + + + if d.body + Main.onLoad() + else + $.bind d, 'DOMContentLoaded', Main.onLoad + + onLoad: -> + $.unbind document, 'DOMContentLoaded', Main.onLoad + if conf['404 Redirect'] and d.title is '4chan - 404' and /^\d+$/.test g.THREAD_ID + redirect() + return + if not $ '#navtopr' + return + $.addStyle Main.css + threading.init() + Favicon.init() + + + #major features + if conf['Image Expansion'] + imgExpand.init() + + if conf['Reveal Spoilers'] and $('.postarea label') + revealSpoilers.init() + + if conf['Quick Reply'] + QR.init() + if conf['Thread Watcher'] watcher.init() @@ -2337,34 +2353,32 @@ Main = if conf['Thread Updater'] updater.init() - if conf['Image Preloading'] - imgPreloading.init() - - if conf['Post in Title'] - titlePost.init() - if conf['Thread Stats'] threadStats.init() - if conf['Unread Count'] - unread.init() - if conf['Reply Navigation'] nav.init() + if conf['Post in Title'] + titlePost.init() + + if conf['Unread Count'] + unread.init() + else #not reply if conf['Thread Hiding'] threadHiding.init() - if conf['Index Navigation'] - nav.init() - if conf['Thread Expansion'] expandThread.init() if conf['Comment Expansion'] expandComment.init() + if conf['Index Navigation'] + nav.init() + + nodes = $$ '.op, a + table' g.callbacks.forEach (callback) -> try @@ -2652,7 +2666,4 @@ Main = } ' -if d.body - Main.init() -else - $.bind d, 'DOMContentLoaded', Main.init +Main.init() From 0400ecb42fea5e1ba1c3f7de823239ae2ee900e9 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 27 Oct 2011 22:28:30 +0200 Subject: [PATCH 5/6] We'll need this for the stable branch. --- 4chan_x.user.js | 6 +++--- script.coffee | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a913b3611..5f760e9db 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2953,7 +2953,7 @@ }; Main = { init: function() { - var cutoff, hiddenThreads, id, lastChecked, now, pathname, reqUpdate, temp, timestamp, _ref; + var cutoff, hiddenThreads, id, lastChecked, now, pathname, temp, timestamp, _ref; if (location.hostname === 'sys.4chan.org') { QR.sys(); return; @@ -2970,8 +2970,8 @@ g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); lastChecked = $.get('lastChecked', 0); now = Date.now(); - reqUpdate = lastChecked < now - 1 * DAY; - if (reqUpdate) { + Main.reqUpdate = lastChecked < now - 1 * DAY; + if (Main.reqUpdate) { $.set('lastChecked', now); cutoff = now - 7 * DAY; hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); diff --git a/script.coffee b/script.coffee index 7ef332b3a..d1fb56071 100644 --- a/script.coffee +++ b/script.coffee @@ -2254,9 +2254,9 @@ Main = lastChecked = $.get 'lastChecked', 0 now = Date.now() - reqUpdate = lastChecked < now - 1*DAY + Main.reqUpdate = lastChecked < now - 1*DAY - if reqUpdate + if Main.reqUpdate $.set 'lastChecked', now cutoff = now - 7*DAY From 71cac4e7f600a0c037af317a6305018ba6f5f175 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 28 Oct 2011 17:32:38 +0200 Subject: [PATCH 6/6] QR error checking fix. --- 4chan_x.user.js | 9 +++++++-- script.coffee | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 5f760e9db..54a1cd44b 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1718,6 +1718,7 @@ }, sys: function() { var recaptcha; + $.unbind(d, 'DOMContentLoaded', QR.sys); if (recaptcha = $('#recaptcha_response_field')) { $.bind(recaptcha, 'keydown', QR.keydown); return; @@ -2955,7 +2956,11 @@ init: function() { var cutoff, hiddenThreads, id, lastChecked, now, pathname, temp, timestamp, _ref; if (location.hostname === 'sys.4chan.org') { - QR.sys(); + if (d.body) { + QR.sys(); + } else { + $.bind(d, 'DOMContentLoaded', QR.sys); + } return; } $.bind(window, 'message', Main.message); @@ -3040,7 +3045,7 @@ }, onLoad: function() { var nodes; - $.unbind(document, 'DOMContentLoaded', Main.onLoad); + $.unbind(d, 'DOMContentLoaded', Main.onLoad); if (conf['404 Redirect'] && d.title === '4chan - 404' && /^\d+$/.test(g.THREAD_ID)) { redirect(); return; diff --git a/script.coffee b/script.coffee index d1fb56071..2c17ef31a 100644 --- a/script.coffee +++ b/script.coffee @@ -1288,6 +1288,7 @@ QR = if $('img.favicon', op).src is Favicon.empty watcher.watch op, id sys: -> + $.unbind d, 'DOMContentLoaded', QR.sys if recaptcha = $ '#recaptcha_response_field' #post reporting $.bind recaptcha, 'keydown', QR.keydown return @@ -2237,7 +2238,10 @@ firstRun = Main = init: -> if location.hostname is 'sys.4chan.org' - QR.sys() + if d.body + QR.sys() + else + $.bind d, 'DOMContentLoaded', QR.sys return $.bind window, 'message', Main.message @@ -2322,7 +2326,7 @@ Main = $.bind d, 'DOMContentLoaded', Main.onLoad onLoad: -> - $.unbind document, 'DOMContentLoaded', Main.onLoad + $.unbind d, 'DOMContentLoaded', Main.onLoad if conf['404 Redirect'] and d.title is '4chan - 404' and /^\d+$/.test g.THREAD_ID redirect() return