From 42377c69cdb48e30d9c1863a6b237fdf046ec2f6 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 11 Mar 2012 06:03:59 +0100 Subject: [PATCH] Don't add a class to hidden threads with stubs. This will slightly improve performance for thread id perparsing on board pages. --- 4chan_x.user.js | 12 +++++------- script.coffee | 10 ++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 35c8c83f4..24061e539 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2438,7 +2438,7 @@ var hiddenThreads, id; hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); id = $('.op', thread).id; - if (thread.hidden || /\bstub\b/.test(thread.className)) { + if (thread.hidden || thread.firstChild.className === 'block') { ThreadHiding.show(thread); delete hiddenThreads[id]; } else { @@ -2454,7 +2454,7 @@ thread.nextSibling.hidden = true; return; } - if (/\bstub\b/.test(thread.className)) return; + if (thread.firstChild.className === 'block') return; num = 0; if (span = $('.omittedposts', thread)) { num = Number(span.textContent.match(/\d+/)[0]); @@ -2474,12 +2474,10 @@ className: 'block' }); $.add(div, a); - $.prepend(thread, div); - return $.addClass(thread, 'stub'); + return $.prepend(thread, div); }, show: function(thread, id) { $.rm($('.block', thread)); - $.removeClass(thread, 'stub'); thread.hidden = false; return thread.nextSibling.hidden = false; } @@ -3279,7 +3277,7 @@ }, parse: function(req, id, threadID) { var doc, node, post, qp; - if (!((qp = ui.el) && qp.innerHTML === ("Loading " + id + "..."))) return; + if (!((qp = ui.el) && qp.textContent === ("Loading " + id + "..."))) return; if (req.status !== 200) { qp.textContent = "" + req.status + " " + req.statusText; return; @@ -3958,7 +3956,7 @@ el: klass === 'op' ? node : node.firstChild.firstChild.lastChild, "class": klass, id: node.getElementsByTagName('input')[0].name, - threadId: g.THREAD_ID || $.x('ancestor::div[contains(@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 1208092db..208ff1263 100644 --- a/script.coffee +++ b/script.coffee @@ -2051,7 +2051,7 @@ ThreadHiding = toggle: (thread) -> hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} id = $('.op', thread).id - if thread.hidden or /\bstub\b/.test thread.className + if thread.hidden or thread.firstChild.className is 'block' ThreadHiding.show thread delete hiddenThreads[id] else @@ -2065,7 +2065,7 @@ ThreadHiding = thread.nextSibling.hidden = true return - return if /\bstub\b/.test thread.className # already hidden by filter + return if thread.firstChild.className is 'block' # already hidden by filter num = 0 if span = $ '.omittedposts', thread @@ -2087,11 +2087,9 @@ ThreadHiding = $.add div, a $.prepend thread, div - $.addClass thread, 'stub' show: (thread, id) -> $.rm $ '.block', thread - $.removeClass thread, 'stub' thread.hidden = false thread.nextSibling.hidden = false @@ -2712,7 +2710,7 @@ QuotePreview = $.off @, 'mouseout', QuotePreview.mouseout $.off @, 'click', QuotePreview.mouseout parse: (req, id, threadID) -> - return unless (qp = ui.el) and qp.innerHTML is "Loading #{id}..." + return unless (qp = ui.el) and qp.textContent is "Loading #{id}..." if req.status isnt 200 qp.textContent = "#{req.status} #{req.statusText}" @@ -3297,7 +3295,7 @@ Main = el: if klass is 'op' then node else node.firstChild.firstChild.lastChild class: klass id: node.getElementsByTagName('input')[0].name - threadId: g.THREAD_ID or $.x('ancestor::div[contains(@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