From 606875c29206a60dda64ac5a74a60f6b5ac3cee6 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 6 Sep 2012 01:13:09 +0200 Subject: [PATCH] Tweak. --- 4chan_x.user.js | 43 +++++++++++++++++++++++-------------------- script.coffee | 38 +++++++++++++++++++------------------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index fd433bc94..7ab665616 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -909,7 +909,7 @@ }, initHeaderReady: function() { var header, nav, settings, _ref, _ref1, _ref2; - if (!$.id('navtopr')) { + if (!$.id('navtopright')) { return; } header = Main.header; @@ -981,7 +981,7 @@ } return; } - if (!$.id('navtopr')) { + if (!$.id('navtopright')) { return; } threads = []; @@ -1371,7 +1371,11 @@ return root; }, fetchedPost: function(req, board, threadID, postID, root) { - var clone, doc, href, inBoard, inThread, link, pc, post, quote, status, url, _i, _len, _ref; + var doc, href, inBoard, inThread, link, pc, post, quote, status, url, _i, _len, _ref; + if (post = g.posts["" + board + "." + postID]) { + Get.insert(post, root); + return; + } status = req.status; if (status !== 200) { if (url = Redirect.post(board, postID)) { @@ -1412,19 +1416,16 @@ link.nextSibling.href = "/" + board + "/res/" + threadID + "#q" + postID; inBoard = g.boards[board] || new Board(board); inThread = g.threads["" + board + "." + threadID] || new Thread(threadID, inBoard); - if (!(post = g.posts["" + board + "." + postID])) { - post = new Post(postContainer, thread, board); - Main.callbackNodes(Post, [post]); - } - if (!root.parentNode) { - return; - } - clone = post.addClone(); - Main.callbackNodes(Post, [clone]); - return $.replace(root.firstChild, Get.cleanRoot(clone)); + post = new Post(postContainer, thread, board); + Main.callbackNodes(Post, [post]); + return Get.insert(post, root); }, archivedPost: function(req, board, postID, root) { - var bq, clone, comment, data, post, postContainer, thread, threadID; + var bq, comment, data, post, postContainer, thread, threadID; + if (post = g.posts["" + board + "." + postID]) { + Get.insert(post, root); + return; + } data = JSON.parse(req.response); if (data.error) { $.addClass(root, 'warning'); @@ -1492,12 +1493,14 @@ }); board = g.boards[board] || new Board(board); thread = g.threads["" + board + "." + threadID] || new Thread(threadID, board); - if (!(post = g.posts["" + board + "." + postID])) { - post = new Post(postContainer, thread, board, { - isArchived: true - }); - Main.callbackNodes(Post, [post]); - } + post = new Post(postContainer, thread, board, { + isArchived: true + }); + Main.callbackNodes(Post, [post]); + return Get.insert(post, root); + }, + insert: function(post, root) { + var clone; if (!root.parentNode) { return; } diff --git a/script.coffee b/script.coffee index 1265e782f..5a4c7b335 100644 --- a/script.coffee +++ b/script.coffee @@ -714,7 +714,7 @@ Main = localStorage.setItem '4chan_settings', false $.ready Main.initHeaderReady initHeaderReady: -> - return unless $.id 'navtopr' + return unless $.id 'navtopright' header = Main.header $.prepend d.body, header @@ -780,7 +780,7 @@ Main = location.href = Redirect.thread g.BOARD, g.THREAD, location.hash return - return unless $.id 'navtopr' + return unless $.id 'navtopright' threads = [] posts = [] @@ -1160,6 +1160,11 @@ Get = $.rm child unless child is post root fetchedPost: (req, board, threadID, postID, root) -> + # In case of multiple callbacks for the same request, + # don't parse the same original post more than once. + if post = g.posts["#{board}.#{postID}"] + Get.insert post, root + return {status} = req if status isnt 200 # The thread can die by the time we check a quote. @@ -1201,18 +1206,15 @@ Get = new Board board inThread = g.threads["#{board}.#{threadID}"] or new Thread threadID, inBoard + post = new Post postContainer, thread, board + Main.callbackNodes Post, [post] + Get.insert post, root + archivedPost: (req, board, postID, root) -> # In case of multiple callbacks for the same request, # don't parse the same original post more than once. - unless post = g.posts["#{board}.#{postID}"] - post = new Post postContainer, thread, board - Main.callbackNodes Post, [post] - - # Stop here if the container has been removed while loading. - return unless root.parentNode - clone = post.addClone() - Main.callbackNodes Post, [clone] - $.replace root.firstChild, Get.cleanRoot clone - archivedPost: (req, board, postID, root) -> + if post = g.posts["#{board}.#{postID}"] + Get.insert post, root + return data = JSON.parse req.response if data.error $.addClass root, 'warning' @@ -1293,13 +1295,11 @@ Get = new Board board thread = g.threads["#{board}.#{threadID}"] or new Thread threadID, board - # In case of multiple callbacks for the same request, - # don't parse the same original post more than once. - unless post = g.posts["#{board}.#{postID}"] - post = new Post postContainer, thread, board, - isArchived: true - Main.callbackNodes Post, [post] - + post = new Post postContainer, thread, board, + isArchived: true + Main.callbackNodes Post, [post] + Get.insert post, root + insert: (post, root) -> # Stop here if the container has been removed while loading. return unless root.parentNode clone = post.addClone()