Merge pull request #336 from MayhemYDG/init

Init ASAP, simplify declarations in ui.drag, remove unnecessary (e)s
This commit is contained in:
James Campos 2011-10-28 09:11:46 -07:00
commit 9e1adc596d
2 changed files with 197 additions and 174 deletions

View File

@ -61,7 +61,7 @@
*/ */
(function() { (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; var __slice = Array.prototype.slice;
config = { config = {
main: { main: {
@ -232,19 +232,11 @@
drag: function(e) { drag: function(e) {
var bottom, left, right, style, top; var bottom, left, right, style, top;
left = e.clientX - ui.dx; 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; top = e.clientY - ui.dy;
if (top < 10) { left = left < 10 ? 0 : ui.width - left < 10 ? null : left;
top = '0'; top = top < 10 ? 0 : ui.height - top < 10 ? null : top;
} else if (ui.height - top < 10) { right = left === null ? 0 : null;
top = null; bottom = top === null ? 0 : null;
}
bottom = top ? null : 0;
style = ui.el.style; style = ui.el.style;
style.top = top; style.top = top;
style.right = right; style.right = right;
@ -275,7 +267,7 @@
return style.right = clientWidth - clientX + 45; return style.right = clientWidth - clientX + 45;
} }
}, },
hoverend: function(e) { hoverend: function() {
return ui.el.parentNode.removeChild(ui.el); return ui.el.parentNode.removeChild(ui.el);
} }
}; };
@ -510,14 +502,6 @@
val = conf[key]; val = conf[key];
conf[key] = $.get(key, val); 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;
}
$$ = function(selector, root) { $$ = function(selector, root) {
if (root == null) { if (root == null) {
root = d.body; root = d.body;
@ -684,14 +668,14 @@
return _results; return _results;
}, },
cb: { cb: {
toggle: function(e) { toggle: function() {
var thread; var thread;
thread = this.parentNode; thread = this.parentNode;
return expandThread.toggle(thread); return expandThread.toggle(thread);
} }
}, },
toggle: function(thread) { 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; threadID = thread.firstChild.id;
pathname = "/" + g.BOARD + "/res/" + threadID; pathname = "/" + g.BOARD + "/res/" + threadID;
a = $('.omittedposts', thread); a = $('.omittedposts', thread);
@ -794,12 +778,12 @@
}); });
}, },
cb: { cb: {
hide: function(e) { hide: function() {
var reply; var reply;
reply = this.parentNode.nextSibling; reply = this.parentNode.nextSibling;
return replyHiding.hide(reply); return replyHiding.hide(reply);
}, },
show: function(e) { show: function() {
var div, table; var div, table;
div = this.parentNode; div = this.parentNode;
table = div.nextSibling; table = div.nextSibling;
@ -1354,7 +1338,7 @@
options.time.call(time); options.time.call(time);
return options.backlink.call(back); return options.backlink.call(back);
}, },
clearHidden: function(e) { clearHidden: function() {
$["delete"]("hiddenReplies/" + g.BOARD + "/"); $["delete"]("hiddenReplies/" + g.BOARD + "/");
$["delete"]("hiddenThreads/" + g.BOARD + "/"); $["delete"]("hiddenThreads/" + g.BOARD + "/");
this.textContent = "hidden: 0"; this.textContent = "hidden: 0";
@ -1370,14 +1354,14 @@
$.set(this.name, key); $.set(this.name, key);
return conf[this.name] = key; return conf[this.name] = key;
}, },
time: function(e) { time: function() {
$.set('time', this.value); $.set('time', this.value);
conf['time'] = this.value; conf['time'] = this.value;
Time.foo(); Time.foo();
Time.date = new Date(); Time.date = new Date();
return $('#timePreview').textContent = Time.funk(Time); return $('#timePreview').textContent = Time.funk(Time);
}, },
backlink: function(e) { backlink: function() {
$.set('backlink', this.value); $.set('backlink', this.value);
conf['backlink'] = this.value; conf['backlink'] = this.value;
return $('#backlinkPreview').textContent = conf['backlink'].replace(/%id/, '123456789'); return $('#backlinkPreview').textContent = conf['backlink'].replace(/%id/, '123456789');
@ -1734,6 +1718,7 @@
}, },
sys: function() { sys: function() {
var recaptcha; var recaptcha;
$.unbind(d, 'DOMContentLoaded', QR.sys);
if (recaptcha = $('#recaptcha_response_field')) { if (recaptcha = $('#recaptcha_response_field')) {
$.bind(recaptcha, 'keydown', QR.keydown); $.bind(recaptcha, 'keydown', QR.keydown);
return; return;
@ -1806,7 +1791,7 @@
init: function() { init: function() {
var a, hiddenThreads, op, thread, _i, _len, _ref, _results; var a, hiddenThreads, op, thread, _i, _len, _ref, _results;
hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {});
_ref = $$('div.thread'); _ref = $$('.thread');
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
thread = _ref[_i]; thread = _ref[_i];
@ -1821,12 +1806,12 @@
return _results; return _results;
}, },
cb: { cb: {
hide: function(e) { hide: function() {
var thread; var thread;
thread = this.parentNode.parentNode; thread = this.parentNode.parentNode;
return threadHiding.hide(thread); return threadHiding.hide(thread);
}, },
show: function(e) { show: function() {
var thread; var thread;
thread = this.parentNode.parentNode; thread = this.parentNode.parentNode;
return threadHiding.show(thread); return threadHiding.show(thread);
@ -2093,10 +2078,10 @@
return _results; return _results;
}, },
cb: { cb: {
toggle: function(e) { toggle: function() {
return watcher.toggle(this.parentNode); return watcher.toggle(this.parentNode);
}, },
x: function(e) { x: function() {
var board, id, _, _ref; var board, id, _, _ref;
_ref = this.nextElementSibling.getAttribute('href').substring(1).split('/'), board = _ref[0], _ = _ref[1], id = _ref[2]; _ref = this.nextElementSibling.getAttribute('href').substring(1).split('/'), board = _ref[0], _ = _ref[1], id = _ref[2];
return watcher.unwatch(board, id); return watcher.unwatch(board, id);
@ -2191,15 +2176,20 @@
}; };
Time = { Time = {
init: function() { init: function() {
var chanOffset;
Time.foo(); Time.foo();
chanOffset = 5 - new Date().getTimezoneOffset() / 60;
if ($.isDST()) {
chanOffset--;
}
this.parse = Date.parse('10/11/11(Tue)18:53') ? function(node) { 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) { } : function(node) {
var day, hour, min, month, year, _, _ref; 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]; _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; year = "20" + year;
month -= 1; month -= 1;
hour = g.chanOffset + Number(hour); hour = chanOffset + Number(hour);
return new Date(year, month, day, hour, min); return new Date(year, month, day, hour, min);
}; };
return g.callbacks.push(Time.node); return g.callbacks.push(Time.node);
@ -2400,7 +2390,7 @@
return this.classList.toggle('inlined'); return this.classList.toggle('inlined');
}, },
add: function(q, id) { 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; root = q.parentNode.nodeName === 'FONT' ? q.parentNode : q.nextSibling ? q.nextSibling : q;
if (el = $.id(id)) { if (el = $.id(id)) {
inline = quoteInline.table(id, el.innerHTML); inline = quoteInline.table(id, el.innerHTML);
@ -2658,7 +2648,7 @@
return Favicon.update(); return Favicon.update();
} }
}, },
scroll: function(e) { scroll: function() {
var bottom, height, i, reply, _len, _ref; var bottom, height, i, reply, _len, _ref;
updater.focus = true; updater.focus = true;
height = d.body.clientHeight; height = d.body.clientHeight;
@ -2765,7 +2755,7 @@
return $.bind(thumb, 'mouseout', ui.hoverend); return $.bind(thumb, 'mouseout', ui.hoverend);
}); });
}, },
mouseover: function(e) { mouseover: function() {
ui.el = $.el('img', { ui.el = $.el('img', {
id: 'iHover', id: 'iHover',
src: this.parentNode.href src: this.parentNode.href
@ -2856,7 +2846,7 @@
e.preventDefault(); e.preventDefault();
return imgExpand.toggle(this); return imgExpand.toggle(this);
}, },
all: function(e) { all: function() {
var thumb, _i, _j, _len, _len2, _ref, _ref2, _results, _results2; var thumb, _i, _j, _len, _len2, _ref, _ref2, _results, _results2;
imgExpand.on = this.checked; imgExpand.on = this.checked;
if (imgExpand.on) { if (imgExpand.on) {
@ -2877,7 +2867,7 @@
return _results2; return _results2;
} }
}, },
typeChange: function(e) { typeChange: function() {
var klass; var klass;
switch (this.value) { switch (this.value) {
case 'full': case 'full':
@ -2923,13 +2913,13 @@
thumb.hidden = true; thumb.hidden = true;
return $.add(a, img); return $.add(a, img);
}, },
error: function(e) { error: function() {
var req, thumb; var req, thumb;
thumb = this.previousSibling; thumb = this.previousSibling;
imgExpand.contract(thumb); imgExpand.contract(thumb);
if (navigator.appName !== 'Opera') { if (navigator.appName !== 'Opera') {
req = $.ajax(this.src, null, 'head'); req = $.ajax(this.src, null, 'head');
return req.onreadystatechange = function(e) { return req.onreadystatechange = function() {
if (this.status !== 404) { if (this.status !== 404) {
return setTimeout(imgExpand.retry, 10000, thumb); return setTimeout(imgExpand.retry, 10000, thumb);
} }
@ -2966,7 +2956,7 @@
form = $('body > form'); form = $('body > form');
return $.prepend(form, controls); return $.prepend(form, controls);
}, },
resize: function(e) { resize: function() {
return imgExpand.style.innerHTML = ".fitheight img[md5] + img {max-height:" + d.body.clientHeight + "px;}"; return imgExpand.style.innerHTML = ".fitheight img[md5] + img {max-height:" + d.body.clientHeight + "px;}";
} }
}; };
@ -2992,30 +2982,29 @@
}; };
Main = { Main = {
init: function() { init: function() {
var cutoff, hiddenThreads, id, lastChecked, nodes, now, timestamp, tzOffset, _ref; var cutoff, hiddenThreads, id, lastChecked, now, pathname, temp, timestamp, _ref;
$.unbind(document, 'DOMContentLoaded', Main.init);
if (location.hostname === 'sys.4chan.org') { if (location.hostname === 'sys.4chan.org') {
QR.sys(); if (d.body) {
return; QR.sys();
} } else {
if (conf['404 Redirect'] && d.title === '4chan - 404' && /^\d+$/.test(g.THREAD_ID)) { $.bind(d, 'DOMContentLoaded', QR.sys);
redirect(); }
return;
}
if (!$('#navtopr')) {
return; return;
} }
$.bind(window, 'message', Main.message); $.bind(window, 'message', Main.message);
Favicon.init(); pathname = location.pathname.substring(1).split('/');
g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); g.BOARD = pathname[0], temp = pathname[1];
tzOffset = (new Date()).getTimezoneOffset() / 60; if (temp === 'res') {
g.chanOffset = 5 - tzOffset; g.REPLY = temp;
if ($.isDST()) { g.THREAD_ID = pathname[2];
g.chanOffset--; } else {
g.PAGENUM = parseInt(temp) || 0;
} }
g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {});
lastChecked = $.get('lastChecked', 0); lastChecked = $.get('lastChecked', 0);
now = Date.now(); now = Date.now();
if (lastChecked < now - 1 * DAY) { Main.reqUpdate = lastChecked < now - 1 * DAY;
if (Main.reqUpdate) {
$.set('lastChecked', now); $.set('lastChecked', now);
cutoff = now - 7 * DAY; cutoff = now - 7 * DAY;
hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {});
@ -3035,19 +3024,14 @@
$.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads);
$.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies);
} }
$.addStyle(Main.css);
threading.init();
if (conf['Filter']) { if (conf['Filter']) {
filter.init(); filter.init();
} }
if (conf['Reply Hiding']) { if (conf['Reply Hiding']) {
replyHiding.init(); replyHiding.init();
} }
if (conf['Image Expansion']) { if (conf['Anonymize']) {
imgExpand.init(); anonymize.init();
}
if (conf['Image Auto-Gif']) {
imgGif.init();
} }
if (conf['Time Formatting']) { if (conf['Time Formatting']) {
Time.init(); Time.init();
@ -3055,18 +3039,12 @@
if (conf['Sauce']) { if (conf['Sauce']) {
sauce.init(); sauce.init();
} }
if (conf['Reveal Spoilers'] && $('.postarea label')) { if (conf['Image Auto-Gif']) {
revealSpoilers.init(); imgGif.init();
}
if (conf['Anonymize']) {
anonymize.init();
} }
if (conf['Image Hover']) { if (conf['Image Hover']) {
imgHover.init(); imgHover.init();
} }
if (conf['Quick Reply']) {
QR.init();
}
if (conf['Report Button']) { if (conf['Report Button']) {
reportButton.init(); reportButton.init();
} }
@ -3082,6 +3060,39 @@
if (conf['Indicate OP quote']) { if (conf['Indicate OP quote']) {
quoteOP.init(); 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(d, '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']) { if (conf['Thread Watcher']) {
watcher.init(); watcher.init();
} }
@ -3092,34 +3103,31 @@
if (conf['Thread Updater']) { if (conf['Thread Updater']) {
updater.init(); updater.init();
} }
if (conf['Image Preloading']) {
imgPreloading.init();
}
if (conf['Post in Title']) {
titlePost.init();
}
if (conf['Thread Stats']) { if (conf['Thread Stats']) {
threadStats.init(); threadStats.init();
} }
if (conf['Unread Count']) {
unread.init();
}
if (conf['Reply Navigation']) { if (conf['Reply Navigation']) {
nav.init(); nav.init();
} }
if (conf['Post in Title']) {
titlePost.init();
}
if (conf['Unread Count']) {
unread.init();
}
} else { } else {
if (conf['Thread Hiding']) { if (conf['Thread Hiding']) {
threadHiding.init(); threadHiding.init();
} }
if (conf['Index Navigation']) {
nav.init();
}
if (conf['Thread Expansion']) { if (conf['Thread Expansion']) {
expandThread.init(); expandThread.init();
} }
if (conf['Comment Expansion']) { if (conf['Comment Expansion']) {
expandComment.init(); expandComment.init();
} }
if (conf['Index Navigation']) {
nav.init();
}
} }
nodes = $$('.op, a + table'); nodes = $$('.op, a + table');
g.callbacks.forEach(function(callback) { g.callbacks.forEach(function(callback) {
@ -3417,9 +3425,5 @@
}\ }\
' '
}; };
if (d.body) { Main.init();
Main.init();
} else {
$.bind(d, 'DOMContentLoaded', Main.init);
}
}).call(this); }).call(this);

View File

@ -152,13 +152,17 @@ ui =
ui.height = d.body.clientHeight - el.offsetHeight ui.height = d.body.clientHeight - el.offsetHeight
drag: (e) -> drag: (e) ->
left = e.clientX - ui.dx 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 top = e.clientY - ui.dy
if top < 10 then top = '0' left =
else if ui.height - top < 10 then top = null if left < 10 then 0
bottom = if top then null else 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 #using null instead of '' is 4% faster
#these 4 statements are 40% faster than 1 style.cssText #these 4 statements are 40% faster than 1 style.cssText
{style} = ui.el {style} = ui.el
@ -197,7 +201,7 @@ ui =
style.left = null style.left = null
style.right = clientWidth - clientX + 45 style.right = clientWidth - clientX + 45
hoverend: (e) -> hoverend: ->
ui.el.parentNode.removeChild ui.el ui.el.parentNode.removeChild ui.el
### ###
@ -370,14 +374,6 @@ else
for key, val of conf for key, val of conf
conf[key] = $.get key, val 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
$$ = (selector, root=d.body) -> $$ = (selector, root=d.body) ->
Array::slice.call root.querySelectorAll selector Array::slice.call root.querySelectorAll selector
@ -480,7 +476,7 @@ expandThread =
$.replace span, a $.replace span, a
cb: cb:
toggle: (e) -> toggle: ->
thread = @parentNode thread = @parentNode
expandThread.toggle thread expandThread.toggle thread
@ -560,11 +556,11 @@ replyHiding =
replyHiding.hide reply replyHiding.hide reply
cb: cb:
hide: (e) -> hide: ->
reply = @parentNode.nextSibling reply = @parentNode.nextSibling
replyHiding.hide reply replyHiding.hide reply
show: (e) -> show: ->
div = @parentNode div = @parentNode
table = div.nextSibling table = div.nextSibling
replyHiding.show table replyHiding.show table
@ -987,7 +983,7 @@ options =
options.time.call time options.time.call time
options.backlink.call back options.backlink.call back
clearHidden: (e) -> clearHidden: ->
#'hidden' might be misleading; it's the number of IDs we're *looking* for, #'hidden' might be misleading; it's the number of IDs we're *looking* for,
# not the number of posts actually hidden on the page. # not the number of posts actually hidden on the page.
$.delete "hiddenReplies/#{g.BOARD}/" $.delete "hiddenReplies/#{g.BOARD}/"
@ -1001,13 +997,13 @@ options =
@value = key @value = key
$.set @name, key $.set @name, key
conf[@name] = key conf[@name] = key
time: (e) -> time: ->
$.set 'time', @value $.set 'time', @value
conf['time'] = @value conf['time'] = @value
Time.foo() Time.foo()
Time.date = new Date() Time.date = new Date()
$('#timePreview').textContent = Time.funk Time $('#timePreview').textContent = Time.funk Time
backlink: (e) -> backlink: ->
$.set 'backlink', @value $.set 'backlink', @value
conf['backlink'] = @value conf['backlink'] = @value
$('#backlinkPreview').textContent = conf['backlink'].replace /%id/, '123456789' $('#backlinkPreview').textContent = conf['backlink'].replace /%id/, '123456789'
@ -1292,6 +1288,7 @@ QR =
if $('img.favicon', op).src is Favicon.empty if $('img.favicon', op).src is Favicon.empty
watcher.watch op, id watcher.watch op, id
sys: -> sys: ->
$.unbind d, 'DOMContentLoaded', QR.sys
if recaptcha = $ '#recaptcha_response_field' #post reporting if recaptcha = $ '#recaptcha_response_field' #post reporting
$.bind recaptcha, 'keydown', QR.keydown $.bind recaptcha, 'keydown', QR.keydown
return return
@ -1349,7 +1346,7 @@ threading =
threadHiding = threadHiding =
init: -> init: ->
hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {}
for thread in $$ 'div.thread' for thread in $$ '.thread'
op = thread.firstChild op = thread.firstChild
a = $.el 'a', a = $.el 'a',
textContent: '[ - ]' textContent: '[ - ]'
@ -1360,10 +1357,10 @@ threadHiding =
threadHiding.hideHide thread threadHiding.hideHide thread
cb: cb:
hide: (e) -> hide: ->
thread = @parentNode.parentNode thread = @parentNode.parentNode
threadHiding.hide thread threadHiding.hide thread
show: (e) -> show: ->
thread = @parentNode.parentNode thread = @parentNode.parentNode
threadHiding.show thread threadHiding.show thread
@ -1589,9 +1586,9 @@ watcher =
favicon.src = Favicon.empty favicon.src = Favicon.empty
cb: cb:
toggle: (e) -> toggle: ->
watcher.toggle @parentNode watcher.toggle @parentNode
x: (e) -> x: ->
[board, _, id] = @nextElementSibling [board, _, id] = @nextElementSibling
.getAttribute('href').substring(1).split('/') .getAttribute('href').substring(1).split('/')
watcher.unwatch board, id watcher.unwatch board, id
@ -1659,16 +1656,21 @@ Time =
init: -> init: ->
Time.foo() 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 = @parse =
if Date.parse '10/11/11(Tue)18:53' 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 else # Firefox the Archaic cannot parse 4chan's time
(node) -> (node) ->
[_, month, day, year, hour, min] = [_, month, day, year, hour, min] =
node.textContent.match /(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/ node.textContent.match /(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/
year = "20#{year}" year = "20#{year}"
month -= 1 #months start at 0 month -= 1 #months start at 0
hour = g.chanOffset + Number hour hour = chanOffset + Number hour
new Date year, month, day, hour, min new Date year, month, day, hour, min
g.callbacks.push Time.node g.callbacks.push Time.node
@ -1964,7 +1966,7 @@ unread =
if unread.replies.length is 1 if unread.replies.length is 1
Favicon.update() Favicon.update()
scroll: (e) -> scroll: ->
updater.focus = true updater.focus = true
height = d.body.clientHeight height = d.body.clientHeight
for reply, i in unread.replies for reply, i in unread.replies
@ -2036,7 +2038,7 @@ imgHover =
$.bind thumb, 'mouseover', imgHover.mouseover $.bind thumb, 'mouseover', imgHover.mouseover
$.bind thumb, 'mousemove', ui.hover $.bind thumb, 'mousemove', ui.hover
$.bind thumb, 'mouseout', ui.hoverend $.bind thumb, 'mouseout', ui.hoverend
mouseover: (e) -> mouseover: ->
ui.el = $.el 'img' ui.el = $.el 'img'
id: 'iHover' id: 'iHover'
src: @parentNode.href src: @parentNode.href
@ -2093,7 +2095,7 @@ imgExpand =
return if e.shiftKey or e.altKey or e.ctrlKey or e.button isnt 0 return if e.shiftKey or e.altKey or e.ctrlKey or e.button isnt 0
e.preventDefault() e.preventDefault()
imgExpand.toggle @ imgExpand.toggle @
all: (e) -> all: ->
imgExpand.on = @checked imgExpand.on = @checked
if imgExpand.on #expand if imgExpand.on #expand
for thumb in $$ 'img[md5]:not([hidden])' for thumb in $$ 'img[md5]:not([hidden])'
@ -2101,7 +2103,7 @@ imgExpand =
else #contract else #contract
for thumb in $$ 'img[md5][hidden]' for thumb in $$ 'img[md5][hidden]'
imgExpand.contract thumb imgExpand.contract thumb
typeChange: (e) -> typeChange: ->
switch @value switch @value
when 'full' when 'full'
klass = '' klass = ''
@ -2136,13 +2138,13 @@ imgExpand =
thumb.hidden = true thumb.hidden = true
$.add a, img $.add a, img
error: (e) -> error: ->
thumb = @previousSibling thumb = @previousSibling
imgExpand.contract thumb imgExpand.contract thumb
#navigator.online is not x-browser/os yet #navigator.online is not x-browser/os yet
if navigator.appName isnt 'Opera' if navigator.appName isnt 'Opera'
req = $.ajax @src, null, 'head' 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 else unless g.dead
setTimeout imgExpand.retry, 10000, thumb setTimeout imgExpand.retry, 10000, thumb
retry: (thumb) -> retry: (thumb) ->
@ -2168,7 +2170,7 @@ imgExpand =
form = $ 'body > form' form = $ 'body > form'
$.prepend form, controls $.prepend form, controls
resize: (e) -> resize: ->
imgExpand.style.innerHTML = ".fitheight img[md5] + img {max-height:#{d.body.clientHeight}px;}" imgExpand.style.innerHTML = ".fitheight img[md5] + img {max-height:#{d.body.clientHeight}px;}"
firstRun = firstRun =
@ -2253,28 +2255,30 @@ firstRun =
Main = Main =
init: -> init: ->
$.unbind document, 'DOMContentLoaded', Main.init
if location.hostname is 'sys.4chan.org' if location.hostname is 'sys.4chan.org'
QR.sys() if d.body
return QR.sys()
if conf['404 Redirect'] and d.title is '4chan - 404' and /^\d+$/.test g.THREAD_ID else
redirect() $.bind d, 'DOMContentLoaded', QR.sys
return
if not $ '#navtopr'
return return
$.bind window, 'message', Main.message $.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}/", {} 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 lastChecked = $.get 'lastChecked', 0
now = Date.now() now = Date.now()
if lastChecked < now - 1*DAY Main.reqUpdate = lastChecked < now - 1*DAY
if Main.reqUpdate
$.set 'lastChecked', now $.set 'lastChecked', now
cutoff = now - 7*DAY cutoff = now - 7*DAY
@ -2291,22 +2295,16 @@ Main =
$.set "hiddenThreads/#{g.BOARD}/", hiddenThreads $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads
$.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies
$.addStyle Main.css
#major features #major features
threading.init()
if conf['Filter'] if conf['Filter']
filter.init() filter.init()
if conf['Reply Hiding'] if conf['Reply Hiding']
replyHiding.init() replyHiding.init()
if conf['Image Expansion'] if conf['Anonymize']
imgExpand.init() anonymize.init()
if conf['Image Auto-Gif']
imgGif.init()
if conf['Time Formatting'] if conf['Time Formatting']
Time.init() Time.init()
@ -2314,18 +2312,12 @@ Main =
if conf['Sauce'] if conf['Sauce']
sauce.init() sauce.init()
if conf['Reveal Spoilers'] and $('.postarea label') if conf['Image Auto-Gif']
revealSpoilers.init() imgGif.init()
if conf['Anonymize']
anonymize.init()
if conf['Image Hover'] if conf['Image Hover']
imgHover.init() imgHover.init()
if conf['Quick Reply']
QR.init()
if conf['Report Button'] if conf['Report Button']
reportButton.init() reportButton.init()
@ -2341,6 +2333,38 @@ Main =
if conf['Indicate OP quote'] if conf['Indicate OP quote']
quoteOP.init() quoteOP.init()
if g.REPLY
if conf['Image Preloading']
imgPreloading.init()
if d.body
Main.onLoad()
else
$.bind d, 'DOMContentLoaded', Main.onLoad
onLoad: ->
$.unbind d, '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'] if conf['Thread Watcher']
watcher.init() watcher.init()
@ -2351,34 +2375,32 @@ Main =
if conf['Thread Updater'] if conf['Thread Updater']
updater.init() updater.init()
if conf['Image Preloading']
imgPreloading.init()
if conf['Post in Title']
titlePost.init()
if conf['Thread Stats'] if conf['Thread Stats']
threadStats.init() threadStats.init()
if conf['Unread Count']
unread.init()
if conf['Reply Navigation'] if conf['Reply Navigation']
nav.init() nav.init()
if conf['Post in Title']
titlePost.init()
if conf['Unread Count']
unread.init()
else #not reply else #not reply
if conf['Thread Hiding'] if conf['Thread Hiding']
threadHiding.init() threadHiding.init()
if conf['Index Navigation']
nav.init()
if conf['Thread Expansion'] if conf['Thread Expansion']
expandThread.init() expandThread.init()
if conf['Comment Expansion'] if conf['Comment Expansion']
expandComment.init() expandComment.init()
if conf['Index Navigation']
nav.init()
nodes = $$ '.op, a + table' nodes = $$ '.op, a + table'
g.callbacks.forEach (callback) -> g.callbacks.forEach (callback) ->
try try
@ -2666,7 +2688,4 @@ Main =
} }
' '
if d.body Main.init()
Main.init()
else
$.bind d, 'DOMContentLoaded', Main.init