diff --git a/4chan_x.user.js b/4chan_x.user.js index ebaed6113..3f188f15f 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -73,7 +73,7 @@ */ (function() { - var $, $$, Anonymize, AutoGif, Config, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, GetTitle, ImageExpand, ImageHover, Keybinds, Main, Nav, Options, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, ReplyHiding, ReportButton, RevealSpoilers, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Threading, Time, TitlePost, UI, Unread, Updater, Watcher, d, _base; + var $, $$, Anonymize, AutoGif, Config, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, GetTitle, ImageExpand, ImageHover, Keybinds, Main, Nav, Options, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, ReplyHiding, ReportButton, RevealSpoilers, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Threading, Time, TitlePost, UI, Unread, Updater, Watcher, d, g, _base; Config = { main: { @@ -192,6 +192,10 @@ } }; + d = document; + + g = {}; + UI = { dialog: function(id, position, html) { var el, saved; @@ -259,8 +263,6 @@ } }; - d = document; - /* loosely follows the jquery api: http://api.jquery.com/ @@ -525,7 +527,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(Main.BOARD) === -1) { + if (boards !== 'global' && boards.split(',').indexOf(g.BOARD) === -1) { continue; } try { @@ -577,7 +579,7 @@ if (!(result = filter(value, isOP))) continue; if (result === true) { if (isOP) { - if (!Main.REPLY) { + if (!g.REPLY) { ThreadHiding.hide(post.el.parentNode); } else { continue; @@ -592,7 +594,7 @@ } else { $.addClass(el.parentNode, result[0]); } - if (isOP && result[1] && !Main.REPLY) { + if (isOP && result[1] && !g.REPLY) { thisThread = el.parentNode; if (firstThread = $('div[class=op]')) { $.before(firstThread.parentNode, [thisThread, thisThread.nextElementSibling]); @@ -722,7 +724,7 @@ for (_i = 0, _len = quotes.length; _i < _len; _i++) { quote = quotes[_i]; if (quote.hash === quote.getAttribute('href')) { - quote.pathname = "/" + Main.BOARD + "/res/" + threadID; + quote.pathname = "/" + g.BOARD + "/res/" + threadID; } } post = { @@ -767,7 +769,7 @@ toggle: function(thread) { var a, backlink, num, pathname, prev, table, threadID, _i, _len, _ref, _ref2, _results; threadID = thread.firstChild.id; - pathname = "/" + Main.BOARD + "/res/" + threadID; + pathname = "/" + g.BOARD + "/res/" + threadID; a = $('.omittedposts', thread); switch (a.textContent[0]) { case '+': @@ -782,7 +784,7 @@ case '-': a.textContent = a.textContent.replace('-', '+'); num = (function() { - switch (Main.BOARD) { + switch (g.BOARD) { case 'b': case 'vg': return 3; @@ -860,7 +862,7 @@ td = ReplyHiding.td.cloneNode(true); $.on(td.firstChild, 'click', ReplyHiding.toggle); $.replace(post.el.previousSibling, td); - if (post.id in Main.hiddenReplies) return ReplyHiding.hide(post.root); + if (post.id in g.hiddenReplies) return ReplyHiding.hide(post.root); }, toggle: function() { var id, parent, quote, table, _i, _j, _len, _len2, _ref, _ref2; @@ -873,7 +875,7 @@ quote = _ref[_i]; $.addClass(quote, 'filtered'); } - Main.hiddenReplies[id] = Date.now(); + g.hiddenReplies[id] = Date.now(); } else { table = parent.nextSibling; table.hidden = false; @@ -884,9 +886,9 @@ quote = _ref2[_j]; $.removeClass(quote, 'filtered'); } - delete Main.hiddenReplies[id]; + delete g.hiddenReplies[id]; } - return $.set("hiddenReplies/" + Main.BOARD + "/", Main.hiddenReplies); + return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); }, hide: function(table) { var div, name, trip, uid, _ref, _ref2; @@ -968,7 +970,7 @@ Keybinds.img(thread, true); break; case Conf.zero: - window.location = "/" + Main.BOARD + "/0#0"; + window.location = "/" + g.BOARD + "/0#0"; break; case Conf.nextPage: if ((_ref = $('input[value=Next]')) != null) _ref.click(); @@ -977,11 +979,11 @@ if ((_ref2 = $('input[value=Previous]')) != null) _ref2.click(); break; case Conf.nextThread: - if (Main.REPLY) return; + if (g.REPLY) return; Nav.scroll(+1); break; case Conf.previousThread: - if (Main.REPLY) return; + if (g.REPLY) return; Nav.scroll(-1); break; case Conf.expandThread: @@ -1096,7 +1098,7 @@ open: function(thread, tab) { var id, url; id = thread.firstChild.id; - url = "//boards.4chan.org/" + Main.BOARD + "/res/" + id; + url = "//boards.4chan.org/" + g.BOARD + "/res/" + id; if (tab) { return $.open(url); } else { @@ -1117,7 +1119,7 @@ td.focus(); return; } - if (!(Main.REPLY || $.x('ancestor::div[@class="thread"]', next) === thread)) { + if (!(g.REPLY || $.x('ancestor::div[@class="thread"]', next) === thread)) { return; } rect = next.getBoundingClientRect(); @@ -1165,14 +1167,14 @@ return $.add(d.body, span); }, prev: function() { - if (Main.REPLY) { + if (g.REPLY) { return window.scrollTo(0, 0); } else { return Nav.scroll(-1); } }, next: function() { - if (Main.REPLY) { + if (g.REPLY) { return window.scrollTo(0, d.body.scrollHeight); } else { return Nav.scroll(+1); @@ -1215,11 +1217,11 @@ var form, iframe, link, loadChecking, script; if (Conf['Hide Original Post Form']) { link = $.el('h1', { - innerHTML: "" + (Main.REPLY ? 'Quick Reply' : 'New Thread') + "" + innerHTML: "" + (g.REPLY ? 'Quick Reply' : 'New Thread') + "" }); $.on($('a', link), 'click', function() { QR.open(); - if (!Main.REPLY) $('select', QR.el).value = 'new'; + if (!g.REPLY) $('select', QR.el).value = 'new'; return $('textarea', QR.el).focus(); }); form = d.forms[0]; @@ -1334,7 +1336,7 @@ value = 'Loading'; disabled = true; } - if (Main.dead) { + if (g.dead) { value = 404; disabled = true; QR.cooldown.auto = false; @@ -1352,8 +1354,8 @@ cooldown: { init: function() { if (!Conf['Cooldown']) return; - QR.cooldown.start($.get("/" + Main.BOARD + "/cooldown", 0)); - return $.sync("/" + Main.BOARD + "/cooldown", QR.cooldown.start); + QR.cooldown.start($.get("/" + g.BOARD + "/cooldown", 0)); + return $.sync("/" + g.BOARD + "/cooldown", QR.cooldown.start); }, start: function(timeout) { var seconds; @@ -1363,14 +1365,14 @@ set: function(seconds) { if (!Conf['Cooldown']) return; QR.cooldown.count(seconds); - return $.set("/" + Main.BOARD + "/cooldown", Date.now() + seconds * $.SECOND); + return $.set("/" + g.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"]("/" + Main.BOARD + "/cooldown"); + $["delete"]("/" + g.BOARD + "/cooldown"); if (QR.cooldown.auto) QR.submit(); } return QR.status(); @@ -1380,7 +1382,7 @@ var caretPos, id, range, s, sel, ta, text, _ref; if (e != null) e.preventDefault(); QR.open(); - if (!Main.REPLY) { + if (!g.REPLY) { $('select', QR.el).value = $.x('ancestor::div[@class="thread"]', this).firstChild.id; } id = this.previousElementSibling.hash.slice(1); @@ -1742,7 +1744,7 @@ QR.spoiler = !!$('#com_submit + label'); spoiler = $('#spoilerLabel', QR.el); spoiler.hidden = !QR.spoiler; - if (!Main.REPLY) { + if (!g.REPLY) { threads = ''; _ref = $$('.op'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -1850,7 +1852,7 @@ return; } QR.cleanError(); - threadID = Main.THREAD_ID || $('select', QR.el).value; + threadID = g.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') { @@ -1937,12 +1939,12 @@ if (Conf['Thread Watcher'] && Conf['Auto Watch']) { $.set('autoWatch', postNumber); } - location.pathname = "/" + Main.BOARD + "/res/" + postNumber; + location.pathname = "/" + g.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'] && !Main.REPLY && !QR.cooldown.auto) { - $.open("//boards.4chan.org/" + Main.BOARD + "/res/" + thread + "#" + postNumber); + if (Conf['Open Reply in New Tab'] && !g.REPLY && !QR.cooldown.auto) { + $.open("//boards.4chan.org/" + g.BOARD + "/res/" + thread + "#" + postNumber); } } if (Conf['Persistent QR'] || QR.cooldown.auto) { @@ -1950,10 +1952,10 @@ } else { QR.close(); } - if (Main.REPLY && (Conf['Unread Count'] || Conf['Unread Favicon'])) { + if (g.REPLY && (Conf['Unread Count'] || Conf['Unread Favicon'])) { Unread.foresee.push(postNumber); } - if (Main.REPLY && Conf['Thread Updater'] && Conf['Auto Update This']) { + if (g.REPLY && Conf['Thread Updater'] && Conf['Auto Update This']) { Updater.update(); } QR.status(); @@ -2237,8 +2239,8 @@ } $.add($('#main_tab + div', dialog), ul); } - hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); - hiddenNum = Object.keys(Main.hiddenReplies).length + Object.keys(hiddenThreads).length; + hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); + hiddenNum = Object.keys(g.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." }); @@ -2309,10 +2311,10 @@ return d.body.style.removeProperty('overflow'); }, clearHidden: function() { - $["delete"]("hiddenReplies/" + Main.BOARD + "/"); - $["delete"]("hiddenThreads/" + Main.BOARD + "/"); + $["delete"]("hiddenReplies/" + g.BOARD + "/"); + $["delete"]("hiddenThreads/" + g.BOARD + "/"); this.textContent = "hidden: 0"; - return Main.hiddenReplies = {}; + return g.hiddenReplies = {}; }, keybind: function(e) { var key; @@ -2373,7 +2375,7 @@ thread: function(node) { var div, nodes; node = Threading.op(node); - if (Main.REPLY) return; + if (g.REPLY) return; nodes = []; while (node.nodeName !== 'HR') { nodes.push(node); @@ -2394,7 +2396,7 @@ ThreadHiding = { init: function() { var a, hiddenThreads, op, thread, _i, _len, _ref; - hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); + hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); _ref = $$('.thread'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { thread = _ref[_i]; @@ -2413,7 +2415,7 @@ }, toggle: function(thread) { var hiddenThreads, id; - hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); + hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); id = $('.op', thread).id; if (thread.hidden || thread.firstChild.className === 'block') { ThreadHiding.show(thread); @@ -2422,7 +2424,7 @@ ThreadHiding.hide(thread); hiddenThreads[id] = Date.now(); } - return $.set("hiddenThreads/" + Main.BOARD + "/", hiddenThreads); + return $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); }, hide: function(thread) { var a, div, name, num, op, span, text, trip, uid, _ref, _ref2; @@ -2540,7 +2542,7 @@ Updater.count.textContent = 404; Updater.count.className = 'warning'; clearTimeout(Updater.timeoutID); - Main.dead = true; + g.dead = true; if (Conf['Unread Count']) { Unread.title = Unread.title.match(/^.+-/)[0] + ' 404'; } else { @@ -2637,8 +2639,8 @@ $.on(favicon, 'click', this.cb.toggle); $.before(input, favicon); } - if (Main.THREAD_ID === $.get('autoWatch', 0)) { - this.watch(Main.THREAD_ID); + if (g.THREAD_ID === $.get('autoWatch', 0)) { + this.watch(g.THREAD_ID); $["delete"]('autoWatch'); } else { this.refresh(); @@ -2671,7 +2673,7 @@ $.rm(div); } $.add(Watcher.dialog, nodes); - watchedBoard = watched[Main.BOARD] || {}; + watchedBoard = watched[g.BOARD] || {}; _ref3 = $$('.favicon'); for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { favicon = _ref3[_j]; @@ -2696,7 +2698,7 @@ toggle: function(thread) { var id; id = $('.favicon + input', thread).name; - return Watcher.watch(id) || Watcher.unwatch(id, Main.BOARD); + return Watcher.watch(id) || Watcher.unwatch(id, g.BOARD); }, unwatch: function(id, board) { var watched; @@ -2710,9 +2712,9 @@ thread = $.id(id); if ($('.favicon', thread).src === Favicon["default"]) return false; watched = $.get('watched', {}); - watched[_name = Main.BOARD] || (watched[_name] = {}); - watched[Main.BOARD][id] = { - href: "/" + Main.BOARD + "/res/" + id, + watched[_name = g.BOARD] || (watched[_name] = {}); + watched[g.BOARD][id] = { + href: "/" + g.BOARD + "/res/" + id, textContent: GetTitle(thread) }; $.set('watched', watched); @@ -2740,7 +2742,7 @@ Sauce = { init: function() { var link, _i, _len, _ref; - if (Main.BOARD === 'f') return; + if (g.BOARD === 'f') return; this.links = []; _ref = Conf['sauces'].split('\n'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -2763,7 +2765,7 @@ case '$3': return "' + img.firstChild.getAttribute('md5').replace(/\=*$/, '') + '"; case '$4': - return Main.BOARD; + return g.BOARD; } }); href = Function('img', "return '" + href + "'"); @@ -2914,7 +2916,7 @@ FileInfo = { init: function() { - if (Main.BOARD === 'f') return; + if (g.BOARD === 'f') return; this.setFormats(); return Main.callbacks.push(this.node); }, @@ -3024,7 +3026,7 @@ span = $.el('span', { innerHTML: el.innerHTML.replace(/
/g, ' ') }); - return "/" + Main.BOARD + "/ - " + span.textContent; + return "/" + g.BOARD + "/ - " + span.textContent; }; TitlePost = { @@ -3178,7 +3180,7 @@ quote = _ref[_i]; if ((href = quote.getAttribute('href')) === quote.hash) { quote.pathname = pathname; - } else if (!Main.REPLY && href !== quote.href) { + } else if (!g.REPLY && href !== quote.href) { quote.href = "res/" + href; } } @@ -3305,7 +3307,7 @@ quote = _ref[_i]; if (!quote.hash) continue; path = quote.pathname.split('/'); - if (path[1] === Main.BOARD && path[3] !== post.threadId) { + if (path[1] === g.BOARD && path[3] !== post.threadId) { $.add(quote, $.tn('\u00A0(Cross-thread)')); } } @@ -3334,7 +3336,7 @@ nodes.push(a = $.el('a', { textContent: "" + quote + "\u00A0(Dead)" })); - if (board === Main.BOARD && $.id(id)) { + if (board === g.BOARD && $.id(id)) { a.href = "#" + id; a.className = 'quotelink'; a.setAttribute('onclick', "replyhl('" + id + "');"); @@ -3370,7 +3372,7 @@ }, report: function() { var id, set, url; - url = "//sys.4chan.org/" + Main.BOARD + "/imgboard.php?mode=report&no=" + ($.x('preceding-sibling::input', this).name); + url = "//sys.4chan.org/" + g.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); @@ -3385,7 +3387,7 @@ $.add(d.body, dialog); this.posts = this.images = 0; this.imgLimit = (function() { - switch (Main.BOARD) { + switch (g.BOARD) { case 'a': case 'mlp': case 'v': @@ -3456,11 +3458,11 @@ }, update: function(forceUpdate) { var count; - if (!Main.REPLY) return; + if (!g.REPLY) return; count = this.replies.length; if (Conf['Unread Count']) this.setTitle(count); if (!(Conf['Unread Favicon'] && (count < 2 || forceUpdate))) return; - Favicon.el.href = Main.dead ? count ? Favicon.unreadDead : Favicon.dead : count ? Favicon.unread : Favicon["default"]; + Favicon.el.href = g.dead ? count ? Favicon.unreadDead : Favicon.dead : count ? Favicon.unread : Favicon["default"]; return $.add(d.head, Favicon.el); } }; @@ -3506,7 +3508,7 @@ Redirect = { init: function() { var url; - url = location.hostname === 'images.4chan.org' ? this.image(location.href) : /^\d+$/.test(Main.THREAD_ID) ? this.thread() : void 0; + url = location.hostname === 'images.4chan.org' ? this.image(location.href) : /^\d+$/.test(g.THREAD_ID) ? this.thread() : void 0; if (url) return location.href = url; }, image: function(href) { @@ -3523,11 +3525,11 @@ } }, thread: function(board, id, mode) { - if (board == null) board = Main.BOARD; - if (id == null) id = Main.THREAD_ID; + if (board == null) board = g.BOARD; + if (id == null) id = g.THREAD_ID; if (mode == null) mode = 'thread'; if (!(Conf['404 Redirect'] || mode === 'post')) return; - switch (Main.BOARD) { + switch (g.BOARD) { case 'a': case 'jp': case 'm': @@ -3737,7 +3739,7 @@ ImageExpand.contract(thumb); $.rm(this); if (!(this.src.split('/')[2] === 'images.4chan.org' && (url = Redirect.image(href)))) { - if (Main.dead) return; + if (g.dead) return; url = href + '?' + Date.now(); } timeoutID = setTimeout(ImageExpand.expand, 10000, thumb, url); @@ -3792,12 +3794,12 @@ })(null, Config); path = location.pathname; pathname = path.slice(1).split('/'); - Main.BOARD = pathname[0], temp = pathname[1]; + g.BOARD = pathname[0], temp = pathname[1]; if (temp === 'res') { - Main.REPLY = true; - Main.THREAD_ID = pathname[2]; + g.REPLY = true; + g.THREAD_ID = pathname[2]; } else { - Main.PAGENUM = parseInt(temp) || 0; + g.PAGENUM = parseInt(temp) || 0; } for (key in Conf) { val = Conf[key]; @@ -3837,7 +3839,7 @@ return; } $.ready(Options.init); - if (Conf['Quick Reply'] && Conf['Hide Original Post Form'] && Main.BOARD !== 'f') { + if (Conf['Quick Reply'] && Conf['Hide Original Post Form'] && g.BOARD !== 'f') { Main.css += 'form[name=post] { display: none; }'; } Main.addStyle(); @@ -3850,22 +3852,22 @@ }); $.set('lastUpdate', now); } - Main.hiddenReplies = $.get("hiddenReplies/" + Main.BOARD + "/", {}); + g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); if ($.get('lastChecked', 0) < now - 1 * $.DAY) { $.set('lastChecked', now); cutoff = now - 7 * $.DAY; - hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); + hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); for (id in hiddenThreads) { timestamp = hiddenThreads[id]; if (timestamp < cutoff) delete hiddenThreads[id]; } - _ref = Main.hiddenReplies; + _ref = g.hiddenReplies; for (id in _ref) { timestamp = _ref[id]; - if (timestamp < cutoff) delete Main.hiddenReplies[id]; + if (timestamp < cutoff) delete g.hiddenReplies[id]; } - $.set("hiddenThreads/" + Main.BOARD + "/", hiddenThreads); - $.set("hiddenReplies/" + Main.BOARD + "/", Main.hiddenReplies); + $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); + $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); } if (Conf['Filter']) Filter.init(); if (Conf['Reply Hiding']) ReplyHiding.init(); @@ -3898,7 +3900,7 @@ _ref = ['navtop', 'navbot']; for (_i = 0, _len = _ref.length; _i < _len; _i++) { nav = _ref[_i]; - $.addClass($("a[href$='/" + Main.BOARD + "/']", $.id(nav)), 'current'); + $.addClass($("a[href$='/" + g.BOARD + "/']", $.id(nav)), 'current'); } form = $('form[name=delform]'); Threading.thread(form.firstElementChild); @@ -3915,7 +3917,7 @@ return Keybinds.init(); }); } - if (Main.REPLY) { + if (g.REPLY) { if (Conf['Thread Updater']) { setTimeout(function() { return Updater.init(); @@ -3996,7 +3998,7 @@ el: klass === 'op' ? node : node.firstChild.firstChild.lastChild, "class": klass, id: node.getElementsByTagName('input')[0].name, - threadId: Main.THREAD_ID || $.x('ancestor::div[@class="thread"]', node).firstChild.id, + threadId: g.THREAD_ID || $.x('ancestor::div[@class="thread"]', node).firstChild.id, isOP: klass === 'op', isInlined: /\binline\b/.test(klass), filesize: node.getElementsByClassName('filesize')[0] || false, diff --git a/script.coffee b/script.coffee index 44dfdb85f..84b8cd353 100644 --- a/script.coffee +++ b/script.coffee @@ -155,6 +155,7 @@ Config = 'Interval': 30 d = document +g = {} UI = dialog: (id, position, html) -> @@ -454,7 +455,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(Main.BOARD) is -1 + if boards isnt 'global' and boards.split(',').indexOf(g.BOARD) is -1 continue try @@ -523,7 +524,7 @@ Filter = # Hide if result is true if isOP - unless Main.REPLY + unless g.REPLY ThreadHiding.hide post.el.parentNode else continue @@ -536,7 +537,7 @@ Filter = $.addClass el, result[0] else $.addClass el.parentNode, result[0] - if isOP and result[1] and not Main.REPLY + if isOP and result[1] and not g.REPLY # Put the highlighted OPs' threads on top of the board pages... thisThread = el.parentNode # ...before the first non highlighted thread. @@ -632,7 +633,7 @@ ExpandComment = quotes = node.getElementsByClassName 'quotelink' for quote in quotes if quote.hash is quote.getAttribute 'href' - quote.pathname = "/#{Main.BOARD}/res/#{threadID}" + quote.pathname = "/#{g.BOARD}/res/#{threadID}" post = el: node threadId: threadID @@ -667,7 +668,7 @@ ExpandThread = toggle: (thread) -> threadID = thread.firstChild.id - pathname = "/#{Main.BOARD}/res/#{threadID}" + pathname = "/#{g.BOARD}/res/#{threadID}" a = $ '.omittedposts', thread # \u00d7 is × @@ -685,7 +686,7 @@ ExpandThread = when '-' a.textContent = a.textContent.replace '-', '+' #goddamit moot - num = switch Main.BOARD + num = switch g.BOARD when 'b', 'vg' then 3 when 't' then 1 else 5 @@ -738,7 +739,7 @@ ReplyHiding = $.on td.firstChild, 'click', ReplyHiding.toggle $.replace post.el.previousSibling, td - if post.id of Main.hiddenReplies + if post.id of g.hiddenReplies ReplyHiding.hide post.root toggle: -> @@ -748,7 +749,7 @@ ReplyHiding = id = parent.nextSibling.id for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']" $.addClass quote, 'filtered' - Main.hiddenReplies[id] = Date.now() + g.hiddenReplies[id] = Date.now() else table = parent.nextSibling table.hidden = false @@ -756,8 +757,8 @@ ReplyHiding = id = table.firstChild.firstChild.lastChild.id for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']" $.removeClass quote, 'filtered' - delete Main.hiddenReplies[id] - $.set "hiddenReplies/#{Main.BOARD}/", Main.hiddenReplies + delete g.hiddenReplies[id] + $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies hide: (table) -> return if table.hidden # already hidden by filter @@ -833,17 +834,17 @@ Keybinds = Keybinds.img thread, true # Board Navigation when Conf.zero - window.location = "/#{Main.BOARD}/0#0" + window.location = "/#{g.BOARD}/0#0" when Conf.nextPage $('input[value=Next]')?.click() when Conf.previousPage $('input[value=Previous]')?.click() # Thread Navigation when Conf.nextThread - return if Main.REPLY + return if g.REPLY Nav.scroll +1 when Conf.previousThread - return if Main.REPLY + return if g.REPLY Nav.scroll -1 when Conf.expandThread ExpandThread.toggle thread @@ -902,7 +903,7 @@ Keybinds = open: (thread, tab) -> id = thread.firstChild.id - url = "//boards.4chan.org/#{Main.BOARD}/res/#{id}" + url = "//boards.4chan.org/#{g.BOARD}/res/#{id}" if tab $.open url else @@ -924,7 +925,7 @@ Keybinds = td.tabIndex = 0 td.focus() return - return unless Main.REPLY or $.x('ancestor::div[@class="thread"]', next) is thread + return unless g.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 @@ -962,13 +963,13 @@ Nav = $.add d.body, span prev: -> - if Main.REPLY + if g.REPLY window.scrollTo 0, 0 else Nav.scroll -1 next: -> - if Main.REPLY + if g.REPLY window.scrollTo 0, d.body.scrollHeight else Nav.scroll +1 @@ -1005,10 +1006,10 @@ QR = asyncInit: -> if Conf['Hide Original Post Form'] - link = $.el 'h1', innerHTML: "#{if Main.REPLY then 'Quick Reply' else 'New Thread'}" + link = $.el 'h1', innerHTML: "#{if g.REPLY then 'Quick Reply' else 'New Thread'}" $.on $('a', link), 'click', -> QR.open() - $('select', QR.el).value = 'new' unless Main.REPLY + $('select', QR.el).value = 'new' unless g.REPLY $('textarea', QR.el).focus() form = d.forms[0] $.before form, link @@ -1093,7 +1094,7 @@ QR = else unless QR.status.ready value = 'Loading' disabled = true - if Main.dead + if g.dead value = 404 disabled = true QR.cooldown.auto = false @@ -1115,28 +1116,28 @@ QR = cooldown: init: -> return unless Conf['Cooldown'] - QR.cooldown.start $.get "/#{Main.BOARD}/cooldown", 0 - $.sync "/#{Main.BOARD}/cooldown", QR.cooldown.start + QR.cooldown.start $.get "/#{g.BOARD}/cooldown", 0 + $.sync "/#{g.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 "/#{Main.BOARD}/cooldown", Date.now() + seconds*$.SECOND + $.set "/#{g.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 "/#{Main.BOARD}/cooldown" + $.delete "/#{g.BOARD}/cooldown" QR.submit() if QR.cooldown.auto QR.status() quote: (e) -> e?.preventDefault() QR.open() - unless Main.REPLY + unless g.REPLY $('select', QR.el).value = $.x('ancestor::div[@class="thread"]', @).firstChild.id # Make sure we get the correct number, even with XXX censors @@ -1446,7 +1447,7 @@ QR = spoiler = $ '#spoilerLabel', QR.el spoiler.hidden = !QR.spoiler - unless Main.REPLY + unless g.REPLY # Make a list with visible threads and an option to create a new one. threads = '' for thread in $$ '.op' @@ -1536,7 +1537,7 @@ QR = return QR.cleanError() - threadID = Main.THREAD_ID or $('select', QR.el).value + threadID = g.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 @@ -1625,22 +1626,22 @@ QR = if Conf['Thread Watcher'] and Conf['Auto Watch'] $.set 'autoWatch', postNumber # auto-noko - location.pathname = "/#{Main.BOARD}/res/#{postNumber}" + location.pathname = "/#{g.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'] && !Main.REPLY && !QR.cooldown.auto - $.open "//boards.4chan.org/#{Main.BOARD}/res/#{thread}##{postNumber}" + if Conf['Open Reply in New Tab'] && !g.REPLY && !QR.cooldown.auto + $.open "//boards.4chan.org/#{g.BOARD}/res/#{thread}##{postNumber}" if Conf['Persistent QR'] or QR.cooldown.auto reply.rm() else QR.close() - if Main.REPLY and (Conf['Unread Count'] or Conf['Unread Favicon']) + if g.REPLY and (Conf['Unread Count'] or Conf['Unread Favicon']) Unread.foresee.push postNumber - if Main.REPLY and Conf['Thread Updater'] and Conf['Auto Update This'] + if g.REPLY and Conf['Thread Updater'] and Conf['Auto Update This'] Updater.update() QR.status() @@ -1887,8 +1888,8 @@ Options = $.add ul, li $.add $('#main_tab + div', dialog), ul - hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} - hiddenNum = Object.keys(Main.hiddenReplies).length + Object.keys(hiddenThreads).length + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} + hiddenNum = Object.keys(g.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 @@ -1955,10 +1956,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/#{Main.BOARD}/" - $.delete "hiddenThreads/#{Main.BOARD}/" + $.delete "hiddenReplies/#{g.BOARD}/" + $.delete "hiddenThreads/#{g.BOARD}/" @textContent = "hidden: 0" - Main.hiddenReplies = {} + g.hiddenReplies = {} keybind: (e) -> return if e.keyCode is 9 e.preventDefault() @@ -2006,7 +2007,7 @@ Threading = thread: (node) -> node = Threading.op node - return if Main.REPLY + return if g.REPLY nodes = [] until node.nodeName is 'HR' @@ -2024,7 +2025,7 @@ Threading = ThreadHiding = init: -> - hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} for thread in $$ '.thread' op = thread.firstChild a = $.el 'a', @@ -2041,7 +2042,7 @@ ThreadHiding = ThreadHiding.toggle @parentNode.parentNode toggle: (thread) -> - hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} id = $('.op', thread).id if thread.hidden or thread.firstChild.className is 'block' ThreadHiding.show thread @@ -2049,7 +2050,7 @@ ThreadHiding = else ThreadHiding.hide thread hiddenThreads[id] = Date.now() - $.set "hiddenThreads/#{Main.BOARD}/", hiddenThreads + $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads hide: (thread) -> unless Conf['Show Stubs'] @@ -2158,7 +2159,7 @@ Updater = Updater.count.textContent = 404 Updater.count.className = 'warning' clearTimeout Updater.timeoutID - Main.dead = true + g.dead = true if Conf['Unread Count'] Unread.title = Unread.title.match(/^.+-/)[0] + ' 404' else @@ -2243,8 +2244,8 @@ Watcher = $.on favicon, 'click', @cb.toggle $.before input, favicon - if Main.THREAD_ID is $.get 'autoWatch', 0 - @watch Main.THREAD_ID + if g.THREAD_ID is $.get 'autoWatch', 0 + @watch g.THREAD_ID $.delete 'autoWatch' else #populate watcher, display watch buttons @@ -2273,7 +2274,7 @@ Watcher = $.rm div $.add Watcher.dialog, nodes - watchedBoard = watched[Main.BOARD] or {} + watchedBoard = watched[g.BOARD] or {} for favicon in $$ '.favicon' id = favicon.nextSibling.name if id of watchedBoard @@ -2291,7 +2292,7 @@ Watcher = toggle: (thread) -> id = $('.favicon + input', thread).name - Watcher.watch(id) or Watcher.unwatch id, Main.BOARD + Watcher.watch(id) or Watcher.unwatch id, g.BOARD unwatch: (id, board) -> watched = $.get 'watched', {} @@ -2304,9 +2305,9 @@ Watcher = return false if $('.favicon', thread).src is Favicon.default watched = $.get 'watched', {} - watched[Main.BOARD] or= {} - watched[Main.BOARD][id] = - href: "/#{Main.BOARD}/res/#{id}" + watched[g.BOARD] or= {} + watched[g.BOARD][id] = + href: "/#{g.BOARD}/res/#{id}" textContent: GetTitle thread $.set 'watched', watched Watcher.refresh() @@ -2325,7 +2326,7 @@ Anonymize = Sauce = init: -> - return if Main.BOARD is 'f' + return if g.BOARD is 'f' @links = [] for link in Conf['sauces'].split '\n' continue if link[0] is '#' @@ -2344,7 +2345,7 @@ Sauce = when '$3' "' + img.firstChild.getAttribute('md5').replace(/\=*$/, '') + '" when '$4' - Main.BOARD + g.BOARD href = Function 'img', "return '#{href}'" el = $.el 'a', target: '_blank' @@ -2454,7 +2455,7 @@ Time = FileInfo = init: -> - return if Main.BOARD is 'f' + return if g.BOARD is 'f' @setFormats() Main.callbacks.push @node node: (post) -> @@ -2528,7 +2529,7 @@ GetTitle = (thread) -> if not el.textContent el = $ '.postername', thread span = $.el 'span', innerHTML: el.innerHTML.replace /
/g, ' ' - "/#{Main.BOARD}/ - #{span.textContent}" + "/#{g.BOARD}/ - #{span.textContent}" TitlePost = init: -> @@ -2649,7 +2650,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 !Main.REPLY and href isnt quote.href #fix x-thread links, not x-board ones + else if !g.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}" @@ -2751,7 +2752,7 @@ 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 Main.BOARD and path[3] isnt post.threadId + if path[1] is g.BOARD and path[3] isnt post.threadId # \u00A0 is nbsp $.add quote, $.tn '\u00A0(Cross-thread)' return @@ -2794,7 +2795,7 @@ Quotify = # \u00A0 is nbsp textContent: "#{quote}\u00A0(Dead)" - if board is Main.BOARD and $.id id + if board is g.BOARD and $.id id a.href = "##{id}" a.className = 'quotelink' a.setAttribute 'onclick', "replyhl('#{id}');" @@ -2825,7 +2826,7 @@ ReportButton = $.after $('span[id]', post.el), [$.tn(' '), a] $.on a, 'click', ReportButton.report report: -> - url = "//sys.4chan.org/#{Main.BOARD}/imgboard.php?mode=report&no=#{$.x('preceding-sibling::input', @).name}" + url = "//sys.4chan.org/#{g.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 @@ -2837,7 +2838,7 @@ ThreadStats = $.add d.body, dialog @posts = @images = 0 @imgLimit = - switch Main.BOARD + switch g.BOARD when 'a', 'mlp', 'v' 251 when 'vg' @@ -2894,7 +2895,7 @@ Unread = ), 5 update: (forceUpdate) -> - return unless Main.REPLY + return unless g.REPLY count = @replies.length @@ -2905,7 +2906,7 @@ Unread = return Favicon.el.href = - if Main.dead + if g.dead if count Favicon.unreadDead else @@ -2958,19 +2959,19 @@ Redirect = url = if location.hostname is 'images.4chan.org' @image location.href - else if /^\d+$/.test Main.THREAD_ID + else if /^\d+$/.test g.THREAD_ID @thread() location.href = url if url image: (href) -> href = href.split '/' - # Do not use Main.BOARD, the image url can originate from a cross-quote. + # Do not use g.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=Main.BOARD, id=Main.THREAD_ID, mode='thread') -> + thread: (board=g.BOARD, id=g.THREAD_ID, mode='thread') -> return unless Conf['404 Redirect'] or mode is 'post' - switch Main.BOARD + switch g.BOARD when 'a', 'jp', 'm', 'tg', 'tv', 'u', 'v', 'vg' "http://archive.foolz.us/#{board}/thread/#{id}/" when 'lit' @@ -3108,7 +3109,7 @@ ImageExpand = ImageExpand.contract thumb $.rm @ unless @src.split('/')[2] is 'images.4chan.org' and url = Redirect.image href - return if Main.dead + return if g.dead # CloudFlare may cache banned pages instead of images. # This will fool CloudFlare's cache. url = href + '?' + Date.now() @@ -3156,12 +3157,12 @@ Main = path = location.pathname pathname = path[1..].split '/' - [Main.BOARD, temp] = pathname + [g.BOARD, temp] = pathname if temp is 'res' - Main.REPLY = true - Main.THREAD_ID = pathname[2] + g.REPLY = true + g.THREAD_ID = pathname[2] else - Main.PAGENUM = parseInt(temp) or 0 + g.PAGENUM = parseInt(temp) or 0 #load values from localStorage for key, val of Conf @@ -3188,7 +3189,7 @@ Main = $.ready Options.init - if Conf['Quick Reply'] and Conf['Hide Original Post Form'] and Main.BOARD isnt 'f' + if Conf['Quick Reply'] and Conf['Hide Original Post Form'] and g.BOARD isnt 'f' Main.css += 'form[name=post] { display: none; }' Main.addStyle() @@ -3198,23 +3199,23 @@ Main = $.ready -> $.add d.head, $.el 'script', src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js' $.set 'lastUpdate', now - Main.hiddenReplies = $.get "hiddenReplies/#{Main.BOARD}/", {} + g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {} if $.get('lastChecked', 0) < now - 1*$.DAY $.set 'lastChecked', now cutoff = now - 7*$.DAY - hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} for id, timestamp of hiddenThreads if timestamp < cutoff delete hiddenThreads[id] - for id, timestamp of Main.hiddenReplies + for id, timestamp of g.hiddenReplies if timestamp < cutoff - delete Main.hiddenReplies[id] + delete g.hiddenReplies[id] - $.set "hiddenThreads/#{Main.BOARD}/", hiddenThreads - $.set "hiddenReplies/#{Main.BOARD}/", Main.hiddenReplies + $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads + $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies #major features @@ -3280,7 +3281,7 @@ Main = $.addClass d.body, "chanx_#{Main.version.split('.')[1]}" $.addClass d.body, $.engine for nav in ['navtop', 'navbot'] - $.addClass $("a[href$='/#{Main.BOARD}/']", $.id nav), 'current' + $.addClass $("a[href$='/#{g.BOARD}/']", $.id nav), 'current' form = $ 'form[name=delform]' Threading.thread form.firstElementChild Favicon.init() @@ -3298,7 +3299,7 @@ Main = if Conf['Keybinds'] setTimeout -> Keybinds.init() - if Main.REPLY + if g.REPLY if Conf['Thread Updater'] setTimeout -> Updater.init() @@ -3363,7 +3364,7 @@ Main = el: if klass is 'op' then node else node.firstChild.firstChild.lastChild class: klass id: node.getElementsByTagName('input')[0].name - threadId: Main.THREAD_ID or $.x('ancestor::div[@class="thread"]', node).firstChild.id + threadId: g.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