From 018963090109638bd260410bdb46078181ecb1d8 Mon Sep 17 00:00:00 2001 From: James Campos Date: Thu, 15 Mar 2012 23:14:51 -0700 Subject: [PATCH] g -> Main --- 4chan_x.user.js | 209 ++++++++++++++++++++++++------------------------ script.coffee | 204 +++++++++++++++++++++++----------------------- 2 files changed, 205 insertions(+), 208 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 8ce222cfc..f5dafb43f 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -73,7 +73,7 @@ */ (function() { - var $, $$, Anonymize, AutoGif, Conf, Config, DAY, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, GetTitle, HOUR, ImageExpand, ImageHover, Keybinds, MINUTE, Main, NAMESPACE, Nav, Options, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, ReplyHiding, ReportButton, RevealSpoilers, SECOND, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Threading, Time, TitlePost, Unread, Updater, VERSION, Watcher, d, engine, flatten, g, log, ui, _base; + var $, $$, Anonymize, AutoGif, Conf, Config, DAY, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, GetTitle, HOUR, ImageExpand, ImageHover, Keybinds, MINUTE, Main, NAMESPACE, Nav, Options, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, ReplyHiding, ReportButton, RevealSpoilers, SECOND, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Threading, Time, TitlePost, Unread, Updater, VERSION, Watcher, d, engine, flatten, log, ui, _base; Config = { main: { @@ -226,10 +226,6 @@ d = document; - g = { - callbacks: [] - }; - ui = { dialog: function(id, position, html) { var el, saved; @@ -553,7 +549,7 @@ if (!(regexp = filter.match(/\/(.+)\/(\w*)/))) continue; filter = filter.replace(regexp[0], ''); boards = ((_ref2 = filter.match(/boards:([^;]+)/)) != null ? _ref2[1].toLowerCase() : void 0) || 'global'; - if (boards !== 'global' && boards.split(',').indexOf(g.BOARD) === -1) { + if (boards !== 'global' && boards.split(',').indexOf(Main.BOARD) === -1) { continue; } try { @@ -576,7 +572,7 @@ } if (!this.filters[key].length) delete this.filters[key]; } - if (Object.keys(this.filters).length) return g.callbacks.push(this.node); + if (Object.keys(this.filters).length) return Main.callbacks.push(this.node); }, createFilter: function(regexp, op, hl, top) { var test; @@ -605,7 +601,7 @@ if (!(result = filter(value, isOP))) continue; if (result === true) { if (isOP) { - if (!g.REPLY) { + if (!Main.REPLY) { ThreadHiding.hide(post.el.parentNode); } else { continue; @@ -620,7 +616,7 @@ } else { $.addClass(el.parentNode, result[0]); } - if (isOP && result[1] && !g.REPLY) { + if (isOP && result[1] && !Main.REPLY) { thisThread = el.parentNode; if (firstThread = $('div[class=op]')) { $.before(firstThread.parentNode, [thisThread, thisThread.nextElementSibling]); @@ -700,7 +696,7 @@ StrikethroughQuotes = { init: function() { - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var el, quote, _i, _len, _ref; @@ -750,7 +746,7 @@ for (_i = 0, _len = quotes.length; _i < _len; _i++) { quote = quotes[_i]; if (quote.hash === quote.getAttribute('href')) { - quote.pathname = "/" + g.BOARD + "/res/" + threadID; + quote.pathname = "/" + Main.BOARD + "/res/" + threadID; } } post = { @@ -795,7 +791,7 @@ toggle: function(thread) { var a, backlink, num, pathname, prev, table, threadID, _i, _len, _ref, _ref2, _results; threadID = thread.firstChild.id; - pathname = "/" + g.BOARD + "/res/" + threadID; + pathname = "/" + Main.BOARD + "/res/" + threadID; a = $('.omittedposts', thread); switch (a.textContent[0]) { case '+': @@ -810,7 +806,7 @@ case '-': a.textContent = a.textContent.replace('-', '+'); num = (function() { - switch (g.BOARD) { + switch (Main.BOARD) { case 'b': case 'vg': return 3; @@ -880,7 +876,7 @@ className: 'replyhider', innerHTML: '[ - ]' }); - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var td; @@ -888,7 +884,7 @@ td = ReplyHiding.td.cloneNode(true); $.on(td.firstChild, 'click', ReplyHiding.toggle); $.replace(post.el.previousSibling, td); - if (post.id in g.hiddenReplies) return ReplyHiding.hide(post.root); + if (post.id in Main.hiddenReplies) return ReplyHiding.hide(post.root); }, toggle: function() { var id, parent, quote, table, _i, _j, _len, _len2, _ref, _ref2; @@ -901,7 +897,7 @@ quote = _ref[_i]; $.addClass(quote, 'filtered'); } - g.hiddenReplies[id] = Date.now(); + Main.hiddenReplies[id] = Date.now(); } else { table = parent.nextSibling; table.hidden = false; @@ -912,9 +908,9 @@ quote = _ref2[_j]; $.removeClass(quote, 'filtered'); } - delete g.hiddenReplies[id]; + delete Main.hiddenReplies[id]; } - return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); + return $.set("hiddenReplies/" + Main.BOARD + "/", Main.hiddenReplies); }, hide: function(table) { var div, name, trip, uid, _ref, _ref2; @@ -996,7 +992,7 @@ Keybinds.img(thread, true); break; case Conf.zero: - window.location = "/" + g.BOARD + "/0#0"; + window.location = "/" + Main.BOARD + "/0#0"; break; case Conf.nextPage: if ((_ref = $('input[value=Next]')) != null) _ref.click(); @@ -1005,11 +1001,11 @@ if ((_ref2 = $('input[value=Previous]')) != null) _ref2.click(); break; case Conf.nextThread: - if (g.REPLY) return; + if (Main.REPLY) return; Nav.scroll(+1); break; case Conf.previousThread: - if (g.REPLY) return; + if (Main.REPLY) return; Nav.scroll(-1); break; case Conf.expandThread: @@ -1124,7 +1120,7 @@ open: function(thread, tab) { var id, url; id = thread.firstChild.id; - url = "//boards.4chan.org/" + g.BOARD + "/res/" + id; + url = "//boards.4chan.org/" + Main.BOARD + "/res/" + id; if (tab) { return $.open(url); } else { @@ -1145,7 +1141,7 @@ td.focus(); return; } - if (!(g.REPLY || $.x('ancestor::div[@class="thread"]', next) === thread)) { + if (!(Main.REPLY || $.x('ancestor::div[@class="thread"]', next) === thread)) { return; } rect = next.getBoundingClientRect(); @@ -1193,14 +1189,14 @@ return $.add(d.body, span); }, prev: function() { - if (g.REPLY) { + if (Main.REPLY) { return window.scrollTo(0, 0); } else { return Nav.scroll(-1); } }, next: function() { - if (g.REPLY) { + if (Main.REPLY) { return window.scrollTo(0, d.body.scrollHeight); } else { return Nav.scroll(+1); @@ -1236,18 +1232,18 @@ QR = { init: function() { if (!$.id('recaptcha_challenge_field_holder')) return; - g.callbacks.push(this.node); + Main.callbacks.push(this.node); return setTimeout(this.asyncInit); }, asyncInit: function() { var form, iframe, link, loadChecking, script; if (Conf['Hide Original Post Form']) { link = $.el('h1', { - innerHTML: "" + (g.REPLY ? 'Quick Reply' : 'New Thread') + "" + innerHTML: "" + (Main.REPLY ? 'Quick Reply' : 'New Thread') + "" }); $.on($('a', link), 'click', function() { QR.open(); - if (!g.REPLY) $('select', QR.el).value = 'new'; + if (!Main.REPLY) $('select', QR.el).value = 'new'; return $('textarea', QR.el).focus(); }); form = d.forms[0]; @@ -1362,7 +1358,7 @@ value = 'Loading'; disabled = true; } - if (g.dead) { + if (Main.dead) { value = 404; disabled = true; QR.cooldown.auto = false; @@ -1380,8 +1376,8 @@ cooldown: { init: function() { if (!Conf['Cooldown']) return; - QR.cooldown.start($.get("/" + g.BOARD + "/cooldown", 0)); - return $.sync("/" + g.BOARD + "/cooldown", QR.cooldown.start); + QR.cooldown.start($.get("/" + Main.BOARD + "/cooldown", 0)); + return $.sync("/" + Main.BOARD + "/cooldown", QR.cooldown.start); }, start: function(timeout) { var seconds; @@ -1391,14 +1387,14 @@ set: function(seconds) { if (!Conf['Cooldown']) return; QR.cooldown.count(seconds); - return $.set("/" + g.BOARD + "/cooldown", Date.now() + seconds * SECOND); + return $.set("/" + Main.BOARD + "/cooldown", Date.now() + seconds * SECOND); }, count: function(seconds) { if (!((0 <= seconds && seconds <= 60))) return; setTimeout(QR.cooldown.count, 1000, seconds - 1); QR.cooldown.seconds = seconds; if (seconds === 0) { - $["delete"]("/" + g.BOARD + "/cooldown"); + $["delete"]("/" + Main.BOARD + "/cooldown"); if (QR.cooldown.auto) QR.submit(); } return QR.status(); @@ -1408,7 +1404,7 @@ var caretPos, id, range, s, sel, ta, text, _ref; if (e != null) e.preventDefault(); QR.open(); - if (!g.REPLY) { + if (!Main.REPLY) { $('select', QR.el).value = $.x('ancestor::div[@class="thread"]', this).firstChild.id; } id = this.previousElementSibling.hash.slice(1); @@ -1770,7 +1766,7 @@ QR.spoiler = !!$('#com_submit + label'); spoiler = $('#spoilerLabel', QR.el); spoiler.hidden = !QR.spoiler; - if (!g.REPLY) { + if (!Main.REPLY) { threads = ''; _ref = $$('.op'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -1878,7 +1874,7 @@ return; } QR.cleanError(); - threadID = g.THREAD_ID || $('select', QR.el).value; + threadID = Main.THREAD_ID || $('select', QR.el).value; QR.cooldown.auto = QR.replies.length > 1; if (Conf['Auto Hide QR'] && !QR.cooldown.auto) QR.hide(); if (Conf['Thread Watcher'] && Conf['Auto Watch Reply'] && threadID !== 'new') { @@ -1965,12 +1961,12 @@ if (Conf['Thread Watcher'] && Conf['Auto Watch']) { $.set('autoWatch', postNumber); } - location.pathname = "/" + g.BOARD + "/res/" + postNumber; + location.pathname = "/" + Main.BOARD + "/res/" + postNumber; } else { QR.cooldown.auto = QR.replies.length > 1; QR.cooldown.set(/sage/i.test(reply.email) ? 60 : 30); - if (Conf['Open Reply in New Tab'] && !g.REPLY && !QR.cooldown.auto) { - $.open("//boards.4chan.org/" + g.BOARD + "/res/" + thread + "#" + postNumber); + if (Conf['Open Reply in New Tab'] && !Main.REPLY && !QR.cooldown.auto) { + $.open("//boards.4chan.org/" + Main.BOARD + "/res/" + thread + "#" + postNumber); } } if (Conf['Persistent QR'] || QR.cooldown.auto) { @@ -1978,10 +1974,10 @@ } else { QR.close(); } - if (g.REPLY && (Conf['Unread Count'] || Conf['Unread Favicon'])) { + if (Main.REPLY && (Conf['Unread Count'] || Conf['Unread Favicon'])) { Unread.foresee.push(postNumber); } - if (g.REPLY && Conf['Thread Updater'] && Conf['Auto Update This']) { + if (Main.REPLY && Conf['Thread Updater'] && Conf['Auto Update This']) { Updater.update(); } QR.status(); @@ -2265,8 +2261,8 @@ } $.add($('#main_tab + div', dialog), ul); } - hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); - hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length; + hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); + hiddenNum = Object.keys(Main.hiddenReplies).length + Object.keys(hiddenThreads).length; li = $.el('li', { innerHTML: " : Forget all hidden posts. Useful if you accidentally hide a post and have \"Show Stubs\" disabled." }); @@ -2337,10 +2333,10 @@ return d.body.style.removeProperty('overflow'); }, clearHidden: function() { - $["delete"]("hiddenReplies/" + g.BOARD + "/"); - $["delete"]("hiddenThreads/" + g.BOARD + "/"); + $["delete"]("hiddenReplies/" + Main.BOARD + "/"); + $["delete"]("hiddenThreads/" + Main.BOARD + "/"); this.textContent = "hidden: 0"; - return g.hiddenReplies = {}; + return Main.hiddenReplies = {}; }, keybind: function(e) { var key; @@ -2401,7 +2397,7 @@ thread: function(node) { var div, nodes; node = Threading.op(node); - if (g.REPLY) return; + if (Main.REPLY) return; nodes = []; while (node.nodeName !== 'HR') { nodes.push(node); @@ -2422,7 +2418,7 @@ ThreadHiding = { init: function() { var a, hiddenThreads, op, thread, _i, _len, _ref; - hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); + hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); _ref = $$('.thread'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { thread = _ref[_i]; @@ -2441,7 +2437,7 @@ }, toggle: function(thread) { var hiddenThreads, id; - hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); + hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); id = $('.op', thread).id; if (thread.hidden || thread.firstChild.className === 'block') { ThreadHiding.show(thread); @@ -2450,7 +2446,7 @@ ThreadHiding.hide(thread); hiddenThreads[id] = Date.now(); } - return $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); + return $.set("hiddenThreads/" + Main.BOARD + "/", hiddenThreads); }, hide: function(thread) { var a, div, name, num, op, span, text, trip, uid, _ref, _ref2; @@ -2568,7 +2564,7 @@ Updater.count.textContent = 404; Updater.count.className = 'warning'; clearTimeout(Updater.timeoutID); - g.dead = true; + Main.dead = true; if (Conf['Unread Count']) { Unread.title = Unread.title.match(/^.+-/)[0] + ' 404'; } else { @@ -2665,8 +2661,8 @@ $.on(favicon, 'click', this.cb.toggle); $.before(input, favicon); } - if (g.THREAD_ID === $.get('autoWatch', 0)) { - this.watch(g.THREAD_ID); + if (Main.THREAD_ID === $.get('autoWatch', 0)) { + this.watch(Main.THREAD_ID); $["delete"]('autoWatch'); } else { this.refresh(); @@ -2699,7 +2695,7 @@ $.rm(div); } $.add(Watcher.dialog, nodes); - watchedBoard = watched[g.BOARD] || {}; + watchedBoard = watched[Main.BOARD] || {}; _ref3 = $$('.favicon'); for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { favicon = _ref3[_j]; @@ -2724,7 +2720,7 @@ toggle: function(thread) { var id; id = $('.favicon + input', thread).name; - return Watcher.watch(id) || Watcher.unwatch(id, g.BOARD); + return Watcher.watch(id) || Watcher.unwatch(id, Main.BOARD); }, unwatch: function(id, board) { var watched; @@ -2738,9 +2734,9 @@ thread = $.id(id); if ($('.favicon', thread).src === Favicon["default"]) return false; watched = $.get('watched', {}); - watched[_name = g.BOARD] || (watched[_name] = {}); - watched[g.BOARD][id] = { - href: "/" + g.BOARD + "/res/" + id, + watched[_name = Main.BOARD] || (watched[_name] = {}); + watched[Main.BOARD][id] = { + href: "/" + Main.BOARD + "/res/" + id, textContent: GetTitle(thread) }; $.set('watched', watched); @@ -2751,7 +2747,7 @@ Anonymize = { init: function() { - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var name, node; @@ -2768,7 +2764,7 @@ Sauce = { init: function() { var link, _i, _len, _ref; - if (g.BOARD === 'f') return; + if (Main.BOARD === 'f') return; this.links = []; _ref = Conf['sauces'].split('\n'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -2777,7 +2773,7 @@ this.links.push(this.createSauceLink(link)); } if (!this.links.length) return; - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, createSauceLink: function(link) { var domain, el, href; @@ -2791,7 +2787,7 @@ case '$3': return "' + img.firstChild.getAttribute('md5').replace(/\=*$/, '') + '"; case '$4': - return g.BOARD; + return Main.BOARD; } }); href = Function('img', "return '" + href + "'"); @@ -2823,7 +2819,7 @@ RevealSpoilers = { init: function() { - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var img; @@ -2851,7 +2847,7 @@ hour = chanOffset + Number(hour); return new Date(year, month, day, hour, min); }; - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var node, time; @@ -2942,9 +2938,9 @@ FileInfo = { init: function() { - if (g.BOARD === 'f') return; + if (Main.BOARD === 'f') return; this.setFormats(); - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var fullname, link, node, regexp, resolution, shortname, size, type, unit, _, _ref; @@ -3052,7 +3048,7 @@ span = $.el('span', { innerHTML: el.innerHTML.replace(/
/g, ' ') }); - return "/" + g.BOARD + "/ - " + span.textContent; + return "/" + Main.BOARD + "/ - " + span.textContent; }; TitlePost = { @@ -3066,7 +3062,7 @@ var format; format = Conf['backlink'].replace(/%id/g, "' + id + '"); this.funk = Function('id', "return '" + format + "'"); - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var a, container, el, link, qid, quote, quotes, root, _i, _len, _ref; @@ -3109,7 +3105,7 @@ QuoteInline = { init: function() { - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var quote, _i, _j, _len, _len2, _ref, _ref2; @@ -3206,7 +3202,7 @@ quote = _ref[_i]; if ((href = quote.getAttribute('href')) === quote.hash) { quote.pathname = pathname; - } else if (!g.REPLY && href !== quote.href) { + } else if (!Main.REPLY && href !== quote.href) { quote.href = "res/" + href; } } @@ -3227,7 +3223,7 @@ QuotePreview = { init: function() { - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var quote, _i, _j, _len, _len2, _ref, _ref2; @@ -3306,7 +3302,7 @@ QuoteOP = { init: function() { - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var quote, _i, _len, _ref; @@ -3323,7 +3319,7 @@ QuoteCT = { init: function() { - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var path, quote, _i, _len, _ref; @@ -3333,7 +3329,7 @@ quote = _ref[_i]; if (!quote.hash) continue; path = quote.pathname.split('/'); - if (path[1] === g.BOARD && path[3] !== post.threadId) { + if (path[1] === Main.BOARD && path[3] !== post.threadId) { $.add(quote, $.tn('\u00A0(Cross-thread)')); } } @@ -3342,7 +3338,7 @@ Quotify = { init: function() { - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var a, board, data, i, id, index, m, node, nodes, quote, quotes, snapshot, text, _i, _len, _ref; @@ -3362,7 +3358,7 @@ nodes.push(a = $.el('a', { textContent: "" + quote + "\u00A0(Dead)" })); - if (board === g.BOARD && $.id(id)) { + if (board === Main.BOARD && $.id(id)) { a.href = "#" + id; a.className = 'quotelink'; a.setAttribute('onclick', "replyhl('" + id + "');"); @@ -3386,7 +3382,7 @@ innerHTML: '[ ! ]', href: 'javascript:;' }); - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var a; @@ -3398,7 +3394,7 @@ }, report: function() { var id, set, url; - url = "//sys.4chan.org/" + g.BOARD + "/imgboard.php?mode=report&no=" + ($.x('preceding-sibling::input', this).name); + url = "//sys.4chan.org/" + Main.BOARD + "/imgboard.php?mode=report&no=" + ($.x('preceding-sibling::input', this).name); id = Date.now(); set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200"; return window.open(url, id, set); @@ -3413,7 +3409,7 @@ $.add(d.body, dialog); this.posts = this.images = 0; this.imgLimit = (function() { - switch (g.BOARD) { + switch (Main.BOARD) { case 'a': case 'mlp': case 'v': @@ -3424,7 +3420,7 @@ return 151; } })(); - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var imgcount; @@ -3444,7 +3440,7 @@ this.title = d.title; this.update(); $.on(window, 'scroll', Unread.scroll); - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, replies: [], foresee: [], @@ -3484,11 +3480,11 @@ }, update: function(forceUpdate) { var count; - if (!g.REPLY) return; + if (!Main.REPLY) return; count = this.replies.length; if (Conf['Unread Count']) this.setTitle(count); if (!(Conf['Unread Favicon'] && (count < 2 || forceUpdate))) return; - Favicon.el.href = g.dead ? count ? Favicon.unreadDead : Favicon.dead : count ? Favicon.unread : Favicon["default"]; + Favicon.el.href = Main.dead ? count ? Favicon.unreadDead : Favicon.dead : count ? Favicon.unread : Favicon["default"]; return $.add(d.head, Favicon.el); } }; @@ -3534,7 +3530,7 @@ Redirect = { init: function() { var url; - url = location.hostname === 'images.4chan.org' ? this.image(location.href) : /^\d+$/.test(g.THREAD_ID) ? this.thread() : void 0; + url = location.hostname === 'images.4chan.org' ? this.image(location.href) : /^\d+$/.test(Main.THREAD_ID) ? this.thread() : void 0; if (url) return location.href = url; }, image: function(href) { @@ -3551,11 +3547,11 @@ } }, thread: function(board, id, mode) { - if (board == null) board = g.BOARD; - if (id == null) id = g.THREAD_ID; + if (board == null) board = Main.BOARD; + if (id == null) id = Main.THREAD_ID; if (mode == null) mode = 'thread'; if (!(Conf['404 Redirect'] || mode === 'post')) return; - switch (g.BOARD) { + switch (Main.BOARD) { case 'a': case 'jp': case 'm': @@ -3606,7 +3602,7 @@ ImageHover = { init: function() { - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { if (!post.img) return; @@ -3640,7 +3636,7 @@ AutoGif = { init: function() { - return g.callbacks.push(this.node); + return Main.callbacks.push(this.node); }, node: function(post) { var img, src; @@ -3658,7 +3654,7 @@ ImageExpand = { init: function() { - g.callbacks.push(this.node); + Main.callbacks.push(this.node); return this.dialog(); }, node: function(post) { @@ -3765,7 +3761,7 @@ ImageExpand.contract(thumb); $.rm(this); if (!(this.src.split('/')[2] === 'images.4chan.org' && (url = Redirect.image(href)))) { - if (g.dead) return; + if (Main.dead) return; url = href + '?' + Date.now(); } timeoutID = setTimeout(ImageExpand.expand, 10000, thumb, url); @@ -3806,12 +3802,12 @@ var cutoff, hiddenThreads, id, key, now, path, pathname, temp, timestamp, val, _ref; path = location.pathname; pathname = path.slice(1).split('/'); - g.BOARD = pathname[0], temp = pathname[1]; + Main.BOARD = pathname[0], temp = pathname[1]; if (temp === 'res') { - g.REPLY = true; - g.THREAD_ID = pathname[2]; + Main.REPLY = true; + Main.THREAD_ID = pathname[2]; } else { - g.PAGENUM = parseInt(temp) || 0; + Main.PAGENUM = parseInt(temp) || 0; } for (key in Conf) { val = Conf[key]; @@ -3851,7 +3847,7 @@ return; } $.ready(Options.init); - if (Conf['Quick Reply'] && Conf['Hide Original Post Form'] && g.BOARD !== 'f') { + if (Conf['Quick Reply'] && Conf['Hide Original Post Form'] && Main.BOARD !== 'f') { Main.css += 'form[name=post] { display: none; }'; } Main.addStyle(); @@ -3864,22 +3860,22 @@ }); $.set('lastUpdate', now); } - g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); + Main.hiddenReplies = $.get("hiddenReplies/" + Main.BOARD + "/", {}); if ($.get('lastChecked', 0) < now - 1 * DAY) { $.set('lastChecked', now); cutoff = now - 7 * DAY; - hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); + hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); for (id in hiddenThreads) { timestamp = hiddenThreads[id]; if (timestamp < cutoff) delete hiddenThreads[id]; } - _ref = g.hiddenReplies; + _ref = Main.hiddenReplies; for (id in _ref) { timestamp = _ref[id]; - if (timestamp < cutoff) delete g.hiddenReplies[id]; + if (timestamp < cutoff) delete Main.hiddenReplies[id]; } - $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); - $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); + $.set("hiddenThreads/" + Main.BOARD + "/", hiddenThreads); + $.set("hiddenReplies/" + Main.BOARD + "/", Main.hiddenReplies); } if (Conf['Filter']) Filter.init(); if (Conf['Reply Hiding']) ReplyHiding.init(); @@ -3912,7 +3908,7 @@ _ref = ['navtop', 'navbot']; for (_i = 0, _len = _ref.length; _i < _len; _i++) { nav = _ref[_i]; - $.addClass($("a[href$='/" + g.BOARD + "/']", $.id(nav)), 'current'); + $.addClass($("a[href$='/" + Main.BOARD + "/']", $.id(nav)), 'current'); } form = $('form[name=delform]'); Threading.thread(form.firstElementChild); @@ -3929,7 +3925,7 @@ return Keybinds.init(); }); } - if (g.REPLY) { + if (Main.REPLY) { if (Conf['Thread Updater']) { setTimeout(function() { return Updater.init(); @@ -4010,7 +4006,7 @@ el: klass === 'op' ? node : node.firstChild.firstChild.lastChild, "class": klass, id: node.getElementsByTagName('input')[0].name, - threadId: g.THREAD_ID || $.x('ancestor::div[@class="thread"]', node).firstChild.id, + threadId: Main.THREAD_ID || $.x('ancestor::div[@class="thread"]', node).firstChild.id, isOP: klass === 'op', isInlined: /\binline\b/.test(klass), filesize: node.getElementsByClassName('filesize')[0] || false, @@ -4022,7 +4018,7 @@ }, node: function(nodes, notify) { var callback, node, _i, _j, _len, _len2, _ref; - _ref = g.callbacks; + _ref = Main.callbacks; for (_i = 0, _len = _ref.length; _i < _len; _i++) { callback = _ref[_i]; try { @@ -4055,6 +4051,7 @@ target = e.target; if (target.nodeName === 'TABLE') return Main.node([Main.preParse(target)]); }, + callbacks: [], css: '\ /* dialog styling */\ .dialog {\ diff --git a/script.coffee b/script.coffee index bbebd5352..bcc67765a 100644 --- a/script.coffee +++ b/script.coffee @@ -179,7 +179,6 @@ HOUR = 60*MINUTE DAY = 24*HOUR engine = /WebKit|Presto|Gecko/.exec(navigator.userAgent)[0].toLowerCase() d = document -g = callbacks: [] ui = dialog: (id, position, html) -> @@ -471,7 +470,7 @@ Filter = # and it's not specifically applicable to the current board. # Defaults to global. boards = filter.match(/boards:([^;]+)/)?[1].toLowerCase() or 'global' - if boards isnt 'global' and boards.split(',').indexOf(g.BOARD) is -1 + if boards isnt 'global' and boards.split(',').indexOf(Main.BOARD) is -1 continue try @@ -507,7 +506,7 @@ Filter = delete @filters[key] if Object.keys(@filters).length - g.callbacks.push @node + Main.callbacks.push @node createFilter: (regexp, op, hl, top) -> test = @@ -540,7 +539,7 @@ Filter = # Hide if result is true if isOP - unless g.REPLY + unless Main.REPLY ThreadHiding.hide post.el.parentNode else continue @@ -553,7 +552,7 @@ Filter = $.addClass el, result[0] else $.addClass el.parentNode, result[0] - if isOP and result[1] and not g.REPLY + if isOP and result[1] and not Main.REPLY # Put the highlighted OPs' threads on top of the board pages... thisThread = el.parentNode # ...before the first non highlighted thread. @@ -612,7 +611,7 @@ Filter = StrikethroughQuotes = init: -> - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return if post.isInlined for quote in post.quotes @@ -649,7 +648,7 @@ ExpandComment = quotes = node.getElementsByClassName 'quotelink' for quote in quotes if quote.hash is quote.getAttribute 'href' - quote.pathname = "/#{g.BOARD}/res/#{threadID}" + quote.pathname = "/#{Main.BOARD}/res/#{threadID}" post = el: node threadId: threadID @@ -684,7 +683,7 @@ ExpandThread = toggle: (thread) -> threadID = thread.firstChild.id - pathname = "/#{g.BOARD}/res/#{threadID}" + pathname = "/#{Main.BOARD}/res/#{threadID}" a = $ '.omittedposts', thread # \u00d7 is × @@ -702,7 +701,7 @@ ExpandThread = when '-' a.textContent = a.textContent.replace '-', '+' #goddamit moot - num = switch g.BOARD + num = switch Main.BOARD when 'b', 'vg' then 3 when 't' then 1 else 5 @@ -747,7 +746,7 @@ ReplyHiding = noWrap: true className: 'replyhider' innerHTML: '[ - ]' - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return if post.class @@ -755,7 +754,7 @@ ReplyHiding = $.on td.firstChild, 'click', ReplyHiding.toggle $.replace post.el.previousSibling, td - if post.id of g.hiddenReplies + if post.id of Main.hiddenReplies ReplyHiding.hide post.root toggle: -> @@ -765,7 +764,7 @@ ReplyHiding = id = parent.nextSibling.id for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']" $.addClass quote, 'filtered' - g.hiddenReplies[id] = Date.now() + Main.hiddenReplies[id] = Date.now() else table = parent.nextSibling table.hidden = false @@ -773,8 +772,8 @@ ReplyHiding = id = table.firstChild.firstChild.lastChild.id for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']" $.removeClass quote, 'filtered' - delete g.hiddenReplies[id] - $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies + delete Main.hiddenReplies[id] + $.set "hiddenReplies/#{Main.BOARD}/", Main.hiddenReplies hide: (table) -> return if table.hidden # already hidden by filter @@ -850,17 +849,17 @@ Keybinds = Keybinds.img thread, true # Board Navigation when Conf.zero - window.location = "/#{g.BOARD}/0#0" + window.location = "/#{Main.BOARD}/0#0" when Conf.nextPage $('input[value=Next]')?.click() when Conf.previousPage $('input[value=Previous]')?.click() # Thread Navigation when Conf.nextThread - return if g.REPLY + return if Main.REPLY Nav.scroll +1 when Conf.previousThread - return if g.REPLY + return if Main.REPLY Nav.scroll -1 when Conf.expandThread ExpandThread.toggle thread @@ -919,7 +918,7 @@ Keybinds = open: (thread, tab) -> id = thread.firstChild.id - url = "//boards.4chan.org/#{g.BOARD}/res/#{id}" + url = "//boards.4chan.org/#{Main.BOARD}/res/#{id}" if tab $.open url else @@ -941,7 +940,7 @@ Keybinds = td.tabIndex = 0 td.focus() return - return unless g.REPLY or $.x('ancestor::div[@class="thread"]', next) is thread + return unless Main.REPLY or $.x('ancestor::div[@class="thread"]', next) is thread rect = next.getBoundingClientRect() if rect.top < 0 or rect.bottom > d.body.clientHeight next.scrollIntoView delta is -1 @@ -979,13 +978,13 @@ Nav = $.add d.body, span prev: -> - if g.REPLY + if Main.REPLY window.scrollTo 0, 0 else Nav.scroll -1 next: -> - if g.REPLY + if Main.REPLY window.scrollTo 0, d.body.scrollHeight else Nav.scroll +1 @@ -1017,15 +1016,15 @@ Nav = QR = init: -> return unless $.id 'recaptcha_challenge_field_holder' - g.callbacks.push @node + Main.callbacks.push @node setTimeout @asyncInit asyncInit: -> if Conf['Hide Original Post Form'] - link = $.el 'h1', innerHTML: "#{if g.REPLY then 'Quick Reply' else 'New Thread'}" + link = $.el 'h1', innerHTML: "#{if Main.REPLY then 'Quick Reply' else 'New Thread'}" $.on $('a', link), 'click', -> QR.open() - $('select', QR.el).value = 'new' unless g.REPLY + $('select', QR.el).value = 'new' unless Main.REPLY $('textarea', QR.el).focus() form = d.forms[0] $.before form, link @@ -1110,7 +1109,7 @@ QR = else unless QR.status.ready value = 'Loading' disabled = true - if g.dead + if Main.dead value = 404 disabled = true QR.cooldown.auto = false @@ -1132,28 +1131,28 @@ QR = cooldown: init: -> return unless Conf['Cooldown'] - QR.cooldown.start $.get "/#{g.BOARD}/cooldown", 0 - $.sync "/#{g.BOARD}/cooldown", QR.cooldown.start + QR.cooldown.start $.get "/#{Main.BOARD}/cooldown", 0 + $.sync "/#{Main.BOARD}/cooldown", QR.cooldown.start start: (timeout) -> seconds = Math.floor (timeout - Date.now()) / 1000 QR.cooldown.count seconds set: (seconds) -> return unless Conf['Cooldown'] QR.cooldown.count seconds - $.set "/#{g.BOARD}/cooldown", Date.now() + seconds*SECOND + $.set "/#{Main.BOARD}/cooldown", Date.now() + seconds*SECOND count: (seconds) -> return unless 0 <= seconds <= 60 setTimeout QR.cooldown.count, 1000, seconds-1 QR.cooldown.seconds = seconds if seconds is 0 - $.delete "/#{g.BOARD}/cooldown" + $.delete "/#{Main.BOARD}/cooldown" QR.submit() if QR.cooldown.auto QR.status() quote: (e) -> e?.preventDefault() QR.open() - unless g.REPLY + unless Main.REPLY $('select', QR.el).value = $.x('ancestor::div[@class="thread"]', @).firstChild.id # Make sure we get the correct number, even with XXX censors @@ -1463,7 +1462,7 @@ QR = spoiler = $ '#spoilerLabel', QR.el spoiler.hidden = !QR.spoiler - unless g.REPLY + unless Main.REPLY # Make a list with visible threads and an option to create a new one. threads = '' for thread in $$ '.op' @@ -1553,7 +1552,7 @@ QR = return QR.cleanError() - threadID = g.THREAD_ID or $('select', QR.el).value + threadID = Main.THREAD_ID or $('select', QR.el).value # Enable auto-posting if we have stuff to post, disable it otherwise. QR.cooldown.auto = QR.replies.length > 1 @@ -1642,22 +1641,22 @@ QR = if Conf['Thread Watcher'] and Conf['Auto Watch'] $.set 'autoWatch', postNumber # auto-noko - location.pathname = "/#{g.BOARD}/res/#{postNumber}" + location.pathname = "/#{Main.BOARD}/res/#{postNumber}" else # Enable auto-posting if we have stuff to post, disable it otherwise. QR.cooldown.auto = QR.replies.length > 1 QR.cooldown.set if /sage/i.test reply.email then 60 else 30 - if Conf['Open Reply in New Tab'] && !g.REPLY && !QR.cooldown.auto - $.open "//boards.4chan.org/#{g.BOARD}/res/#{thread}##{postNumber}" + if Conf['Open Reply in New Tab'] && !Main.REPLY && !QR.cooldown.auto + $.open "//boards.4chan.org/#{Main.BOARD}/res/#{thread}##{postNumber}" if Conf['Persistent QR'] or QR.cooldown.auto reply.rm() else QR.close() - if g.REPLY and (Conf['Unread Count'] or Conf['Unread Favicon']) + if Main.REPLY and (Conf['Unread Count'] or Conf['Unread Favicon']) Unread.foresee.push postNumber - if g.REPLY and Conf['Thread Updater'] and Conf['Auto Update This'] + if Main.REPLY and Conf['Thread Updater'] and Conf['Auto Update This'] Updater.update() QR.status() @@ -1904,8 +1903,8 @@ Options = $.add ul, li $.add $('#main_tab + div', dialog), ul - hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} - hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length + hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} + hiddenNum = Object.keys(Main.hiddenReplies).length + Object.keys(hiddenThreads).length li = $.el 'li', innerHTML: " : Forget all hidden posts. Useful if you accidentally hide a post and have \"Show Stubs\" disabled." $.on $('button', li), 'click', Options.clearHidden @@ -1972,10 +1971,10 @@ Options = 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}/" - $.delete "hiddenThreads/#{g.BOARD}/" + $.delete "hiddenReplies/#{Main.BOARD}/" + $.delete "hiddenThreads/#{Main.BOARD}/" @textContent = "hidden: 0" - g.hiddenReplies = {} + Main.hiddenReplies = {} keybind: (e) -> return if e.keyCode is 9 e.preventDefault() @@ -2023,7 +2022,7 @@ Threading = thread: (node) -> node = Threading.op node - return if g.REPLY + return if Main.REPLY nodes = [] until node.nodeName is 'HR' @@ -2041,7 +2040,7 @@ Threading = ThreadHiding = init: -> - hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} + hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} for thread in $$ '.thread' op = thread.firstChild a = $.el 'a', @@ -2058,7 +2057,7 @@ ThreadHiding = ThreadHiding.toggle @parentNode.parentNode toggle: (thread) -> - hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} + hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} id = $('.op', thread).id if thread.hidden or thread.firstChild.className is 'block' ThreadHiding.show thread @@ -2066,7 +2065,7 @@ ThreadHiding = else ThreadHiding.hide thread hiddenThreads[id] = Date.now() - $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads + $.set "hiddenThreads/#{Main.BOARD}/", hiddenThreads hide: (thread) -> unless Conf['Show Stubs'] @@ -2175,7 +2174,7 @@ Updater = Updater.count.textContent = 404 Updater.count.className = 'warning' clearTimeout Updater.timeoutID - g.dead = true + Main.dead = true if Conf['Unread Count'] Unread.title = Unread.title.match(/^.+-/)[0] + ' 404' else @@ -2260,8 +2259,8 @@ Watcher = $.on favicon, 'click', @cb.toggle $.before input, favicon - if g.THREAD_ID is $.get 'autoWatch', 0 - @watch g.THREAD_ID + if Main.THREAD_ID is $.get 'autoWatch', 0 + @watch Main.THREAD_ID $.delete 'autoWatch' else #populate watcher, display watch buttons @@ -2290,7 +2289,7 @@ Watcher = $.rm div $.add Watcher.dialog, nodes - watchedBoard = watched[g.BOARD] or {} + watchedBoard = watched[Main.BOARD] or {} for favicon in $$ '.favicon' id = favicon.nextSibling.name if id of watchedBoard @@ -2308,7 +2307,7 @@ Watcher = toggle: (thread) -> id = $('.favicon + input', thread).name - Watcher.watch(id) or Watcher.unwatch id, g.BOARD + Watcher.watch(id) or Watcher.unwatch id, Main.BOARD unwatch: (id, board) -> watched = $.get 'watched', {} @@ -2321,9 +2320,9 @@ Watcher = return false if $('.favicon', thread).src is Favicon.default watched = $.get 'watched', {} - watched[g.BOARD] or= {} - watched[g.BOARD][id] = - href: "/#{g.BOARD}/res/#{id}" + watched[Main.BOARD] or= {} + watched[Main.BOARD][id] = + href: "/#{Main.BOARD}/res/#{id}" textContent: GetTitle thread $.set 'watched', watched Watcher.refresh() @@ -2331,7 +2330,7 @@ Watcher = Anonymize = init: -> - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return if post.class is 'inline' name = $ '.commentpostername, .postername', post.el @@ -2342,13 +2341,13 @@ Anonymize = Sauce = init: -> - return if g.BOARD is 'f' + return if Main.BOARD is 'f' @links = [] for link in Conf['sauces'].split '\n' continue if link[0] is '#' @links.push @createSauceLink link return unless @links.length - g.callbacks.push @node + Main.callbacks.push @node createSauceLink: (link) -> domain = link.match(/(\w+)\.\w+\//)[1] @@ -2361,7 +2360,7 @@ Sauce = when '$3' "' + img.firstChild.getAttribute('md5').replace(/\=*$/, '') + '" when '$4' - g.BOARD + Main.BOARD href = Function 'img', "return '#{href}'" el = $.el 'a', target: '_blank' @@ -2382,7 +2381,7 @@ Sauce = RevealSpoilers = init: -> - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> {img} = post if not (img and /^Spoil/.test img.alt) or post.class is 'inline' @@ -2412,7 +2411,7 @@ Time = hour = chanOffset + Number hour new Date year, month, day, hour, min - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return if post.class is 'inline' # .posttime exists on every board except /f/ @@ -2471,9 +2470,9 @@ Time = FileInfo = init: -> - return if g.BOARD is 'f' + return if Main.BOARD is 'f' @setFormats() - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return if post.class is 'inline' or not node = post.filesize type = if node.childElementCount is 2 then 0 else 1 @@ -2545,7 +2544,7 @@ GetTitle = (thread) -> if not el.textContent el = $ '.postername', thread span = $.el 'span', innerHTML: el.innerHTML.replace /
/g, ' ' - "/#{g.BOARD}/ - #{span.textContent}" + "/#{Main.BOARD}/ - #{span.textContent}" TitlePost = init: -> @@ -2555,7 +2554,7 @@ QuoteBacklink = init: -> format = Conf['backlink'].replace /%id/g, "' + id + '" @funk = Function 'id', "return '#{format}'" - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return if post.isInlined quotes = {} @@ -2589,7 +2588,7 @@ QuoteBacklink = QuoteInline = init: -> - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> for quote in post.quotes continue unless quote.hash @@ -2666,7 +2665,7 @@ QuoteInline = for quote in $$ '.quotelink', newInline if (href = quote.getAttribute 'href') is quote.hash #add pathname to normal quotes quote.pathname = pathname - else if !g.REPLY and href isnt quote.href #fix x-thread links, not x-board ones + else if !Main.REPLY and href isnt quote.href #fix x-thread links, not x-board ones quote.href = "res/#{href}" link = $ '.quotejs', newInline link.href = "#{pathname}##{id}" @@ -2681,7 +2680,7 @@ QuoteInline = QuotePreview = init: -> - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> for quote in post.quotes $.on quote, 'mouseover', QuotePreview.mouseover if quote.hash @@ -2748,7 +2747,7 @@ QuotePreview = QuoteOP = init: -> - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return if post.class is 'inline' for quote in post.quotes @@ -2759,7 +2758,7 @@ QuoteOP = QuoteCT = init: -> - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return if post.class is 'inline' for quote in post.quotes @@ -2768,14 +2767,14 @@ QuoteCT = continue path = quote.pathname.split '/' # If quote leads to a different thread id and is located on the same board. - if path[1] is g.BOARD and path[3] isnt post.threadId + if path[1] is Main.BOARD and path[3] isnt post.threadId # \u00A0 is nbsp $.add quote, $.tn '\u00A0(Cross-thread)' return Quotify = init: -> - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return if post.class is 'inline' @@ -2811,7 +2810,7 @@ Quotify = # \u00A0 is nbsp textContent: "#{quote}\u00A0(Dead)" - if board is g.BOARD and $.id id + if board is Main.BOARD and $.id id a.href = "##{id}" a.className = 'quotelink' a.setAttribute 'onclick', "replyhl('#{id}');" @@ -2835,14 +2834,14 @@ ReportButton = className: 'reportbutton' innerHTML: '[ ! ]' href: 'javascript:;' - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> unless a = $ '.reportbutton', post.el a = ReportButton.a.cloneNode true $.after $('span[id]', post.el), [$.tn(' '), a] $.on a, 'click', ReportButton.report report: -> - url = "//sys.4chan.org/#{g.BOARD}/imgboard.php?mode=report&no=#{$.x('preceding-sibling::input', @).name}" + url = "//sys.4chan.org/#{Main.BOARD}/imgboard.php?mode=report&no=#{$.x('preceding-sibling::input', @).name}" id = Date.now() set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200" window.open url, id, set @@ -2854,14 +2853,14 @@ ThreadStats = $.add d.body, dialog @posts = @images = 0 @imgLimit = - switch g.BOARD + switch Main.BOARD when 'a', 'mlp', 'v' 251 when 'vg' 501 else 151 - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return if post.isInlined $.id('postcount').textContent = ++ThreadStats.posts @@ -2876,7 +2875,7 @@ Unread = @title = d.title @update() $.on window, 'scroll', Unread.scroll - g.callbacks.push @node + Main.callbacks.push @node replies: [] foresee: [] @@ -2911,7 +2910,7 @@ Unread = ), 5 update: (forceUpdate) -> - return unless g.REPLY + return unless Main.REPLY count = @replies.length @@ -2922,7 +2921,7 @@ Unread = return Favicon.el.href = - if g.dead + if Main.dead if count Favicon.unreadDead else @@ -2975,19 +2974,19 @@ Redirect = url = if location.hostname is 'images.4chan.org' @image location.href - else if /^\d+$/.test g.THREAD_ID + else if /^\d+$/.test Main.THREAD_ID @thread() location.href = url if url image: (href) -> href = href.split '/' - # Do not use g.BOARD, the image url can originate from a cross-quote. + # Do not use Main.BOARD, the image url can originate from a cross-quote. return unless Conf['404 Redirect'] switch href[3] when 'a', 'jp', 'm', 'tg', 'u', 'vg' "http://archive.foolz.us/#{href[3]}/full_image/#{href[5]}" - thread: (board=g.BOARD, id=g.THREAD_ID, mode='thread') -> + thread: (board=Main.BOARD, id=Main.THREAD_ID, mode='thread') -> return unless Conf['404 Redirect'] or mode is 'post' - switch g.BOARD + switch Main.BOARD when 'a', 'jp', 'm', 'tg', 'tv', 'u', 'v', 'vg' "http://archive.foolz.us/#{board}/thread/#{id}/" when 'lit' @@ -3004,7 +3003,7 @@ Redirect = ImageHover = init: -> - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return unless post.img $.on post.img, 'mouseover', ImageHover.mouseover @@ -3030,7 +3029,7 @@ ImageHover = AutoGif = init: -> - g.callbacks.push @node + Main.callbacks.push @node node: (post) -> return if post.root.hidden or not post.img src = post.img.parentNode.href @@ -3043,7 +3042,7 @@ AutoGif = ImageExpand = init: -> - g.callbacks.push @node + Main.callbacks.push @node @dialog() node: (post) -> @@ -3125,7 +3124,7 @@ ImageExpand = ImageExpand.contract thumb $.rm @ unless @src.split('/')[2] is 'images.4chan.org' and url = Redirect.image href - return if g.dead + return if Main.dead # CloudFlare may cache banned pages instead of images. # This will fool CloudFlare's cache. url = href + '?' + Date.now() @@ -3160,12 +3159,12 @@ Main = init: -> path = location.pathname pathname = path[1..].split '/' - [g.BOARD, temp] = pathname + [Main.BOARD, temp] = pathname if temp is 'res' - g.REPLY = true - g.THREAD_ID = pathname[2] + Main.REPLY = true + Main.THREAD_ID = pathname[2] else - g.PAGENUM = parseInt(temp) or 0 + Main.PAGENUM = parseInt(temp) or 0 #load values from localStorage for key, val of Conf @@ -3192,7 +3191,7 @@ Main = $.ready Options.init - if Conf['Quick Reply'] and Conf['Hide Original Post Form'] and g.BOARD isnt 'f' + if Conf['Quick Reply'] and Conf['Hide Original Post Form'] and Main.BOARD isnt 'f' Main.css += 'form[name=post] { display: none; }' Main.addStyle() @@ -3202,23 +3201,23 @@ Main = $.ready -> $.add d.head, $.el 'script', src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js' $.set 'lastUpdate', now - g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {} + Main.hiddenReplies = $.get "hiddenReplies/#{Main.BOARD}/", {} if $.get('lastChecked', 0) < now - 1*DAY $.set 'lastChecked', now cutoff = now - 7*DAY - hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} + hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} for id, timestamp of hiddenThreads if timestamp < cutoff delete hiddenThreads[id] - for id, timestamp of g.hiddenReplies + for id, timestamp of Main.hiddenReplies if timestamp < cutoff - delete g.hiddenReplies[id] + delete Main.hiddenReplies[id] - $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads - $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies + $.set "hiddenThreads/#{Main.BOARD}/", hiddenThreads + $.set "hiddenReplies/#{Main.BOARD}/", Main.hiddenReplies #major features @@ -3284,7 +3283,7 @@ Main = $.addClass d.body, "chanx_#{VERSION.split('.')[1]}" $.addClass d.body, engine for nav in ['navtop', 'navbot'] - $.addClass $("a[href$='/#{g.BOARD}/']", $.id nav), 'current' + $.addClass $("a[href$='/#{Main.BOARD}/']", $.id nav), 'current' form = $ 'form[name=delform]' Threading.thread form.firstElementChild Favicon.init() @@ -3302,7 +3301,7 @@ Main = if Conf['Keybinds'] setTimeout -> Keybinds.init() - if g.REPLY + if Main.REPLY if Conf['Thread Updater'] setTimeout -> Updater.init() @@ -3367,7 +3366,7 @@ Main = el: if klass is 'op' then node else node.firstChild.firstChild.lastChild class: klass id: node.getElementsByTagName('input')[0].name - threadId: g.THREAD_ID or $.x('ancestor::div[@class="thread"]', node).firstChild.id + threadId: Main.THREAD_ID or $.x('ancestor::div[@class="thread"]', node).firstChild.id isOP: klass is 'op' isInlined: /\binline\b/.test klass filesize: node.getElementsByClassName('filesize')[0] or false @@ -3376,7 +3375,7 @@ Main = post.img = if post.filesize then node.getElementsByTagName('img')[0] else false post node: (nodes, notify) -> - for callback in g.callbacks + for callback in Main.callbacks try callback node for node in nodes catch err @@ -3392,6 +3391,7 @@ Main = {target} = e Main.node [Main.preParse target] if target.nodeName is 'TABLE' + callbacks: [] css: ' /* dialog styling */ .dialog {