From 3c359bf5607fe1e874f184e7390db0c1ac6de6f1 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 14 Jan 2013 02:52:47 +0100 Subject: [PATCH] Some sort of catalog support. --- 4chan_x.user.js | 31 ++++++++++++++++++++++--------- lib/$.coffee | 3 ++- src/features.coffee | 6 +++--- src/main.coffee | 16 ++++++++++++---- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index f4a79690a..8e44b8ae0 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -20,7 +20,7 @@ // @icon https://github.com/MayhemYDG/4chan-x/raw/stable/img/icon.gif // ==/UserScript== -/* 4chan X Alpha - Version 3.0.0 - 2013-01-13 +/* 4chan X Alpha - Version 3.0.0 - 2013-01-14 * http://mayhemydg.github.com/4chan-x/ * * Copyright (c) 2009-2011 James Campos @@ -398,8 +398,9 @@ return $.on(d, 'DOMContentLoaded', cb); }, sync: function(key, cb) { + key = "" + g.NAMESPACE + key; return $.on(window, 'storage', function(e) { - if (e.key === ("" + g.NAMESPACE + key)) { + if (e.key === key) { return cb(JSON.parse(e.newValue)); } }); @@ -964,7 +965,7 @@ container = $.el('div', { id: "pc" + postID, className: "postContainer " + (isOP ? 'op' : 'reply') + "Container", - innerHTML: (isOP ? '' : "
>>
") + ("
") + ("' + (isOP ? fileHTML : '') + ("' + (isOP ? '' : fileHTML) + ("
" + (comment || '') + "
") + '
' + innerHTML: (isOP ? '' : "
>>
") + ("
") + ("' + (isOP ? fileHTML : '') + ("' + (isOP ? '' : fileHTML) + ("
" + (comment || '') + "
") + '
' }); _ref = $$('.quotelink', container); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -1988,7 +1989,7 @@ ThreadUpdater = { init: function() { - if (!g.REPLY) { + if (g.VIEW !== 'thread') { return; } return Thread.prototype.callbacks.push({ @@ -2622,21 +2623,33 @@ } pathname = location.pathname.split('/'); g.BOARD = new Board(pathname[1]); - if (g.REPLY = pathname[2] === 'res') { + g.VIEW = (function() { + switch (pathname[2]) { + case 'res': + return 'thread'; + case 'catalog': + return 'catalog'; + default: + return 'index'; + } + })(); + if (g.VIEW === 'thread') { g.THREAD = +pathname[3]; } switch (location.hostname) { case 'boards.4chan.org': Main.initHeader(); + if (g.VIEW === 'catalog') { + return; + } return Main.initFeatures(); case 'sys.4chan.org': break; case 'images.4chan.org': $.ready(function() { - var path, url; + var url; if (Conf['404 Redirect'] && d.title === '4chan - 404 Not Found') { - path = location.pathname.split('/'); - url = Redirect.image(path[1], path[3]); + url = Redirect.image(pathname[1], pathname[3]); if (url) { return location.href = url; } @@ -2821,7 +2834,7 @@ initFeaturesReady: function() { var boardChild, posts, thread, threadChild, threads, _i, _j, _len, _len1, _ref, _ref1; if (d.title === '4chan - 404 Not Found') { - if (Conf['404 Redirect'] && g.REPLY) { + if (Conf['404 Redirect'] && g.VIEW === 'thread') { location.href = Redirect.to({ board: g.BOARD, threadID: g.THREAD, diff --git a/lib/$.coffee b/lib/$.coffee index f1d9231ee..fb4b6ee08 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -30,8 +30,9 @@ $.extend $, fc() $.on d, 'DOMContentLoaded', cb sync: (key, cb) -> + key = "#{g.NAMESPACE}#{key}" $.on window, 'storage', (e) -> - if e.key is "#{g.NAMESPACE}#{key}" + if e.key is key cb JSON.parse e.newValue formData: (form) -> if form instanceof HTMLFormElement diff --git a/src/features.coffee b/src/features.coffee index 9b6f62e43..f8e728062 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -302,7 +302,7 @@ Build = '
' + "No." + "No." + " - return unless g.REPLY + return if g.VIEW isnt 'thread' Thread::callbacks.push name: 'Thread Updater' cb: @node diff --git a/src/main.coffee b/src/main.coffee index 9682e5b96..62a07ad70 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -283,20 +283,28 @@ Main = pathname = location.pathname.split '/' g.BOARD = new Board pathname[1] - if g.REPLY = pathname[2] is 'res' + g.VIEW = + switch pathname[2] + when 'res' + 'thread' + when 'catalog' + 'catalog' + else + 'index' + if g.VIEW is 'thread' g.THREAD = +pathname[3] switch location.hostname when 'boards.4chan.org' Main.initHeader() + return if g.VIEW is 'catalog' Main.initFeatures() when 'sys.4chan.org' return when 'images.4chan.org' $.ready -> if Conf['404 Redirect'] and d.title is '4chan - 404 Not Found' - path = location.pathname.split '/' - url = Redirect.image path[1], path[3] + url = Redirect.image pathname[1], pathname[3] location.href = url if url return @@ -473,7 +481,7 @@ Main = $.ready Main.initFeaturesReady initFeaturesReady: -> if d.title is '4chan - 404 Not Found' - if Conf['404 Redirect'] and g.REPLY + if Conf['404 Redirect'] and g.VIEW is 'thread' location.href = Redirect.to board: g.BOARD threadID: g.THREAD