undo half of g -> Main

namespace, version, callbacks still in Main
This commit is contained in:
James Campos 2012-03-16 04:18:44 -07:00
parent 5dafc95c5d
commit 267d1885b9
2 changed files with 164 additions and 161 deletions

View File

@ -73,7 +73,7 @@
*/ */
(function() { (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 = { Config = {
main: { main: {
@ -192,6 +192,10 @@
} }
}; };
d = document;
g = {};
UI = { UI = {
dialog: function(id, position, html) { dialog: function(id, position, html) {
var el, saved; var el, saved;
@ -259,8 +263,6 @@
} }
}; };
d = document;
/* /*
loosely follows the jquery api: loosely follows the jquery api:
http://api.jquery.com/ http://api.jquery.com/
@ -525,7 +527,7 @@
if (!(regexp = filter.match(/\/(.+)\/(\w*)/))) continue; if (!(regexp = filter.match(/\/(.+)\/(\w*)/))) continue;
filter = filter.replace(regexp[0], ''); filter = filter.replace(regexp[0], '');
boards = ((_ref2 = filter.match(/boards:([^;]+)/)) != null ? _ref2[1].toLowerCase() : void 0) || 'global'; 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; continue;
} }
try { try {
@ -577,7 +579,7 @@
if (!(result = filter(value, isOP))) continue; if (!(result = filter(value, isOP))) continue;
if (result === true) { if (result === true) {
if (isOP) { if (isOP) {
if (!Main.REPLY) { if (!g.REPLY) {
ThreadHiding.hide(post.el.parentNode); ThreadHiding.hide(post.el.parentNode);
} else { } else {
continue; continue;
@ -592,7 +594,7 @@
} else { } else {
$.addClass(el.parentNode, result[0]); $.addClass(el.parentNode, result[0]);
} }
if (isOP && result[1] && !Main.REPLY) { if (isOP && result[1] && !g.REPLY) {
thisThread = el.parentNode; thisThread = el.parentNode;
if (firstThread = $('div[class=op]')) { if (firstThread = $('div[class=op]')) {
$.before(firstThread.parentNode, [thisThread, thisThread.nextElementSibling]); $.before(firstThread.parentNode, [thisThread, thisThread.nextElementSibling]);
@ -722,7 +724,7 @@
for (_i = 0, _len = quotes.length; _i < _len; _i++) { for (_i = 0, _len = quotes.length; _i < _len; _i++) {
quote = quotes[_i]; quote = quotes[_i];
if (quote.hash === quote.getAttribute('href')) { if (quote.hash === quote.getAttribute('href')) {
quote.pathname = "/" + Main.BOARD + "/res/" + threadID; quote.pathname = "/" + g.BOARD + "/res/" + threadID;
} }
} }
post = { post = {
@ -767,7 +769,7 @@
toggle: function(thread) { toggle: function(thread) {
var a, backlink, num, pathname, prev, table, threadID, _i, _len, _ref, _ref2, _results; var a, backlink, num, pathname, prev, table, threadID, _i, _len, _ref, _ref2, _results;
threadID = thread.firstChild.id; threadID = thread.firstChild.id;
pathname = "/" + Main.BOARD + "/res/" + threadID; pathname = "/" + g.BOARD + "/res/" + threadID;
a = $('.omittedposts', thread); a = $('.omittedposts', thread);
switch (a.textContent[0]) { switch (a.textContent[0]) {
case '+': case '+':
@ -782,7 +784,7 @@
case '-': case '-':
a.textContent = a.textContent.replace('-', '+'); a.textContent = a.textContent.replace('-', '+');
num = (function() { num = (function() {
switch (Main.BOARD) { switch (g.BOARD) {
case 'b': case 'b':
case 'vg': case 'vg':
return 3; return 3;
@ -860,7 +862,7 @@
td = ReplyHiding.td.cloneNode(true); td = ReplyHiding.td.cloneNode(true);
$.on(td.firstChild, 'click', ReplyHiding.toggle); $.on(td.firstChild, 'click', ReplyHiding.toggle);
$.replace(post.el.previousSibling, td); $.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() { toggle: function() {
var id, parent, quote, table, _i, _j, _len, _len2, _ref, _ref2; var id, parent, quote, table, _i, _j, _len, _len2, _ref, _ref2;
@ -873,7 +875,7 @@
quote = _ref[_i]; quote = _ref[_i];
$.addClass(quote, 'filtered'); $.addClass(quote, 'filtered');
} }
Main.hiddenReplies[id] = Date.now(); g.hiddenReplies[id] = Date.now();
} else { } else {
table = parent.nextSibling; table = parent.nextSibling;
table.hidden = false; table.hidden = false;
@ -884,9 +886,9 @@
quote = _ref2[_j]; quote = _ref2[_j];
$.removeClass(quote, 'filtered'); $.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) { hide: function(table) {
var div, name, trip, uid, _ref, _ref2; var div, name, trip, uid, _ref, _ref2;
@ -968,7 +970,7 @@
Keybinds.img(thread, true); Keybinds.img(thread, true);
break; break;
case Conf.zero: case Conf.zero:
window.location = "/" + Main.BOARD + "/0#0"; window.location = "/" + g.BOARD + "/0#0";
break; break;
case Conf.nextPage: case Conf.nextPage:
if ((_ref = $('input[value=Next]')) != null) _ref.click(); if ((_ref = $('input[value=Next]')) != null) _ref.click();
@ -977,11 +979,11 @@
if ((_ref2 = $('input[value=Previous]')) != null) _ref2.click(); if ((_ref2 = $('input[value=Previous]')) != null) _ref2.click();
break; break;
case Conf.nextThread: case Conf.nextThread:
if (Main.REPLY) return; if (g.REPLY) return;
Nav.scroll(+1); Nav.scroll(+1);
break; break;
case Conf.previousThread: case Conf.previousThread:
if (Main.REPLY) return; if (g.REPLY) return;
Nav.scroll(-1); Nav.scroll(-1);
break; break;
case Conf.expandThread: case Conf.expandThread:
@ -1096,7 +1098,7 @@
open: function(thread, tab) { open: function(thread, tab) {
var id, url; var id, url;
id = thread.firstChild.id; id = thread.firstChild.id;
url = "//boards.4chan.org/" + Main.BOARD + "/res/" + id; url = "//boards.4chan.org/" + g.BOARD + "/res/" + id;
if (tab) { if (tab) {
return $.open(url); return $.open(url);
} else { } else {
@ -1117,7 +1119,7 @@
td.focus(); td.focus();
return; return;
} }
if (!(Main.REPLY || $.x('ancestor::div[@class="thread"]', next) === thread)) { if (!(g.REPLY || $.x('ancestor::div[@class="thread"]', next) === thread)) {
return; return;
} }
rect = next.getBoundingClientRect(); rect = next.getBoundingClientRect();
@ -1165,14 +1167,14 @@
return $.add(d.body, span); return $.add(d.body, span);
}, },
prev: function() { prev: function() {
if (Main.REPLY) { if (g.REPLY) {
return window.scrollTo(0, 0); return window.scrollTo(0, 0);
} else { } else {
return Nav.scroll(-1); return Nav.scroll(-1);
} }
}, },
next: function() { next: function() {
if (Main.REPLY) { if (g.REPLY) {
return window.scrollTo(0, d.body.scrollHeight); return window.scrollTo(0, d.body.scrollHeight);
} else { } else {
return Nav.scroll(+1); return Nav.scroll(+1);
@ -1215,11 +1217,11 @@
var form, iframe, link, loadChecking, script; var form, iframe, link, loadChecking, script;
if (Conf['Hide Original Post Form']) { if (Conf['Hide Original Post Form']) {
link = $.el('h1', { link = $.el('h1', {
innerHTML: "<a href=javascript:;>" + (Main.REPLY ? 'Quick Reply' : 'New Thread') + "</a>" innerHTML: "<a href=javascript:;>" + (g.REPLY ? 'Quick Reply' : 'New Thread') + "</a>"
}); });
$.on($('a', link), 'click', function() { $.on($('a', link), 'click', function() {
QR.open(); QR.open();
if (!Main.REPLY) $('select', QR.el).value = 'new'; if (!g.REPLY) $('select', QR.el).value = 'new';
return $('textarea', QR.el).focus(); return $('textarea', QR.el).focus();
}); });
form = d.forms[0]; form = d.forms[0];
@ -1334,7 +1336,7 @@
value = 'Loading'; value = 'Loading';
disabled = true; disabled = true;
} }
if (Main.dead) { if (g.dead) {
value = 404; value = 404;
disabled = true; disabled = true;
QR.cooldown.auto = false; QR.cooldown.auto = false;
@ -1352,8 +1354,8 @@
cooldown: { cooldown: {
init: function() { init: function() {
if (!Conf['Cooldown']) return; if (!Conf['Cooldown']) return;
QR.cooldown.start($.get("/" + Main.BOARD + "/cooldown", 0)); QR.cooldown.start($.get("/" + g.BOARD + "/cooldown", 0));
return $.sync("/" + Main.BOARD + "/cooldown", QR.cooldown.start); return $.sync("/" + g.BOARD + "/cooldown", QR.cooldown.start);
}, },
start: function(timeout) { start: function(timeout) {
var seconds; var seconds;
@ -1363,14 +1365,14 @@
set: function(seconds) { set: function(seconds) {
if (!Conf['Cooldown']) return; if (!Conf['Cooldown']) return;
QR.cooldown.count(seconds); 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) { count: function(seconds) {
if (!((0 <= seconds && seconds <= 60))) return; if (!((0 <= seconds && seconds <= 60))) return;
setTimeout(QR.cooldown.count, 1000, seconds - 1); setTimeout(QR.cooldown.count, 1000, seconds - 1);
QR.cooldown.seconds = seconds; QR.cooldown.seconds = seconds;
if (seconds === 0) { if (seconds === 0) {
$["delete"]("/" + Main.BOARD + "/cooldown"); $["delete"]("/" + g.BOARD + "/cooldown");
if (QR.cooldown.auto) QR.submit(); if (QR.cooldown.auto) QR.submit();
} }
return QR.status(); return QR.status();
@ -1380,7 +1382,7 @@
var caretPos, id, range, s, sel, ta, text, _ref; var caretPos, id, range, s, sel, ta, text, _ref;
if (e != null) e.preventDefault(); if (e != null) e.preventDefault();
QR.open(); QR.open();
if (!Main.REPLY) { if (!g.REPLY) {
$('select', QR.el).value = $.x('ancestor::div[@class="thread"]', this).firstChild.id; $('select', QR.el).value = $.x('ancestor::div[@class="thread"]', this).firstChild.id;
} }
id = this.previousElementSibling.hash.slice(1); id = this.previousElementSibling.hash.slice(1);
@ -1742,7 +1744,7 @@
QR.spoiler = !!$('#com_submit + label'); QR.spoiler = !!$('#com_submit + label');
spoiler = $('#spoilerLabel', QR.el); spoiler = $('#spoilerLabel', QR.el);
spoiler.hidden = !QR.spoiler; spoiler.hidden = !QR.spoiler;
if (!Main.REPLY) { if (!g.REPLY) {
threads = '<option value=new>New thread</option>'; threads = '<option value=new>New thread</option>';
_ref = $$('.op'); _ref = $$('.op');
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -1850,7 +1852,7 @@
return; return;
} }
QR.cleanError(); 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; QR.cooldown.auto = QR.replies.length > 1;
if (Conf['Auto Hide QR'] && !QR.cooldown.auto) QR.hide(); if (Conf['Auto Hide QR'] && !QR.cooldown.auto) QR.hide();
if (Conf['Thread Watcher'] && Conf['Auto Watch Reply'] && threadID !== 'new') { if (Conf['Thread Watcher'] && Conf['Auto Watch Reply'] && threadID !== 'new') {
@ -1937,12 +1939,12 @@
if (Conf['Thread Watcher'] && Conf['Auto Watch']) { if (Conf['Thread Watcher'] && Conf['Auto Watch']) {
$.set('autoWatch', postNumber); $.set('autoWatch', postNumber);
} }
location.pathname = "/" + Main.BOARD + "/res/" + postNumber; location.pathname = "/" + g.BOARD + "/res/" + postNumber;
} else { } else {
QR.cooldown.auto = QR.replies.length > 1; QR.cooldown.auto = QR.replies.length > 1;
QR.cooldown.set(/sage/i.test(reply.email) ? 60 : 30); QR.cooldown.set(/sage/i.test(reply.email) ? 60 : 30);
if (Conf['Open Reply in New Tab'] && !Main.REPLY && !QR.cooldown.auto) { if (Conf['Open Reply in New Tab'] && !g.REPLY && !QR.cooldown.auto) {
$.open("//boards.4chan.org/" + Main.BOARD + "/res/" + thread + "#" + postNumber); $.open("//boards.4chan.org/" + g.BOARD + "/res/" + thread + "#" + postNumber);
} }
} }
if (Conf['Persistent QR'] || QR.cooldown.auto) { if (Conf['Persistent QR'] || QR.cooldown.auto) {
@ -1950,10 +1952,10 @@
} else { } else {
QR.close(); QR.close();
} }
if (Main.REPLY && (Conf['Unread Count'] || Conf['Unread Favicon'])) { if (g.REPLY && (Conf['Unread Count'] || Conf['Unread Favicon'])) {
Unread.foresee.push(postNumber); 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(); Updater.update();
} }
QR.status(); QR.status();
@ -2237,8 +2239,8 @@
} }
$.add($('#main_tab + div', dialog), ul); $.add($('#main_tab + div', dialog), ul);
} }
hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {});
hiddenNum = Object.keys(Main.hiddenReplies).length + Object.keys(hiddenThreads).length; hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length;
li = $.el('li', { li = $.el('li', {
innerHTML: "<button>hidden: " + hiddenNum + "</button> <span class=description>: Forget all hidden posts. Useful if you accidentally hide a post and have \"Show Stubs\" disabled." innerHTML: "<button>hidden: " + hiddenNum + "</button> <span class=description>: 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'); return d.body.style.removeProperty('overflow');
}, },
clearHidden: function() { clearHidden: function() {
$["delete"]("hiddenReplies/" + Main.BOARD + "/"); $["delete"]("hiddenReplies/" + g.BOARD + "/");
$["delete"]("hiddenThreads/" + Main.BOARD + "/"); $["delete"]("hiddenThreads/" + g.BOARD + "/");
this.textContent = "hidden: 0"; this.textContent = "hidden: 0";
return Main.hiddenReplies = {}; return g.hiddenReplies = {};
}, },
keybind: function(e) { keybind: function(e) {
var key; var key;
@ -2373,7 +2375,7 @@
thread: function(node) { thread: function(node) {
var div, nodes; var div, nodes;
node = Threading.op(node); node = Threading.op(node);
if (Main.REPLY) return; if (g.REPLY) return;
nodes = []; nodes = [];
while (node.nodeName !== 'HR') { while (node.nodeName !== 'HR') {
nodes.push(node); nodes.push(node);
@ -2394,7 +2396,7 @@
ThreadHiding = { ThreadHiding = {
init: function() { init: function() {
var a, hiddenThreads, op, thread, _i, _len, _ref; var a, hiddenThreads, op, thread, _i, _len, _ref;
hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {});
_ref = $$('.thread'); _ref = $$('.thread');
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
thread = _ref[_i]; thread = _ref[_i];
@ -2413,7 +2415,7 @@
}, },
toggle: function(thread) { toggle: function(thread) {
var hiddenThreads, id; var hiddenThreads, id;
hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {});
id = $('.op', thread).id; id = $('.op', thread).id;
if (thread.hidden || thread.firstChild.className === 'block') { if (thread.hidden || thread.firstChild.className === 'block') {
ThreadHiding.show(thread); ThreadHiding.show(thread);
@ -2422,7 +2424,7 @@
ThreadHiding.hide(thread); ThreadHiding.hide(thread);
hiddenThreads[id] = Date.now(); hiddenThreads[id] = Date.now();
} }
return $.set("hiddenThreads/" + Main.BOARD + "/", hiddenThreads); return $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads);
}, },
hide: function(thread) { hide: function(thread) {
var a, div, name, num, op, span, text, trip, uid, _ref, _ref2; var a, div, name, num, op, span, text, trip, uid, _ref, _ref2;
@ -2540,7 +2542,7 @@
Updater.count.textContent = 404; Updater.count.textContent = 404;
Updater.count.className = 'warning'; Updater.count.className = 'warning';
clearTimeout(Updater.timeoutID); clearTimeout(Updater.timeoutID);
Main.dead = true; g.dead = true;
if (Conf['Unread Count']) { if (Conf['Unread Count']) {
Unread.title = Unread.title.match(/^.+-/)[0] + ' 404'; Unread.title = Unread.title.match(/^.+-/)[0] + ' 404';
} else { } else {
@ -2637,8 +2639,8 @@
$.on(favicon, 'click', this.cb.toggle); $.on(favicon, 'click', this.cb.toggle);
$.before(input, favicon); $.before(input, favicon);
} }
if (Main.THREAD_ID === $.get('autoWatch', 0)) { if (g.THREAD_ID === $.get('autoWatch', 0)) {
this.watch(Main.THREAD_ID); this.watch(g.THREAD_ID);
$["delete"]('autoWatch'); $["delete"]('autoWatch');
} else { } else {
this.refresh(); this.refresh();
@ -2671,7 +2673,7 @@
$.rm(div); $.rm(div);
} }
$.add(Watcher.dialog, nodes); $.add(Watcher.dialog, nodes);
watchedBoard = watched[Main.BOARD] || {}; watchedBoard = watched[g.BOARD] || {};
_ref3 = $$('.favicon'); _ref3 = $$('.favicon');
for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
favicon = _ref3[_j]; favicon = _ref3[_j];
@ -2696,7 +2698,7 @@
toggle: function(thread) { toggle: function(thread) {
var id; var id;
id = $('.favicon + input', thread).name; 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) { unwatch: function(id, board) {
var watched; var watched;
@ -2710,9 +2712,9 @@
thread = $.id(id); thread = $.id(id);
if ($('.favicon', thread).src === Favicon["default"]) return false; if ($('.favicon', thread).src === Favicon["default"]) return false;
watched = $.get('watched', {}); watched = $.get('watched', {});
watched[_name = Main.BOARD] || (watched[_name] = {}); watched[_name = g.BOARD] || (watched[_name] = {});
watched[Main.BOARD][id] = { watched[g.BOARD][id] = {
href: "/" + Main.BOARD + "/res/" + id, href: "/" + g.BOARD + "/res/" + id,
textContent: GetTitle(thread) textContent: GetTitle(thread)
}; };
$.set('watched', watched); $.set('watched', watched);
@ -2740,7 +2742,7 @@
Sauce = { Sauce = {
init: function() { init: function() {
var link, _i, _len, _ref; var link, _i, _len, _ref;
if (Main.BOARD === 'f') return; if (g.BOARD === 'f') return;
this.links = []; this.links = [];
_ref = Conf['sauces'].split('\n'); _ref = Conf['sauces'].split('\n');
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -2763,7 +2765,7 @@
case '$3': case '$3':
return "' + img.firstChild.getAttribute('md5').replace(/\=*$/, '') + '"; return "' + img.firstChild.getAttribute('md5').replace(/\=*$/, '') + '";
case '$4': case '$4':
return Main.BOARD; return g.BOARD;
} }
}); });
href = Function('img', "return '" + href + "'"); href = Function('img', "return '" + href + "'");
@ -2914,7 +2916,7 @@
FileInfo = { FileInfo = {
init: function() { init: function() {
if (Main.BOARD === 'f') return; if (g.BOARD === 'f') return;
this.setFormats(); this.setFormats();
return Main.callbacks.push(this.node); return Main.callbacks.push(this.node);
}, },
@ -3024,7 +3026,7 @@
span = $.el('span', { span = $.el('span', {
innerHTML: el.innerHTML.replace(/<br>/g, ' ') innerHTML: el.innerHTML.replace(/<br>/g, ' ')
}); });
return "/" + Main.BOARD + "/ - " + span.textContent; return "/" + g.BOARD + "/ - " + span.textContent;
}; };
TitlePost = { TitlePost = {
@ -3178,7 +3180,7 @@
quote = _ref[_i]; quote = _ref[_i];
if ((href = quote.getAttribute('href')) === quote.hash) { if ((href = quote.getAttribute('href')) === quote.hash) {
quote.pathname = pathname; quote.pathname = pathname;
} else if (!Main.REPLY && href !== quote.href) { } else if (!g.REPLY && href !== quote.href) {
quote.href = "res/" + href; quote.href = "res/" + href;
} }
} }
@ -3305,7 +3307,7 @@
quote = _ref[_i]; quote = _ref[_i];
if (!quote.hash) continue; if (!quote.hash) continue;
path = quote.pathname.split('/'); 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)')); $.add(quote, $.tn('\u00A0(Cross-thread)'));
} }
} }
@ -3334,7 +3336,7 @@
nodes.push(a = $.el('a', { nodes.push(a = $.el('a', {
textContent: "" + quote + "\u00A0(Dead)" textContent: "" + quote + "\u00A0(Dead)"
})); }));
if (board === Main.BOARD && $.id(id)) { if (board === g.BOARD && $.id(id)) {
a.href = "#" + id; a.href = "#" + id;
a.className = 'quotelink'; a.className = 'quotelink';
a.setAttribute('onclick', "replyhl('" + id + "');"); a.setAttribute('onclick', "replyhl('" + id + "');");
@ -3370,7 +3372,7 @@
}, },
report: function() { report: function() {
var id, set, url; 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(); id = Date.now();
set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200"; set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200";
return window.open(url, id, set); return window.open(url, id, set);
@ -3385,7 +3387,7 @@
$.add(d.body, dialog); $.add(d.body, dialog);
this.posts = this.images = 0; this.posts = this.images = 0;
this.imgLimit = (function() { this.imgLimit = (function() {
switch (Main.BOARD) { switch (g.BOARD) {
case 'a': case 'a':
case 'mlp': case 'mlp':
case 'v': case 'v':
@ -3456,11 +3458,11 @@
}, },
update: function(forceUpdate) { update: function(forceUpdate) {
var count; var count;
if (!Main.REPLY) return; if (!g.REPLY) return;
count = this.replies.length; count = this.replies.length;
if (Conf['Unread Count']) this.setTitle(count); if (Conf['Unread Count']) this.setTitle(count);
if (!(Conf['Unread Favicon'] && (count < 2 || forceUpdate))) return; 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); return $.add(d.head, Favicon.el);
} }
}; };
@ -3506,7 +3508,7 @@
Redirect = { Redirect = {
init: function() { init: function() {
var url; 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; if (url) return location.href = url;
}, },
image: function(href) { image: function(href) {
@ -3523,11 +3525,11 @@
} }
}, },
thread: function(board, id, mode) { thread: function(board, id, mode) {
if (board == null) board = Main.BOARD; if (board == null) board = g.BOARD;
if (id == null) id = Main.THREAD_ID; if (id == null) id = g.THREAD_ID;
if (mode == null) mode = 'thread'; if (mode == null) mode = 'thread';
if (!(Conf['404 Redirect'] || mode === 'post')) return; if (!(Conf['404 Redirect'] || mode === 'post')) return;
switch (Main.BOARD) { switch (g.BOARD) {
case 'a': case 'a':
case 'jp': case 'jp':
case 'm': case 'm':
@ -3737,7 +3739,7 @@
ImageExpand.contract(thumb); ImageExpand.contract(thumb);
$.rm(this); $.rm(this);
if (!(this.src.split('/')[2] === 'images.4chan.org' && (url = Redirect.image(href)))) { if (!(this.src.split('/')[2] === 'images.4chan.org' && (url = Redirect.image(href)))) {
if (Main.dead) return; if (g.dead) return;
url = href + '?' + Date.now(); url = href + '?' + Date.now();
} }
timeoutID = setTimeout(ImageExpand.expand, 10000, thumb, url); timeoutID = setTimeout(ImageExpand.expand, 10000, thumb, url);
@ -3792,12 +3794,12 @@
})(null, Config); })(null, Config);
path = location.pathname; path = location.pathname;
pathname = path.slice(1).split('/'); pathname = path.slice(1).split('/');
Main.BOARD = pathname[0], temp = pathname[1]; g.BOARD = pathname[0], temp = pathname[1];
if (temp === 'res') { if (temp === 'res') {
Main.REPLY = true; g.REPLY = true;
Main.THREAD_ID = pathname[2]; g.THREAD_ID = pathname[2];
} else { } else {
Main.PAGENUM = parseInt(temp) || 0; g.PAGENUM = parseInt(temp) || 0;
} }
for (key in Conf) { for (key in Conf) {
val = Conf[key]; val = Conf[key];
@ -3837,7 +3839,7 @@
return; return;
} }
$.ready(Options.init); $.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.css += 'form[name=post] { display: none; }';
} }
Main.addStyle(); Main.addStyle();
@ -3850,22 +3852,22 @@
}); });
$.set('lastUpdate', now); $.set('lastUpdate', now);
} }
Main.hiddenReplies = $.get("hiddenReplies/" + Main.BOARD + "/", {}); g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {});
if ($.get('lastChecked', 0) < now - 1 * $.DAY) { if ($.get('lastChecked', 0) < now - 1 * $.DAY) {
$.set('lastChecked', now); $.set('lastChecked', now);
cutoff = now - 7 * $.DAY; cutoff = now - 7 * $.DAY;
hiddenThreads = $.get("hiddenThreads/" + Main.BOARD + "/", {}); hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {});
for (id in hiddenThreads) { for (id in hiddenThreads) {
timestamp = hiddenThreads[id]; timestamp = hiddenThreads[id];
if (timestamp < cutoff) delete hiddenThreads[id]; if (timestamp < cutoff) delete hiddenThreads[id];
} }
_ref = Main.hiddenReplies; _ref = g.hiddenReplies;
for (id in _ref) { for (id in _ref) {
timestamp = _ref[id]; timestamp = _ref[id];
if (timestamp < cutoff) delete Main.hiddenReplies[id]; if (timestamp < cutoff) delete g.hiddenReplies[id];
} }
$.set("hiddenThreads/" + Main.BOARD + "/", hiddenThreads); $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads);
$.set("hiddenReplies/" + Main.BOARD + "/", Main.hiddenReplies); $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies);
} }
if (Conf['Filter']) Filter.init(); if (Conf['Filter']) Filter.init();
if (Conf['Reply Hiding']) ReplyHiding.init(); if (Conf['Reply Hiding']) ReplyHiding.init();
@ -3898,7 +3900,7 @@
_ref = ['navtop', 'navbot']; _ref = ['navtop', 'navbot'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
nav = _ref[_i]; nav = _ref[_i];
$.addClass($("a[href$='/" + Main.BOARD + "/']", $.id(nav)), 'current'); $.addClass($("a[href$='/" + g.BOARD + "/']", $.id(nav)), 'current');
} }
form = $('form[name=delform]'); form = $('form[name=delform]');
Threading.thread(form.firstElementChild); Threading.thread(form.firstElementChild);
@ -3915,7 +3917,7 @@
return Keybinds.init(); return Keybinds.init();
}); });
} }
if (Main.REPLY) { if (g.REPLY) {
if (Conf['Thread Updater']) { if (Conf['Thread Updater']) {
setTimeout(function() { setTimeout(function() {
return Updater.init(); return Updater.init();
@ -3996,7 +3998,7 @@
el: klass === 'op' ? node : node.firstChild.firstChild.lastChild, el: klass === 'op' ? node : node.firstChild.firstChild.lastChild,
"class": klass, "class": klass,
id: node.getElementsByTagName('input')[0].name, 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', isOP: klass === 'op',
isInlined: /\binline\b/.test(klass), isInlined: /\binline\b/.test(klass),
filesize: node.getElementsByClassName('filesize')[0] || false, filesize: node.getElementsByClassName('filesize')[0] || false,

View File

@ -155,6 +155,7 @@ Config =
'Interval': 30 'Interval': 30
d = document d = document
g = {}
UI = UI =
dialog: (id, position, html) -> dialog: (id, position, html) ->
@ -454,7 +455,7 @@ Filter =
# and it's not specifically applicable to the current board. # and it's not specifically applicable to the current board.
# Defaults to global. # Defaults to global.
boards = filter.match(/boards:([^;]+)/)?[1].toLowerCase() or '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 continue
try try
@ -523,7 +524,7 @@ Filter =
# Hide # Hide
if result is true if result is true
if isOP if isOP
unless Main.REPLY unless g.REPLY
ThreadHiding.hide post.el.parentNode ThreadHiding.hide post.el.parentNode
else else
continue continue
@ -536,7 +537,7 @@ Filter =
$.addClass el, result[0] $.addClass el, result[0]
else else
$.addClass el.parentNode, result[0] $.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... # Put the highlighted OPs' threads on top of the board pages...
thisThread = el.parentNode thisThread = el.parentNode
# ...before the first non highlighted thread. # ...before the first non highlighted thread.
@ -632,7 +633,7 @@ ExpandComment =
quotes = node.getElementsByClassName 'quotelink' quotes = node.getElementsByClassName 'quotelink'
for quote in quotes for quote in quotes
if quote.hash is quote.getAttribute 'href' if quote.hash is quote.getAttribute 'href'
quote.pathname = "/#{Main.BOARD}/res/#{threadID}" quote.pathname = "/#{g.BOARD}/res/#{threadID}"
post = post =
el: node el: node
threadId: threadID threadId: threadID
@ -667,7 +668,7 @@ ExpandThread =
toggle: (thread) -> toggle: (thread) ->
threadID = thread.firstChild.id threadID = thread.firstChild.id
pathname = "/#{Main.BOARD}/res/#{threadID}" pathname = "/#{g.BOARD}/res/#{threadID}"
a = $ '.omittedposts', thread a = $ '.omittedposts', thread
# \u00d7 is &times; # \u00d7 is &times;
@ -685,7 +686,7 @@ ExpandThread =
when '-' when '-'
a.textContent = a.textContent.replace '-', '+' a.textContent = a.textContent.replace '-', '+'
#goddamit moot #goddamit moot
num = switch Main.BOARD num = switch g.BOARD
when 'b', 'vg' then 3 when 'b', 'vg' then 3
when 't' then 1 when 't' then 1
else 5 else 5
@ -738,7 +739,7 @@ ReplyHiding =
$.on td.firstChild, 'click', ReplyHiding.toggle $.on td.firstChild, 'click', ReplyHiding.toggle
$.replace post.el.previousSibling, td $.replace post.el.previousSibling, td
if post.id of Main.hiddenReplies if post.id of g.hiddenReplies
ReplyHiding.hide post.root ReplyHiding.hide post.root
toggle: -> toggle: ->
@ -748,7 +749,7 @@ ReplyHiding =
id = parent.nextSibling.id id = parent.nextSibling.id
for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']" for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']"
$.addClass quote, 'filtered' $.addClass quote, 'filtered'
Main.hiddenReplies[id] = Date.now() g.hiddenReplies[id] = Date.now()
else else
table = parent.nextSibling table = parent.nextSibling
table.hidden = false table.hidden = false
@ -756,8 +757,8 @@ ReplyHiding =
id = table.firstChild.firstChild.lastChild.id id = table.firstChild.firstChild.lastChild.id
for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']" for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']"
$.removeClass quote, 'filtered' $.removeClass quote, 'filtered'
delete Main.hiddenReplies[id] delete g.hiddenReplies[id]
$.set "hiddenReplies/#{Main.BOARD}/", Main.hiddenReplies $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies
hide: (table) -> hide: (table) ->
return if table.hidden # already hidden by filter return if table.hidden # already hidden by filter
@ -833,17 +834,17 @@ Keybinds =
Keybinds.img thread, true Keybinds.img thread, true
# Board Navigation # Board Navigation
when Conf.zero when Conf.zero
window.location = "/#{Main.BOARD}/0#0" window.location = "/#{g.BOARD}/0#0"
when Conf.nextPage when Conf.nextPage
$('input[value=Next]')?.click() $('input[value=Next]')?.click()
when Conf.previousPage when Conf.previousPage
$('input[value=Previous]')?.click() $('input[value=Previous]')?.click()
# Thread Navigation # Thread Navigation
when Conf.nextThread when Conf.nextThread
return if Main.REPLY return if g.REPLY
Nav.scroll +1 Nav.scroll +1
when Conf.previousThread when Conf.previousThread
return if Main.REPLY return if g.REPLY
Nav.scroll -1 Nav.scroll -1
when Conf.expandThread when Conf.expandThread
ExpandThread.toggle thread ExpandThread.toggle thread
@ -902,7 +903,7 @@ Keybinds =
open: (thread, tab) -> open: (thread, tab) ->
id = thread.firstChild.id id = thread.firstChild.id
url = "//boards.4chan.org/#{Main.BOARD}/res/#{id}" url = "//boards.4chan.org/#{g.BOARD}/res/#{id}"
if tab if tab
$.open url $.open url
else else
@ -924,7 +925,7 @@ Keybinds =
td.tabIndex = 0 td.tabIndex = 0
td.focus() td.focus()
return 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() rect = next.getBoundingClientRect()
if rect.top < 0 or rect.bottom > d.body.clientHeight if rect.top < 0 or rect.bottom > d.body.clientHeight
next.scrollIntoView delta is -1 next.scrollIntoView delta is -1
@ -962,13 +963,13 @@ Nav =
$.add d.body, span $.add d.body, span
prev: -> prev: ->
if Main.REPLY if g.REPLY
window.scrollTo 0, 0 window.scrollTo 0, 0
else else
Nav.scroll -1 Nav.scroll -1
next: -> next: ->
if Main.REPLY if g.REPLY
window.scrollTo 0, d.body.scrollHeight window.scrollTo 0, d.body.scrollHeight
else else
Nav.scroll +1 Nav.scroll +1
@ -1005,10 +1006,10 @@ QR =
asyncInit: -> asyncInit: ->
if Conf['Hide Original Post Form'] if Conf['Hide Original Post Form']
link = $.el 'h1', innerHTML: "<a href=javascript:;>#{if Main.REPLY then 'Quick Reply' else 'New Thread'}</a>" link = $.el 'h1', innerHTML: "<a href=javascript:;>#{if g.REPLY then 'Quick Reply' else 'New Thread'}</a>"
$.on $('a', link), 'click', -> $.on $('a', link), 'click', ->
QR.open() QR.open()
$('select', QR.el).value = 'new' unless Main.REPLY $('select', QR.el).value = 'new' unless g.REPLY
$('textarea', QR.el).focus() $('textarea', QR.el).focus()
form = d.forms[0] form = d.forms[0]
$.before form, link $.before form, link
@ -1093,7 +1094,7 @@ QR =
else unless QR.status.ready else unless QR.status.ready
value = 'Loading' value = 'Loading'
disabled = true disabled = true
if Main.dead if g.dead
value = 404 value = 404
disabled = true disabled = true
QR.cooldown.auto = false QR.cooldown.auto = false
@ -1115,28 +1116,28 @@ QR =
cooldown: cooldown:
init: -> init: ->
return unless Conf['Cooldown'] return unless Conf['Cooldown']
QR.cooldown.start $.get "/#{Main.BOARD}/cooldown", 0 QR.cooldown.start $.get "/#{g.BOARD}/cooldown", 0
$.sync "/#{Main.BOARD}/cooldown", QR.cooldown.start $.sync "/#{g.BOARD}/cooldown", QR.cooldown.start
start: (timeout) -> start: (timeout) ->
seconds = Math.floor (timeout - Date.now()) / 1000 seconds = Math.floor (timeout - Date.now()) / 1000
QR.cooldown.count seconds QR.cooldown.count seconds
set: (seconds) -> set: (seconds) ->
return unless Conf['Cooldown'] return unless Conf['Cooldown']
QR.cooldown.count seconds QR.cooldown.count seconds
$.set "/#{Main.BOARD}/cooldown", Date.now() + seconds*$.SECOND $.set "/#{g.BOARD}/cooldown", Date.now() + seconds*$.SECOND
count: (seconds) -> count: (seconds) ->
return unless 0 <= seconds <= 60 return unless 0 <= seconds <= 60
setTimeout QR.cooldown.count, 1000, seconds-1 setTimeout QR.cooldown.count, 1000, seconds-1
QR.cooldown.seconds = seconds QR.cooldown.seconds = seconds
if seconds is 0 if seconds is 0
$.delete "/#{Main.BOARD}/cooldown" $.delete "/#{g.BOARD}/cooldown"
QR.submit() if QR.cooldown.auto QR.submit() if QR.cooldown.auto
QR.status() QR.status()
quote: (e) -> quote: (e) ->
e?.preventDefault() e?.preventDefault()
QR.open() QR.open()
unless Main.REPLY unless g.REPLY
$('select', QR.el).value = $.x('ancestor::div[@class="thread"]', @).firstChild.id $('select', QR.el).value = $.x('ancestor::div[@class="thread"]', @).firstChild.id
# Make sure we get the correct number, even with XXX censors # Make sure we get the correct number, even with XXX censors
@ -1446,7 +1447,7 @@ QR =
spoiler = $ '#spoilerLabel', QR.el spoiler = $ '#spoilerLabel', QR.el
spoiler.hidden = !QR.spoiler spoiler.hidden = !QR.spoiler
unless Main.REPLY unless g.REPLY
# Make a list with visible threads and an option to create a new one. # Make a list with visible threads and an option to create a new one.
threads = '<option value=new>New thread</option>' threads = '<option value=new>New thread</option>'
for thread in $$ '.op' for thread in $$ '.op'
@ -1536,7 +1537,7 @@ QR =
return return
QR.cleanError() 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. # Enable auto-posting if we have stuff to post, disable it otherwise.
QR.cooldown.auto = QR.replies.length > 1 QR.cooldown.auto = QR.replies.length > 1
@ -1625,22 +1626,22 @@ QR =
if Conf['Thread Watcher'] and Conf['Auto Watch'] if Conf['Thread Watcher'] and Conf['Auto Watch']
$.set 'autoWatch', postNumber $.set 'autoWatch', postNumber
# auto-noko # auto-noko
location.pathname = "/#{Main.BOARD}/res/#{postNumber}" location.pathname = "/#{g.BOARD}/res/#{postNumber}"
else else
# Enable auto-posting if we have stuff to post, disable it otherwise. # Enable auto-posting if we have stuff to post, disable it otherwise.
QR.cooldown.auto = QR.replies.length > 1 QR.cooldown.auto = QR.replies.length > 1
QR.cooldown.set if /sage/i.test reply.email then 60 else 30 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 if Conf['Open Reply in New Tab'] && !g.REPLY && !QR.cooldown.auto
$.open "//boards.4chan.org/#{Main.BOARD}/res/#{thread}##{postNumber}" $.open "//boards.4chan.org/#{g.BOARD}/res/#{thread}##{postNumber}"
if Conf['Persistent QR'] or QR.cooldown.auto if Conf['Persistent QR'] or QR.cooldown.auto
reply.rm() reply.rm()
else else
QR.close() 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 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() Updater.update()
QR.status() QR.status()
@ -1887,8 +1888,8 @@ Options =
$.add ul, li $.add ul, li
$.add $('#main_tab + div', dialog), ul $.add $('#main_tab + div', dialog), ul
hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {}
hiddenNum = Object.keys(Main.hiddenReplies).length + Object.keys(hiddenThreads).length hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length
li = $.el 'li', li = $.el 'li',
innerHTML: "<button>hidden: #{hiddenNum}</button> <span class=description>: Forget all hidden posts. Useful if you accidentally hide a post and have \"Show Stubs\" disabled." innerHTML: "<button>hidden: #{hiddenNum}</button> <span class=description>: Forget all hidden posts. Useful if you accidentally hide a post and have \"Show Stubs\" disabled."
$.on $('button', li), 'click', Options.clearHidden $.on $('button', li), 'click', Options.clearHidden
@ -1955,10 +1956,10 @@ Options =
clearHidden: -> clearHidden: ->
#'hidden' might be misleading; it's the number of IDs we're *looking* for, #'hidden' might be misleading; it's the number of IDs we're *looking* for,
# not the number of posts actually hidden on the page. # not the number of posts actually hidden on the page.
$.delete "hiddenReplies/#{Main.BOARD}/" $.delete "hiddenReplies/#{g.BOARD}/"
$.delete "hiddenThreads/#{Main.BOARD}/" $.delete "hiddenThreads/#{g.BOARD}/"
@textContent = "hidden: 0" @textContent = "hidden: 0"
Main.hiddenReplies = {} g.hiddenReplies = {}
keybind: (e) -> keybind: (e) ->
return if e.keyCode is 9 return if e.keyCode is 9
e.preventDefault() e.preventDefault()
@ -2006,7 +2007,7 @@ Threading =
thread: (node) -> thread: (node) ->
node = Threading.op node node = Threading.op node
return if Main.REPLY return if g.REPLY
nodes = [] nodes = []
until node.nodeName is 'HR' until node.nodeName is 'HR'
@ -2024,7 +2025,7 @@ Threading =
ThreadHiding = ThreadHiding =
init: -> init: ->
hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {}
for thread in $$ '.thread' for thread in $$ '.thread'
op = thread.firstChild op = thread.firstChild
a = $.el 'a', a = $.el 'a',
@ -2041,7 +2042,7 @@ ThreadHiding =
ThreadHiding.toggle @parentNode.parentNode ThreadHiding.toggle @parentNode.parentNode
toggle: (thread) -> toggle: (thread) ->
hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {}
id = $('.op', thread).id id = $('.op', thread).id
if thread.hidden or thread.firstChild.className is 'block' if thread.hidden or thread.firstChild.className is 'block'
ThreadHiding.show thread ThreadHiding.show thread
@ -2049,7 +2050,7 @@ ThreadHiding =
else else
ThreadHiding.hide thread ThreadHiding.hide thread
hiddenThreads[id] = Date.now() hiddenThreads[id] = Date.now()
$.set "hiddenThreads/#{Main.BOARD}/", hiddenThreads $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads
hide: (thread) -> hide: (thread) ->
unless Conf['Show Stubs'] unless Conf['Show Stubs']
@ -2158,7 +2159,7 @@ Updater =
Updater.count.textContent = 404 Updater.count.textContent = 404
Updater.count.className = 'warning' Updater.count.className = 'warning'
clearTimeout Updater.timeoutID clearTimeout Updater.timeoutID
Main.dead = true g.dead = true
if Conf['Unread Count'] if Conf['Unread Count']
Unread.title = Unread.title.match(/^.+-/)[0] + ' 404' Unread.title = Unread.title.match(/^.+-/)[0] + ' 404'
else else
@ -2243,8 +2244,8 @@ Watcher =
$.on favicon, 'click', @cb.toggle $.on favicon, 'click', @cb.toggle
$.before input, favicon $.before input, favicon
if Main.THREAD_ID is $.get 'autoWatch', 0 if g.THREAD_ID is $.get 'autoWatch', 0
@watch Main.THREAD_ID @watch g.THREAD_ID
$.delete 'autoWatch' $.delete 'autoWatch'
else else
#populate watcher, display watch buttons #populate watcher, display watch buttons
@ -2273,7 +2274,7 @@ Watcher =
$.rm div $.rm div
$.add Watcher.dialog, nodes $.add Watcher.dialog, nodes
watchedBoard = watched[Main.BOARD] or {} watchedBoard = watched[g.BOARD] or {}
for favicon in $$ '.favicon' for favicon in $$ '.favicon'
id = favicon.nextSibling.name id = favicon.nextSibling.name
if id of watchedBoard if id of watchedBoard
@ -2291,7 +2292,7 @@ Watcher =
toggle: (thread) -> toggle: (thread) ->
id = $('.favicon + input', thread).name 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) -> unwatch: (id, board) ->
watched = $.get 'watched', {} watched = $.get 'watched', {}
@ -2304,9 +2305,9 @@ Watcher =
return false if $('.favicon', thread).src is Favicon.default return false if $('.favicon', thread).src is Favicon.default
watched = $.get 'watched', {} watched = $.get 'watched', {}
watched[Main.BOARD] or= {} watched[g.BOARD] or= {}
watched[Main.BOARD][id] = watched[g.BOARD][id] =
href: "/#{Main.BOARD}/res/#{id}" href: "/#{g.BOARD}/res/#{id}"
textContent: GetTitle thread textContent: GetTitle thread
$.set 'watched', watched $.set 'watched', watched
Watcher.refresh() Watcher.refresh()
@ -2325,7 +2326,7 @@ Anonymize =
Sauce = Sauce =
init: -> init: ->
return if Main.BOARD is 'f' return if g.BOARD is 'f'
@links = [] @links = []
for link in Conf['sauces'].split '\n' for link in Conf['sauces'].split '\n'
continue if link[0] is '#' continue if link[0] is '#'
@ -2344,7 +2345,7 @@ Sauce =
when '$3' when '$3'
"' + img.firstChild.getAttribute('md5').replace(/\=*$/, '') + '" "' + img.firstChild.getAttribute('md5').replace(/\=*$/, '') + '"
when '$4' when '$4'
Main.BOARD g.BOARD
href = Function 'img', "return '#{href}'" href = Function 'img', "return '#{href}'"
el = $.el 'a', el = $.el 'a',
target: '_blank' target: '_blank'
@ -2454,7 +2455,7 @@ Time =
FileInfo = FileInfo =
init: -> init: ->
return if Main.BOARD is 'f' return if g.BOARD is 'f'
@setFormats() @setFormats()
Main.callbacks.push @node Main.callbacks.push @node
node: (post) -> node: (post) ->
@ -2528,7 +2529,7 @@ GetTitle = (thread) ->
if not el.textContent if not el.textContent
el = $ '.postername', thread el = $ '.postername', thread
span = $.el 'span', innerHTML: el.innerHTML.replace /<br>/g, ' ' span = $.el 'span', innerHTML: el.innerHTML.replace /<br>/g, ' '
"/#{Main.BOARD}/ - #{span.textContent}" "/#{g.BOARD}/ - #{span.textContent}"
TitlePost = TitlePost =
init: -> init: ->
@ -2649,7 +2650,7 @@ QuoteInline =
for quote in $$ '.quotelink', newInline for quote in $$ '.quotelink', newInline
if (href = quote.getAttribute 'href') is quote.hash #add pathname to normal quotes if (href = quote.getAttribute 'href') is quote.hash #add pathname to normal quotes
quote.pathname = pathname 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}" quote.href = "res/#{href}"
link = $ '.quotejs', newInline link = $ '.quotejs', newInline
link.href = "#{pathname}##{id}" link.href = "#{pathname}##{id}"
@ -2751,7 +2752,7 @@ QuoteCT =
continue continue
path = quote.pathname.split '/' path = quote.pathname.split '/'
# If quote leads to a different thread id and is located on the same board. # 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 # \u00A0 is nbsp
$.add quote, $.tn '\u00A0(Cross-thread)' $.add quote, $.tn '\u00A0(Cross-thread)'
return return
@ -2794,7 +2795,7 @@ Quotify =
# \u00A0 is nbsp # \u00A0 is nbsp
textContent: "#{quote}\u00A0(Dead)" textContent: "#{quote}\u00A0(Dead)"
if board is Main.BOARD and $.id id if board is g.BOARD and $.id id
a.href = "##{id}" a.href = "##{id}"
a.className = 'quotelink' a.className = 'quotelink'
a.setAttribute 'onclick', "replyhl('#{id}');" a.setAttribute 'onclick', "replyhl('#{id}');"
@ -2825,7 +2826,7 @@ ReportButton =
$.after $('span[id]', post.el), [$.tn(' '), a] $.after $('span[id]', post.el), [$.tn(' '), a]
$.on a, 'click', ReportButton.report $.on a, 'click', ReportButton.report
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() id = Date.now()
set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200" set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200"
window.open url, id, set window.open url, id, set
@ -2837,7 +2838,7 @@ ThreadStats =
$.add d.body, dialog $.add d.body, dialog
@posts = @images = 0 @posts = @images = 0
@imgLimit = @imgLimit =
switch Main.BOARD switch g.BOARD
when 'a', 'mlp', 'v' when 'a', 'mlp', 'v'
251 251
when 'vg' when 'vg'
@ -2894,7 +2895,7 @@ Unread =
), 5 ), 5
update: (forceUpdate) -> update: (forceUpdate) ->
return unless Main.REPLY return unless g.REPLY
count = @replies.length count = @replies.length
@ -2905,7 +2906,7 @@ Unread =
return return
Favicon.el.href = Favicon.el.href =
if Main.dead if g.dead
if count if count
Favicon.unreadDead Favicon.unreadDead
else else
@ -2958,19 +2959,19 @@ Redirect =
url = url =
if location.hostname is 'images.4chan.org' if location.hostname is 'images.4chan.org'
@image location.href @image location.href
else if /^\d+$/.test Main.THREAD_ID else if /^\d+$/.test g.THREAD_ID
@thread() @thread()
location.href = url if url location.href = url if url
image: (href) -> image: (href) ->
href = href.split '/' 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'] return unless Conf['404 Redirect']
switch href[3] switch href[3]
when 'a', 'jp', 'm', 'tg', 'u', 'vg' when 'a', 'jp', 'm', 'tg', 'u', 'vg'
"http://archive.foolz.us/#{href[3]}/full_image/#{href[5]}" "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' return unless Conf['404 Redirect'] or mode is 'post'
switch Main.BOARD switch g.BOARD
when 'a', 'jp', 'm', 'tg', 'tv', 'u', 'v', 'vg' when 'a', 'jp', 'm', 'tg', 'tv', 'u', 'v', 'vg'
"http://archive.foolz.us/#{board}/thread/#{id}/" "http://archive.foolz.us/#{board}/thread/#{id}/"
when 'lit' when 'lit'
@ -3108,7 +3109,7 @@ ImageExpand =
ImageExpand.contract thumb ImageExpand.contract thumb
$.rm @ $.rm @
unless @src.split('/')[2] is 'images.4chan.org' and url = Redirect.image href 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. # CloudFlare may cache banned pages instead of images.
# This will fool CloudFlare's cache. # This will fool CloudFlare's cache.
url = href + '?' + Date.now() url = href + '?' + Date.now()
@ -3156,12 +3157,12 @@ Main =
path = location.pathname path = location.pathname
pathname = path[1..].split '/' pathname = path[1..].split '/'
[Main.BOARD, temp] = pathname [g.BOARD, temp] = pathname
if temp is 'res' if temp is 'res'
Main.REPLY = true g.REPLY = true
Main.THREAD_ID = pathname[2] g.THREAD_ID = pathname[2]
else else
Main.PAGENUM = parseInt(temp) or 0 g.PAGENUM = parseInt(temp) or 0
#load values from localStorage #load values from localStorage
for key, val of Conf for key, val of Conf
@ -3188,7 +3189,7 @@ Main =
$.ready Options.init $.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.css += 'form[name=post] { display: none; }'
Main.addStyle() Main.addStyle()
@ -3198,23 +3199,23 @@ Main =
$.ready -> $.add d.head, $.el 'script', src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js' $.ready -> $.add d.head, $.el 'script', src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js'
$.set 'lastUpdate', now $.set 'lastUpdate', now
Main.hiddenReplies = $.get "hiddenReplies/#{Main.BOARD}/", {} g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {}
if $.get('lastChecked', 0) < now - 1*$.DAY if $.get('lastChecked', 0) < now - 1*$.DAY
$.set 'lastChecked', now $.set 'lastChecked', now
cutoff = now - 7*$.DAY cutoff = now - 7*$.DAY
hiddenThreads = $.get "hiddenThreads/#{Main.BOARD}/", {} hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {}
for id, timestamp of hiddenThreads for id, timestamp of hiddenThreads
if timestamp < cutoff if timestamp < cutoff
delete hiddenThreads[id] delete hiddenThreads[id]
for id, timestamp of Main.hiddenReplies for id, timestamp of g.hiddenReplies
if timestamp < cutoff if timestamp < cutoff
delete Main.hiddenReplies[id] delete g.hiddenReplies[id]
$.set "hiddenThreads/#{Main.BOARD}/", hiddenThreads $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads
$.set "hiddenReplies/#{Main.BOARD}/", Main.hiddenReplies $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies
#major features #major features
@ -3280,7 +3281,7 @@ Main =
$.addClass d.body, "chanx_#{Main.version.split('.')[1]}" $.addClass d.body, "chanx_#{Main.version.split('.')[1]}"
$.addClass d.body, $.engine $.addClass d.body, $.engine
for nav in ['navtop', 'navbot'] 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]' form = $ 'form[name=delform]'
Threading.thread form.firstElementChild Threading.thread form.firstElementChild
Favicon.init() Favicon.init()
@ -3298,7 +3299,7 @@ Main =
if Conf['Keybinds'] if Conf['Keybinds']
setTimeout -> Keybinds.init() setTimeout -> Keybinds.init()
if Main.REPLY if g.REPLY
if Conf['Thread Updater'] if Conf['Thread Updater']
setTimeout -> Updater.init() setTimeout -> Updater.init()
@ -3363,7 +3364,7 @@ Main =
el: if klass is 'op' then node else node.firstChild.firstChild.lastChild el: if klass is 'op' then node else node.firstChild.firstChild.lastChild
class: klass class: klass
id: node.getElementsByTagName('input')[0].name 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' isOP: klass is 'op'
isInlined: /\binline\b/.test klass isInlined: /\binline\b/.test klass
filesize: node.getElementsByClassName('filesize')[0] or false filesize: node.getElementsByClassName('filesize')[0] or false