From 9da579f2165f8936f2dfda9d011bf699dedf08a0 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 13 Nov 2011 10:43:18 -0800 Subject: [PATCH] coffee-script 1.1.3 --- 4chan_x.user.js | 585 ++++++++++++++++++------------------------------ 1 file changed, 214 insertions(+), 371 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 5ab7f4b2f..8c707cc43 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -64,6 +64,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, quoteBacklink, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, strikethroughQuotes, threadHiding, threadStats, threading, titlePost, ui, unread, updater, val, watcher; var __slice = Array.prototype.slice; + config = { main: { Enhancing: { @@ -162,11 +163,13 @@ 'Interval': 30 } }; + if (typeof console !== "undefined" && console !== null) { log = function(arg) { return console.log(arg); }; } + if (!Object.keys) { Object.keys = function(o) { var key, _results; @@ -177,7 +180,9 @@ return _results; }; } + conf = {}; + (flatten = function(parent, obj) { var key, val, _results; if (obj.length) { @@ -197,15 +202,23 @@ return conf[parent] = obj; } })(null, config); + NAMESPACE = 'AEOS.4chan_x.'; + SECOND = 1000; + MINUTE = 60 * SECOND; + HOUR = 60 * MINUTE; + DAY = 24 * HOUR; + d = document; + g = { callbacks: [] }; + ui = { dialog: function(id, position, html) { var el, saved, _ref; @@ -273,17 +286,18 @@ return ui.el.parentNode.removeChild(ui.el); } }; + /* loosely follows the jquery api: http://api.jquery.com/ not chainable */ + $ = function(selector, root) { - if (root == null) { - root = d.body; - } + if (root == null) root = d.body; return root.querySelector(selector); }; + $.extend = function(object, properties) { var key, val; for (key in properties) { @@ -292,6 +306,7 @@ } return object; }; + $.extend($, { id: function(id) { return d.getElementById(id); @@ -306,9 +321,7 @@ }, ajax: function(url, cb, type) { var r; - if (type == null) { - type = 'get'; - } + if (type == null) type = 'get'; r = new XMLHttpRequest(); r.onload = cb; r.open(type, url, true); @@ -357,9 +370,7 @@ return style; }, x: function(path, root) { - if (root == null) { - root = d.body; - } + if (root == null) root = d.body; return d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue; }, tn: function(s) { @@ -399,9 +410,7 @@ el: function(tag, properties) { var el; el = d.createElement(tag); - if (properties) { - $.extend(el, properties); - } + if (properties) $.extend(el, properties); return el; }, on: function(el, eventType, handler) { @@ -422,45 +431,35 @@ 0200 EST (UTC-05) = 0700 UTC 0200 EDT (UTC-04) = 0600 UTC - */ + */ var D, date, day, hours, month, sunday; D = new Date(); date = D.getUTCDate(); day = D.getUTCDay(); hours = D.getUTCHours(); month = D.getUTCMonth(); - if (month < 2 || 10 < month) { - return false; - } - if ((2 < month && month < 10)) { - return true; - } + if (month < 2 || 10 < month) return false; + if ((2 < month && month < 10)) return true; sunday = date - day; if (month === 2) { - if (sunday < 8) { - return false; - } + if (sunday < 8) return false; if (sunday < 15 && day === 0) { - if (hours < 7) { - return false; - } + if (hours < 7) return false; return true; } return true; } - if (sunday < 1) { - return true; - } + if (sunday < 1) return true; if (sunday < 8 && day === 0) { - if (hours < 6) { - return true; - } + if (hours < 6) return true; return false; } return false; } }); + $.cache.requests = {}; + if (typeof GM_deleteValue !== "undefined" && GM_deleteValue !== null) { $.extend($, { "delete": function(name) { @@ -509,25 +508,24 @@ } }); } + for (key in conf) { val = conf[key]; conf[key] = $.get(key, val); } + $$ = function(selector, root) { - if (root == null) { - root = d.body; - } + if (root == null) root = d.body; return Array.prototype.slice.call(root.querySelectorAll(selector)); }; + filter = { regexps: {}, callbacks: [], init: function() { var f, filter, key, m, _i, _len; for (key in config.filter) { - if (!(m = conf[key].match(/^\/.+\/\w*$/gm))) { - continue; - } + if (!(m = conf[key].match(/^\/.+\/\w*$/gm))) continue; this.regexps[key] = []; for (_i = 0, _len = m.length; _i < _len; _i++) { filter = m[_i]; @@ -571,9 +569,7 @@ }, mail: function(root) { var mail; - if (mail = $('.linkmail', root)) { - return filter.test('mail', mail.href); - } + if (mail = $('.linkmail', root)) return filter.test('mail', mail.href); }, sub: function(root) { var sub; @@ -587,9 +583,7 @@ }, file: function(root) { var file; - if (file = $('.filesize span', root)) { - return filter.test('file', file.title); - } + if (file = $('.filesize span', root)) return filter.test('file', file.title); }, md5: function(root) { var img; @@ -598,23 +592,31 @@ } } }; + strikethroughQuotes = { init: function() { return g.callbacks.push(function(root) { var el, quote, _i, _len, _ref, _results; - if (root.className === 'inline') { - return; - } + if (root.className === 'inline') return; _ref = $$('.quotelink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; - _results.push((el = $.id(quote.hash.slice(1))) ? el.parentNode.parentNode.parentNode.hidden ? $.addClass(quote, 'filtered') : void 0 : void 0); + if (el = $.id(quote.hash.slice(1))) { + if (el.parentNode.parentNode.parentNode.hidden) { + _results.push($.addClass(quote, 'filtered')); + } else { + _results.push(void 0); + } + } else { + _results.push(void 0); + } } return _results; }); } }; + expandComment = { init: function() { var a, _i, _len, _ref, _results; @@ -664,21 +666,18 @@ if (quote.getAttribute('href') === quote.hash) { quote.pathname = "/" + g.BOARD + "/res/" + threadID; } - if (quote.hash.slice(1) === threadID) { - quote.innerHTML += ' (OP)'; - } + if (quote.hash.slice(1) === threadID) quote.innerHTML += ' (OP)'; if (conf['Quote Preview']) { $.on(quote, 'mouseover', quotePreview.mouseover); $.on(quote, 'mousemove', ui.hover); $.on(quote, 'mouseout', quotePreview.mouseout); } - if (conf['Quote Inline']) { - $.on(quote, 'click', quoteInline.toggle); - } + if (conf['Quote Inline']) $.on(quote, 'click', quoteInline.toggle); } return $.replace(a.parentNode.parentNode, bq); } }; + expandThread = { init: function() { var a, span, _i, _len, _ref, _results; @@ -709,9 +708,7 @@ a = $('.omittedposts', thread); switch (a.textContent[0]) { case '+': - if ((_ref = $('.op .container', thread)) != null) { - _ref.innerHTML = ''; - } + if ((_ref = $('.op .container', thread)) != null) _ref.innerHTML = ''; a.textContent = a.textContent.replace('+', 'X Loading...'); return $.cache(pathname, (function() { return expandThread.parse(this, pathname, thread, a); @@ -739,7 +736,11 @@ _results = []; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { backlink = _ref2[_i]; - _results.push(!$.id(backlink.hash.slice(1)) ? $.rm(backlink) : void 0); + if (!$.id(backlink.hash.slice(1))) { + _results.push($.rm(backlink)); + } else { + _results.push(void 0); + } } return _results; } @@ -785,13 +786,12 @@ return _results; } }; + replyHiding = { init: function() { return g.callbacks.push(function(root) { var a, dd, id, reply; - if (!(dd = $('.doubledash', root))) { - return; - } + if (!(dd = $('.doubledash', root))) return; dd.className = 'replyhider'; a = $.el('a', { textContent: '[ - ]' @@ -800,9 +800,7 @@ $.replace(dd.firstChild, a); reply = dd.nextSibling; id = reply.id; - if (id in g.hiddenReplies) { - return replyHiding.hide(reply); - } + if (id in g.hiddenReplies) return replyHiding.hide(reply); }); }, cb: { @@ -862,6 +860,7 @@ return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); } }; + keybinds = { init: function() { var node, _i, _len, _ref; @@ -878,9 +877,7 @@ if (((_ref = e.target.nodeName) === 'TEXTAREA' || _ref === 'INPUT') && !e.altKey && !e.ctrlKey && !(e.keyCode === 27)) { return; } - if (!(key = keybinds.keyCode(e))) { - return; - } + if (!(key = keybinds.keyCode(e))) return; thread = nav.getThread(); switch (key) { case conf.close: @@ -892,9 +889,7 @@ break; case conf.spoiler: ta = e.target; - if (ta.nodeName !== 'TEXTAREA') { - return; - } + if (ta.nodeName !== 'TEXTAREA') return; value = ta.value; selStart = ta.selectionStart; selEnd = ta.selectionEnd; @@ -951,14 +946,10 @@ threadHiding.toggle(thread); break; case conf.nextPage: - if ((_ref2 = $('input[value=Next]')) != null) { - _ref2.click(); - } + if ((_ref2 = $('input[value=Next]')) != null) _ref2.click(); break; case conf.previousPage: - if ((_ref3 = $('input[value=Previous]')) != null) { - _ref3.click(); - } + if ((_ref3 = $('input[value=Previous]')) != null) _ref3.click(); break; case conf.submit: if (QR.qr) { @@ -1041,12 +1032,8 @@ } })(); if (key) { - if (e.altKey) { - key = 'alt+' + key; - } - if (e.ctrlKey) { - key = 'ctrl+' + key; - } + if (e.altKey) key = 'alt+' + key; + if (e.ctrlKey) key = 'ctrl+' + key; } return key; }, @@ -1089,9 +1076,7 @@ rect = td.getBoundingClientRect(); if (rect.top > 0 && rect.bottom < d.body.clientHeight) { next = $.x('following::td[@class="reply"]', td); - if ($.x('ancestor::div[@class="thread"]', next) !== thread) { - return; - } + if ($.x('ancestor::div[@class="thread"]', next) !== thread) return; rect = next.getBoundingClientRect(); if (rect.top > 0 && rect.bottom < d.body.clientHeight) { next.className = 'replyhl'; @@ -1137,6 +1122,7 @@ } } }; + nav = { init: function() { var next, prev, span; @@ -1170,9 +1156,7 @@ rect = thread.getBoundingClientRect(); bottom = rect.bottom; if (bottom > 0) { - if (full) { - return [thread, i, rect]; - } + if (full) return [thread, i, rect]; return thread; } } @@ -1213,6 +1197,7 @@ return window.scrollBy(0, top); } }; + options = { init: function() { var a, home; @@ -1374,9 +1359,7 @@ keybind: function(e) { e.preventDefault(); e.stopPropagation(); - if ((key = keybinds.keyCode(e)) == null) { - return; - } + if ((key = keybinds.keyCode(e)) == null) return; this.value = key; $.set(this.name, key); return conf[this.name] = key; @@ -1394,12 +1377,11 @@ return $('#backlinkPreview').textContent = conf['backlink'].replace(/%id/, '123456789'); } }; + QR = { init: function() { var holder; - if (!($('form[name=post]') && $('#recaptcha_response_field'))) { - return; - } + if (!($('form[name=post]') && $('#recaptcha_response_field'))) return; g.callbacks.push(function(root) { var quote; quote = $('.quotejs + a', root); @@ -1430,9 +1412,7 @@ if (conf['Persistent QR']) { QR.dialog(); $('textarea', QR.qr).blur(); - if (conf['Auto Hide QR']) { - $('#autohide', QR.qr).checked = true; - } + if (conf['Auto Hide QR']) $('#autohide', QR.qr).checked = true; } if (conf['Cooldown']) { return $.on(window, 'storage', function(e) { @@ -1468,9 +1448,7 @@ captchaImg: function() { var c, qr; qr = QR.qr; - if (!qr) { - return; - } + if (!qr) return; c = QR.captcha.challenge; return $('#captcha img', qr).src = "http://www.google.com/recaptcha/api/image?c=" + c; }, @@ -1490,9 +1468,7 @@ captchas = $.get('captchas', []); cutoff = Date.now() - 5 * HOUR + 5 * MINUTE; while (captcha = captchas.shift()) { - if (captcha.time > cutoff) { - break; - } + if (captcha.time > cutoff) break; } $.set('captchas', captchas); QR.stats(captchas); @@ -1516,9 +1492,7 @@ QR.foo(this); return; } - if (this.parentNode.className === 'wat') { - QR.attach(this); - } + if (this.parentNode.className === 'wat') QR.attach(this); fr = new FileReader(); img = $('img', this.parentNode); fr.onload = function(e) { @@ -1532,9 +1506,7 @@ }, cooldown: function() { var b, cooldown, n, now; - if (!(g.REPLY && QR.qr)) { - return; - } + if (!(g.REPLY && QR.qr)) return; cooldown = $.get("cooldown/" + g.BOARD, 0); now = Date.now(); n = Math.ceil((cooldown - now) / 1000); @@ -1550,9 +1522,7 @@ textContent: 'Submit', disabled: false }); - if ($('#autopost', QR.qr).checked) { - return QR.submit(); - } + if ($('#autopost', QR.qr).checked) return QR.submit(); } }, foo: function(old) { @@ -1571,15 +1541,11 @@ }, dialog: function(text, tid) { var l, qr, ta; - if (text == null) { - text = ''; - } + if (text == null) text = ''; tid || (tid = g.THREAD_ID || ''); QR.qr = qr = ui.dialog('qr', 'top: 0; right: 0;', " X
" + (g.REPLY ? "" : '') + " " + QR.spoiler + "
"); QR.reset(); - if (conf['Cooldown']) { - QR.cooldown(); - } + if (conf['Cooldown']) QR.cooldown(); QR.foo(); $.on($('.close', qr), 'click', QR.close); $.on($('form', qr), 'submit', QR.submit); @@ -1601,27 +1567,21 @@ QR.captchaReload(); return; } - if (!(e.keyCode === 13 && v)) { - return; - } + if (!(e.keyCode === 13 && v)) return; QR.captchaPush(this); e.preventDefault(); return QR.submit(); }, quote: function(e, blank) { var bq, i, id, qr, s, sel, ss, ta, text, tid, v, _base, _ref, _ref2; - if (e != null) { - e.preventDefault(); - } + if (e != null) e.preventDefault(); tid = (_ref = $.x('ancestor::div[@class="thread"]/div', this)) != null ? _ref.id : void 0; id = this.textContent; text = ">>" + id + "\n"; sel = getSelection(); bq = $.x('ancestor::blockquote', sel.anchorNode); if (id === ((_ref2 = $.x('preceding-sibling::input', bq)) != null ? _ref2.name : void 0)) { - if (s = sel.toString().replace(/\n/g, '\n>')) { - text += ">" + s + "\n"; - } + if (s = sel.toString().replace(/\n/g, '\n>')) text += ">" + s + "\n"; } qr = QR.qr; if (!qr) { @@ -1652,9 +1612,7 @@ if (textContent) { $.extend($('a.error', qr), data); if (textContent === 'Error: Duplicate file entry detected.') { - if (row) { - $.rm(row); - } + if (row) $.rm(row); QR.stats(); setTimeout(QR.submit, 1000); } else if (textContent === 'You seem to have mistyped the verification.') { @@ -1662,9 +1620,7 @@ } return; } - if (row) { - $.rm(row); - } + if (row) $.rm(row); QR.stats(); if (conf['Persistent QR'] || ((_ref2 = $('#files input', qr)) != null ? _ref2.files.length : void 0)) { QR.reset(); @@ -1686,9 +1642,7 @@ $('[name=pwd]', qr).value = (m = c.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $('input[name=pwd]').value; $('[name=sub]', qr).value = ''; if (!conf['Remember Spoiler']) { - if ((_ref = $('[name=spoiler]', qr)) != null) { - _ref.checked = false; - } + if ((_ref = $('[name=spoiler]', qr)) != null) _ref.checked = false; } return $('textarea', qr).value = ''; }, @@ -1708,34 +1662,22 @@ return; } $('.error', qr).textContent = ''; - if (e && (el = $('#recaptcha_response_field', qr)).value) { - QR.captchaPush(el); - } + if (e && (el = $('#recaptcha_response_field', qr)).value) QR.captchaPush(el); if (!(captcha = QR.captchaShift())) { alert('You forgot to type in the verification.'); - if (e != null) { - e.preventDefault(); - } + if (e != null) e.preventDefault(); return; } challenge = captcha.challenge, response = captcha.response; $('#challenge', qr).value = challenge; $('#response', qr).value = response; - if (conf['Auto Hide QR']) { - $('#autohide', qr).checked = true; - } - if (input = $('#files input', qr)) { - input.setAttribute('form', 'qr_form'); - } - if (!e) { - $('#qr_form', qr).submit(); - } + if (conf['Auto Hide QR']) $('#autohide', qr).checked = true; + if (input = $('#files input', qr)) input.setAttribute('form', 'qr_form'); + if (!e) $('#qr_form', qr).submit(); QR.sage = /sage/i.test($('[name=email]', qr).value); id = $('input[name=resto]', qr).value; QR.op = !id; - if (QR.op) { - $('[name=email]', qr).value = 'noko'; - } + if (QR.op) $('[name=email]', qr).value = 'noko'; if (conf['Thread Watcher'] && conf['Auto Watch Reply']) { op = $.id(id); if ($('img.favicon', op).src === Favicon.empty) { @@ -1756,7 +1698,7 @@ To access the parent, we have to break out of the sandbox and evaluate in the global context. - */ + */ return $.globalEval(function() { var data, href, node, textContent, _ref; $ = function(css) { @@ -1776,6 +1718,7 @@ }); } }; + threading = { init: function() { return threading.thread($('body > form').firstChild); @@ -1797,9 +1740,7 @@ thread: function(node) { var div; node = threading.op(node); - if (g.REPLY) { - return; - } + if (g.REPLY) return; div = $.el('div', { className: 'thread' }); @@ -1814,6 +1755,7 @@ } } }; + threadHiding = { init: function() { var a, hiddenThreads, op, thread, _i, _len, _ref, _results; @@ -1828,7 +1770,11 @@ }); $.on(a, 'click', threadHiding.cb.hide); $.prepend(op, a); - _results.push(op.id in hiddenThreads ? threadHiding.hideHide(thread) : void 0); + if (op.id in hiddenThreads) { + _results.push(threadHiding.hideHide(thread)); + } else { + _results.push(void 0); + } } return _results; }, @@ -1898,12 +1844,11 @@ return $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); } }; + updater = { init: function() { var checkbox, checked, dialog, html, input, name, title, _i, _len, _ref; - if (!$('form[name=post]')) { - return; - } + if (!$('form[name=post]')) return; if (conf['Scrolling']) { if (conf['Scroll BG']) { updater.focus = true; @@ -2020,9 +1965,7 @@ while (reply = arr.pop()) { $.before(updater.br, reply); } - if (scroll) { - return scrollTo(0, d.body.scrollHeight); - } + if (scroll) return scrollTo(0, d.body.scrollHeight); } }, timeout: function() { @@ -2045,14 +1988,13 @@ update: function() { var cb, url, _ref; updater.timer.textContent = 0; - if ((_ref = updater.request) != null) { - _ref.abort(); - } + if ((_ref = updater.request) != null) _ref.abort(); url = location.pathname + '?' + Date.now(); cb = updater.cb.update; return updater.request = $.ajax(url, cb); } }; + watcher = { init: function() { var favicon, html, input, inputs, _i, _len; @@ -2070,9 +2012,7 @@ } watcher.refresh(); return $.on(window, 'storage', function(e) { - if (e.key === ("" + NAMESPACE + "watched")) { - return watcher.refresh(); - } + if (e.key === ("" + NAMESPACE + "watched")) return watcher.refresh(); }); }, refresh: function() { @@ -2103,7 +2043,11 @@ for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { favicon = _ref3[_j]; id = favicon.nextSibling.name; - _results.push(id in watchedBoard ? favicon.src = Favicon["default"] : favicon.src = Favicon.empty); + if (id in watchedBoard) { + _results.push(favicon.src = Favicon["default"]); + } else { + _results.push(favicon.src = Favicon.empty); + } } return _results; }, @@ -2147,6 +2091,7 @@ return watcher.refresh(); } }; + anonymize = { init: function() { return g.callbacks.push(function(root) { @@ -2163,6 +2108,7 @@ }); } }; + sauce = { init: function() { sauce.prefixes = conf['flavors'].match(/^[^#].+$/gm); @@ -2171,9 +2117,7 @@ }); return g.callbacks.push(function(root) { var i, link, prefix, suffix, thumb, _len, _ref, _results; - if (root.className === 'inline' || !(thumb = $('img[md5]', root))) { - return; - } + if (root.className === 'inline' || !(thumb = $('img[md5]', root))) return; suffix = thumb.src; _ref = sauce.prefixes; _results = []; @@ -2190,6 +2134,7 @@ }); } }; + revealSpoilers = { init: function() { return g.callbacks.push(function(root) { @@ -2204,14 +2149,13 @@ }); } }; + Time = { init: function() { var chanOffset; Time.foo(); chanOffset = 5 - new Date().getTimezoneOffset() / 60; - if ($.isDST()) { - chanOffset--; - } + if ($.isDST()) chanOffset--; this.parse = Date.parse('10/11/11(Tue)18:53') ? function(node) { return new Date(Date.parse(node.textContent) + chanOffset * HOUR); } : function(node) { @@ -2226,9 +2170,7 @@ }, node: function(root) { var node, posttime, time; - if (root.className === 'inline') { - return; - } + if (root.className === 'inline') return; node = (posttime = $('.posttime', root)) ? posttime : $('span[id]', root).previousSibling; Time.date = Time.parse(node); time = $.el('time', { @@ -2312,25 +2254,26 @@ } } }; + getTitle = function(thread) { var el, span; el = $('.filetitle', thread); if (!el.textContent) { el = $('blockquote', thread); - if (!el.textContent) { - el = $('.postername', thread); - } + if (!el.textContent) el = $('.postername', thread); } span = $.el('span', { innerHTML: el.innerHTML.replace(/
/g, ' ') }); return "/" + g.BOARD + "/ - " + span.textContent; }; + titlePost = { init: function() { return d.title = getTitle(); } }; + quoteBacklink = { init: function() { var format; @@ -2338,16 +2281,12 @@ quoteBacklink.funk = Function('id', "return'" + format + "'"); return g.callbacks.push(function(root) { var a, container, el, id, link, qid, quote, quotes, _i, _len, _ref, _results; - if (/\binline\b/.test(root.className)) { - return; - } + if (/\binline\b/.test(root.className)) return; quotes = {}; _ref = $$('.quotelink', root); for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; - if (!(qid = quote.hash.slice(1))) { - continue; - } + if (!(qid = quote.hash.slice(1))) continue; quotes[qid] = quote; } id = $('input', root).name; @@ -2358,21 +2297,15 @@ }); _results = []; for (qid in quotes) { - if (!(el = $.id(qid))) { - continue; - } - if (el.className === 'op' && !conf['OP Backlinks']) { - continue; - } + if (!(el = $.id(qid))) continue; + if (el.className === 'op' && !conf['OP Backlinks']) continue; link = a.cloneNode(true); if (conf['Quote Preview']) { $.on(link, 'mouseover', quotePreview.mouseover); $.on(link, 'mousemove', ui.hover); $.on(link, 'mouseout', quotePreview.mouseout); } - if (conf['Quote Inline']) { - $.on(link, 'click', quoteInline.toggle); - } + if (conf['Quote Inline']) $.on(link, 'click', quoteInline.toggle); if (!((container = $('.container', el)) && container.parentNode === el)) { container = $.el('span', { className: 'container' @@ -2386,6 +2319,7 @@ }); } }; + quoteInline = { init: function() { return g.callbacks.push(function(root) { @@ -2394,9 +2328,7 @@ _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; - if (!quote.hash) { - continue; - } + if (!quote.hash) continue; quote.removeAttribute('onclick'); _results.push($.on(quote, 'click', quoteInline.toggle)); } @@ -2405,17 +2337,13 @@ }, toggle: function(e) { var id; - if (e.shiftKey || e.altKey || e.ctrlKey || e.button !== 0) { - return; - } + if (e.shiftKey || e.altKey || e.ctrlKey || e.button !== 0) return; e.preventDefault(); id = this.hash.slice(1); if (/\binlined\b/.test(this.className)) { quoteInline.rm(this, id); } else { - if ($.x("ancestor::*[@id='" + id + "']", this)) { - return; - } + if ($.x("ancestor::*[@id='" + id + "']", this)) return; quoteInline.add(this, id); } return this.classList.toggle('inlined'); @@ -2460,9 +2388,7 @@ }, parse: function(req, pathname, id, threadID, inline) { var body, href, html, link, newInline, op, quote, reply, _i, _j, _len, _len2, _ref, _ref2; - if (!inline.parentNode) { - return; - } + if (!inline.parentNode) return; if (req.status !== 200) { inline.innerHTML = "" + req.status + " " + req.statusText; return; @@ -2507,6 +2433,7 @@ }); } }; + quotePreview = { init: function() { return g.callbacks.push(function(root) { @@ -2515,9 +2442,7 @@ _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; - if (!quote.hash) { - continue; - } + if (!quote.hash) continue; $.on(quote, 'mouseover', quotePreview.mouseover); $.on(quote, 'mousemove', ui.hover); _results.push($.on(quote, 'mouseout', quotePreview.mouseout)); @@ -2535,16 +2460,18 @@ id = this.hash.slice(1); if (el = $.id(id)) { qp.innerHTML = el.innerHTML; - if (conf['Quote Highlighting']) { - $.addClass(el, 'qphl'); - } + if (conf['Quote Highlighting']) $.addClass(el, 'qphl'); if (/\bbacklink\b/.test(this.className)) { replyID = $.x('preceding::input', this).name; _ref = $$('.quotelink', qp); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; - _results.push(quote.hash.slice(1) === replyID ? quote.className = 'forwardlink' : void 0); + if (quote.hash.slice(1) === replyID) { + _results.push(quote.className = 'forwardlink'); + } else { + _results.push(void 0); + } } return _results; } @@ -2559,16 +2486,12 @@ }, mouseout: function() { var el; - if (el = $.id(this.hash.slice(1))) { - $.removeClass(el, 'qphl'); - } + if (el = $.id(this.hash.slice(1))) $.removeClass(el, 'qphl'); return ui.hoverend(); }, parse: function(req, id, threadID) { var body, html, op, qp, reply, _i, _len, _ref; - if (!((qp = ui.el) && (qp.innerHTML === ("Loading " + id + "...")))) { - return; - } + if (!((qp = ui.el) && (qp.innerHTML === ("Loading " + id + "...")))) return; if (req.status !== 200) { qp.innerHTML = "" + req.status + " " + req.statusText; return; @@ -2593,24 +2516,28 @@ return Time.node(qp); } }; + quoteOP = { init: function() { return g.callbacks.push(function(root) { var quote, tid, _i, _len, _ref, _results; - if (root.className === 'inline') { - return; - } + if (root.className === 'inline') return; tid = g.THREAD_ID || $.x('ancestor::div[contains(@class,"thread")]/div', root).id; _ref = $$('.quotelink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; - _results.push(quote.hash.slice(1) === tid ? quote.innerHTML += ' (OP)' : void 0); + if (quote.hash.slice(1) === tid) { + _results.push(quote.innerHTML += ' (OP)'); + } else { + _results.push(void 0); + } } return _results; }); } }; + reportButton = { init: function() { return g.callbacks.push(function(root) { @@ -2635,6 +2562,7 @@ return window.open(url, id, set); } }; + threadStats = { init: function() { var dialog, html; @@ -2649,9 +2577,7 @@ return g.callbacks.push(threadStats.node); }, node: function(root) { - if (root.className) { - return; - } + if (root.className) return; threadStats.postcountEl.textContent = ++threadStats.posts; if ($('img[md5]', root)) { threadStats.imagecountEl.textContent = ++threadStats.images; @@ -2661,6 +2587,7 @@ } } }; + unread = { init: function() { unread.replies = []; @@ -2669,14 +2596,10 @@ return g.callbacks.push(unread.node); }, node: function(root) { - if (root.hidden || root.className) { - return; - } + if (root.hidden || root.className) return; unread.replies.push(root); unread.updateTitle(); - if (unread.replies.length === 1) { - return Favicon.update(); - } + if (unread.replies.length === 1) return Favicon.update(); }, scroll: function() { var bottom, height, i, reply, _len, _ref; @@ -2686,23 +2609,18 @@ for (i = 0, _len = _ref.length; i < _len; i++) { reply = _ref[i]; bottom = reply.getBoundingClientRect().bottom; - if (bottom > height) { - break; - } - } - if (i === 0) { - return; + if (bottom > height) break; } + if (i === 0) return; unread.replies = unread.replies.slice(i); unread.updateTitle(); - if (unread.replies.length === 0) { - return Favicon.update(); - } + if (unread.replies.length === 0) return Favicon.update(); }, updateTitle: function() { return d.title = d.title.replace(/\d+/, unread.replies.length); } }; + Favicon = { init: function() { var favicon, href; @@ -2726,6 +2644,7 @@ return $.replace(favicon, clone); } }; + redirect = function() { var url; switch (g.BOARD) { @@ -2769,13 +2688,12 @@ } return location.href = url; }; + imgHover = { init: function() { return g.callbacks.push(function(root) { var thumb; - if (!(thumb = $('img[md5]', root))) { - return; - } + if (!(thumb = $('img[md5]', root))) return; $.on(thumb, 'mouseover', imgHover.mouseover); $.on(thumb, 'mousemove', ui.hover); return $.on(thumb, 'mouseout', ui.hoverend); @@ -2789,6 +2707,7 @@ return $.add(d.body, ui.el); } }; + imgPreloading = { init: function() { var controls, form, label; @@ -2820,9 +2739,7 @@ }, node: function(root) { var thumb; - if (!(imgPreloading.on && (thumb = $('img[md5]:last-child', root)))) { - return; - } + if (!(imgPreloading.on && (thumb = $('img[md5]:last-child', root)))) return; return imgPreloading.preload(thumb); }, preload: function(thumb) { @@ -2831,20 +2748,18 @@ }); } }; + imgGif = { init: function() { return g.callbacks.push(function(root) { var src, thumb; - if (!(thumb = $('img[md5]', root))) { - return; - } + if (!(thumb = $('img[md5]', root))) return; src = thumb.parentNode.href; - if (/gif$/.test(src)) { - return thumb.src = src; - } + if (/gif$/.test(src)) return thumb.src = src; }); } }; + imgExpand = { init: function() { g.callbacks.push(imgExpand.node); @@ -2852,9 +2767,7 @@ }, node: function(root) { var a, thumb; - if (!(thumb = $('img[md5]', root))) { - return; - } + if (!(thumb = $('img[md5]', root))) return; a = thumb.parentNode; $.on(a, 'click', imgExpand.cb.toggle); if (imgExpand.on && root.className !== 'inline') { @@ -2863,9 +2776,7 @@ }, cb: { toggle: function(e) { - if (e.shiftKey || e.altKey || e.ctrlKey || e.button !== 0) { - return; - } + if (e.shiftKey || e.altKey || e.ctrlKey || e.button !== 0) return; e.preventDefault(); return imgExpand.toggle(this); }, @@ -2909,9 +2820,7 @@ form.className = klass; if (/\bfitheight\b/.test(form.className)) { $.on(window, 'resize', imgExpand.resize); - if (!imgExpand.style) { - imgExpand.style = $.addStyle(''); - } + if (!imgExpand.style) imgExpand.style = $.addStyle(''); return imgExpand.resize(); } else if (imgExpand.style) { return $.off(window, 'resize', imgExpand.resize); @@ -2962,9 +2871,7 @@ } }, retry: function(thumb) { - if (!thumb.hidden) { - return imgExpand.expand(thumb); - } + if (!thumb.hidden) return imgExpand.expand(thumb); }, dialog: function() { var controls, form, imageType, option, select, _i, _len, _ref; @@ -2993,6 +2900,7 @@ return imgExpand.style.innerHTML = ".fitheight img + img {max-height:" + d.body.clientHeight + "px;}"; } }; + firstRun = { init: function() { var dialog, style; @@ -3018,6 +2926,7 @@ return $.off(window, 'click', firstRun.close); } }; + Main = { init: function() { var cutoff, hiddenThreads, id, lastChecked, now, pathname, temp, timestamp, _ref; @@ -3048,59 +2957,29 @@ hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); for (id in hiddenThreads) { timestamp = hiddenThreads[id]; - if (timestamp < cutoff) { - delete hiddenThreads[id]; - } + if (timestamp < cutoff) delete hiddenThreads[id]; } _ref = g.hiddenReplies; for (id in _ref) { timestamp = _ref[id]; - if (timestamp < cutoff) { - delete g.hiddenReplies[id]; - } + if (timestamp < cutoff) delete g.hiddenReplies[id]; } $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); } - if (conf['Filter']) { - filter.init(); - } - if (conf['Reply Hiding']) { - replyHiding.init(); - } - if (conf['Filter'] || conf['Reply Hiding']) { - strikethroughQuotes.init(); - } - if (conf['Anonymize']) { - anonymize.init(); - } - if (conf['Time Formatting']) { - Time.init(); - } - if (conf['Sauce']) { - sauce.init(); - } - if (conf['Image Auto-Gif']) { - imgGif.init(); - } - if (conf['Image Hover']) { - imgHover.init(); - } - if (conf['Report Button']) { - reportButton.init(); - } - if (conf['Quote Inline']) { - quoteInline.init(); - } - if (conf['Quote Preview']) { - quotePreview.init(); - } - if (conf['Quote Backlinks']) { - quoteBacklink.init(); - } - if (conf['Indicate OP quote']) { - quoteOP.init(); - } + if (conf['Filter']) filter.init(); + if (conf['Reply Hiding']) replyHiding.init(); + if (conf['Filter'] || conf['Reply Hiding']) strikethroughQuotes.init(); + if (conf['Anonymize']) anonymize.init(); + if (conf['Time Formatting']) Time.init(); + if (conf['Sauce']) sauce.init(); + if (conf['Image Auto-Gif']) imgGif.init(); + if (conf['Image Hover']) imgHover.init(); + if (conf['Report Button']) reportButton.init(); + if (conf['Quote Inline']) quoteInline.init(); + if (conf['Quote Preview']) quotePreview.init(); + if (conf['Quote Backlinks']) quoteBacklink.init(); + if (conf['Indicate OP quote']) quoteOP.init(); if (d.body) { return Main.onLoad(); } else { @@ -3114,59 +2993,27 @@ redirect(); return; } - if (!$('#navtopr')) { - 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(); - } - if (conf['Keybinds']) { - keybinds.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(); + if (conf['Keybinds']) keybinds.init(); if (g.REPLY) { - if (conf['Thread Updater']) { - updater.init(); - } - if (conf['Thread Stats']) { - threadStats.init(); - } - if (conf['Image Preloading']) { - imgPreloading.init(); - } - if (conf['Reply Navigation']) { - nav.init(); - } - if (conf['Post in Title']) { - titlePost.init(); - } - if (conf['Unread Count']) { - unread.init(); - } + if (conf['Thread Updater']) updater.init(); + if (conf['Thread Stats']) threadStats.init(); + if (conf['Image Preloading']) imgPreloading.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['Thread Expansion']) { - expandThread.init(); - } - if (conf['Comment Expansion']) { - expandComment.init(); - } - if (conf['Index Navigation']) { - nav.init(); - } + if (conf['Thread Hiding']) threadHiding.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) { @@ -3178,23 +3025,17 @@ }); $.on($('form[name=delform]'), 'DOMNodeInserted', Main.node); options.init(); - if (!$.get('firstrun')) { - return firstRun.init(); - } + if (!$.get('firstrun')) return firstRun.init(); }, message: function(e) { var data, origin; origin = e.origin, data = e.data; - if (origin === 'http://sys.4chan.org') { - return QR.receive(data); - } + if (origin === 'http://sys.4chan.org') return QR.receive(data); }, node: function(e) { var target; target = e.target; - if (target.nodeName !== 'TABLE') { - return; - } + if (target.nodeName !== 'TABLE') return; return g.callbacks.forEach(function(callback) { try { return callback(target); @@ -3471,5 +3312,7 @@ }\ ' }; + Main.init(); + }).call(this);