diff --git a/4chan_x.user.js b/4chan_x.user.js index 2669e119e..c4b9986dc 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -227,7 +227,6 @@ left = left < 10 ? '0px' : UI.width - left < 10 ? null : left + 'px'; top = top < 10 ? '0px' : UI.height - top < 10 ? null : top + 'px'; style = UI.el.style; - $.log(left, top); style.left = left; style.top = top; style.right = left === null ? '0px' : null; @@ -619,7 +618,7 @@ if (post.isInlined) { return; } - isOP = /\bop\b/.test(post["class"]); + isOP = post.id === post.threadId; root = post.root; for (key in Filter.filters) { value = Filter[key](post); @@ -907,8 +906,8 @@ } quote.href = "res/" + href; } - id = reply.firstElementChild.id.slice(2); - link = $('.postNum.desktop', reply).firstElementChild; + id = reply.id.slice(2); + link = $('.postInfo > .postNum > a:first-child', reply); link.href = "res/" + threadID + "#p" + id; link.nextSibling.href = "res/" + threadID + "#q" + id; nodes.push(reply); @@ -2453,7 +2452,7 @@ dialog = UI.dialog('updater', 'bottom: 0; right: 0;', html); this.count = $('#count', dialog); this.timer = $('#timer', dialog); - this.thread = $('.thread'); + this.thread = $.id("t" + g.THREAD_ID); _ref = $$('input', dialog); for (_i = 0, _len = _ref.length; _i < _len; _i++) { input = _ref[_i]; @@ -2712,7 +2711,7 @@ }, node: function(post) { var name, node; - if (post["class"] === 'inline') { + if (post.isInlined && !post.isCrosspost) { return; } name = $('.name', post.el); @@ -2773,7 +2772,7 @@ node: function(post) { var img, link, nodes, _i, _len, _ref; img = post.img; - if (post["class"] === 'inline' || !img) { + if (post.isInlined && !post.isCrosspost || !img) { return; } img = img.parentNode; @@ -2794,7 +2793,7 @@ node: function(post) { var img; img = post.img; - if (!(img && /^Spoiler/.test(img.alt)) || post["class"] === 'inline') { + if (!(img && /^Spoiler/.test(img.alt)) || post.isInlined && !post.isCrosspost) { return; } img.removeAttribute('style'); @@ -2824,7 +2823,7 @@ }, node: function(post) { var node; - if (post["class"] === 'inline') { + if (post.isInlined && !post.isCrosspost) { return; } node = $('.postInfo > .dateTime', post.el); @@ -2919,7 +2918,7 @@ }, node: function(post) { var data, link, node, regexp, resolution, size, span, unit, _, _ref; - if (post["class"] === 'inline' || !(node = post.filesize)) { + if (post.isInlined && !post.isCrosspost || !(node = post.filesize)) { return; } regexp = /^File: (<.+>)-\((?:Spoiler Image, )?([\d\.]+) (\w+), (\d+x\d+|PDF)/; @@ -3207,7 +3206,7 @@ link = $('.postInfo > .postNum > a:first-child', newInline); link.href = "" + pathname + "#p" + id; link.nextSibling.href = "" + pathname + "#q" + id; - $.addClass(newInline, 'crossquote'); + $.addClass(newInline, 'crosspost'); return $.replace(inline, newInline); }, clone: function(id, el) { @@ -3324,7 +3323,7 @@ }, node: function(post) { var quote, _i, _len, _ref; - if (post["class"] === 'inline') { + if (post.isInlined && !post.isCrosspost) { return; } _ref = post.quotes; @@ -3343,7 +3342,7 @@ }, node: function(post) { var path, quote, _i, _len, _ref; - if (post["class"] === 'inline') { + if (post.isInlined && !post.isCrosspost) { return; } _ref = post.quotes; @@ -3366,7 +3365,7 @@ }, node: function(post) { var a, board, data, i, id, index, m, node, nodes, quote, quotes, snapshot, text, _i, _j, _len, _ref; - if (post["class"] === 'inline') { + if (post.isInlined && !post.isCrosspost) { return; } snapshot = d.evaluate('.//text()[not(parent::a)]', post.el.lastElementChild, null, 6, null); @@ -3384,7 +3383,7 @@ nodes.push($.tn(text)); } id = quote.match(/\d+$/)[0]; - board = (m = quote.match(/^>>>\/([a-z\d]+)/)) ? m[1] : $('.postNum.desktop', post.el).firstElementChild.pathname.split('/')[1]; + board = (m = quote.match(/^>>>\/([a-z\d]+)/)) ? m[1] : $('.postInfo > .postNum > a:first-child', post.el).pathname.split('/')[1]; nodes.push(a = $.el('a', { textContent: "" + quote + "\u00A0(Dead)" })); @@ -3487,7 +3486,7 @@ return; } el = post.el; - if (el.hidden) { + if (el.hidden || /\bop\b/.test(post["class"]) || post.isInlined) { return; } count = Unread.replies.push(el); @@ -3743,7 +3742,7 @@ } a = post.img.parentNode; $.on(a, 'click', ImageExpand.cb.toggle); - if (ImageExpand.on && !post.el.hidden && post["class"] !== 'inline') { + if (ImageExpand.on && !post.el.hidden) { return ImageExpand.expand(post.img); } }, @@ -4147,6 +4146,7 @@ id: el.id.slice(1), threadId: g.THREAD_ID || $.x('ancestor::div[@class="thread"]', node).id.slice(1), isInlined: /\binline\b/.test(klass), + isCrosspost: /\bcrosspost\b/.test(klass), quotes: el.getElementsByClassName('quotelink'), backlinks: el.getElementsByClassName('backlink'), fileInfo: false, diff --git a/script.coffee b/script.coffee index 301c296ca..fa2003243 100644 --- a/script.coffee +++ b/script.coffee @@ -194,7 +194,6 @@ UI = #using null instead of '' is 4% faster #these 4 statements are 40% faster than 1 style.cssText {style} = UI.el - $.log left, top style.left = left style.top = top style.right = if left is null then '0px' else null @@ -510,7 +509,7 @@ Filter = node: (post) -> return if post.isInlined - isOP = /\bop\b/.test post.class + isOP = post.id is post.threadId {root} = post for key of Filter.filters value = Filter[key] post @@ -706,8 +705,8 @@ ExpandThread = href = quote.getAttribute 'href' continue if href[0] is '/' # Cross-board quote quote.href = "res/#{href}" # Fix pathnames - id = reply.firstElementChild.id[2..] - link = $('.postNum.desktop', reply).firstElementChild + id = reply.id[2..] + link = $ '.postInfo > .postNum > a:first-child', reply link.href = "res/#{threadID}#p#{id}" link.nextSibling.href = "res/#{threadID}#q#{id}" nodes.push reply @@ -1945,7 +1944,7 @@ Updater = @count = $ '#count', dialog @timer = $ '#timer', dialog - @thread = $ '.thread' + @thread = $.id "t#{g.THREAD_ID}" for input in $$ 'input', dialog if input.type is 'checkbox' @@ -2156,7 +2155,7 @@ Anonymize = init: -> Main.callbacks.push @node node: (post) -> - return if post.class is 'inline' + return if post.isInlined and not post.isCrosspost name = $ '.name', post.el name.textContent = 'Anonymous' if node = name.nextElementSibling @@ -2195,7 +2194,7 @@ Sauce = node: (post) -> {img} = post - return if post.class is 'inline' or not img + return if post.isInlined and not post.isCrosspost or not img img = img.parentNode nodes = [] for link in Sauce.links @@ -2208,10 +2207,10 @@ RevealSpoilers = Main.callbacks.push @node node: (post) -> {img} = post - if not (img and /^Spoiler/.test img.alt) or post.class is 'inline' + if not (img and /^Spoiler/.test img.alt) or post.isInlined and not post.isCrosspost return img.removeAttribute 'style' - img.src = "//thumbs.4chan.org#{img.parentNode.pathname.replace(/src(\/\d+).+$/, 'thumb$1s.jpg')}" + img.src = "//thumbs.4chan.org#{img.parentNode.pathname.replace /src(\/\d+).+$/, 'thumb$1s.jpg'}" Time = init: -> @@ -2236,7 +2235,7 @@ Time = Main.callbacks.push @node node: (post) -> - return if post.class is 'inline' + return if post.isInlined and not post.isCrosspost node = $ '.postInfo > .dateTime', post.el Time.date = Time.parse node.textContent node.textContent = Time.funk(Time) @@ -2296,7 +2295,7 @@ FileInfo = @setFormats() Main.callbacks.push @node node: (post) -> - return if post.class is 'inline' or not node = post.filesize + return if post.isInlined and not post.isCrosspost or not node = post.filesize regexp = /^File: (<.+>)-\((?:Spoiler Image, )?([\d\.]+) (\w+), (\d+x\d+|PDF)/ [_, link, size, unit, resolution] = node.innerHTML.match regexp @@ -2482,7 +2481,7 @@ QuoteInline = link = $ '.postInfo > .postNum > a:first-child', newInline link.href = "#{pathname}#p#{id}" link.nextSibling.href = "#{pathname}#q#{id}" - $.addClass newInline, 'crossquote' + $.addClass newInline, 'crosspost' $.replace inline, newInline clone: (id, el) -> @@ -2558,7 +2557,7 @@ QuoteOP = init: -> Main.callbacks.push @node node: (post) -> - return if post.class is 'inline' + return if post.isInlined and not post.isCrosspost for quote in post.quotes if quote.hash[2..] is post.threadId # \u00A0 is nbsp @@ -2569,7 +2568,7 @@ QuoteCT = init: -> Main.callbacks.push @node node: (post) -> - return if post.class is 'inline' + return if post.isInlined and not post.isCrosspost for quote in post.quotes unless quote.hash # Make sure this isn't a link to the board we're on. @@ -2585,7 +2584,7 @@ Quotify = init: -> Main.callbacks.push @node node: (post) -> - return if post.class is 'inline' + return if post.isInlined and not post.isCrosspost # XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE is 6 # Get all the text nodes that are not inside an anchor. @@ -2613,7 +2612,7 @@ Quotify = m[1] else # Get the post's board, whether it's inlined or not. - $('.postNum.desktop', post.el).firstElementChild.pathname.split('/')[1] + $('.postInfo > .postNum > a:first-child', post.el).pathname.split('/')[1] nodes.push a = $.el 'a', # \u00A0 is nbsp @@ -2695,7 +2694,7 @@ Unread = return {el} = post # new HTML ??? - return if el.hidden # or inlined/OP + return if el.hidden or /\bop\b/.test(post.class) or post.isInlined count = Unread.replies.push el Unread.update count is 1 @@ -2867,7 +2866,7 @@ ImageExpand = return unless post.img a = post.img.parentNode $.on a, 'click', ImageExpand.cb.toggle - if ImageExpand.on and !post.el.hidden and post.class isnt 'inline' + if ImageExpand.on and !post.el.hidden ImageExpand.expand post.img cb: toggle: (e) -> @@ -3180,16 +3179,17 @@ Main = el = $ '.post', node klass = el.className post = - root: node - el: el - class: klass - id: el.id[1..] - threadId: g.THREAD_ID or $.x('ancestor::div[@class="thread"]', node).id[1..] - isInlined: /\binline\b/.test klass - quotes: el.getElementsByClassName 'quotelink' - backlinks: el.getElementsByClassName 'backlink' - fileInfo: false - img: false + root: node + el: el + class: klass + id: el.id[1..] + threadId: g.THREAD_ID or $.x('ancestor::div[@class="thread"]', node).id[1..] + isInlined: /\binline\b/.test klass + isCrosspost: /\bcrosspost\b/.test klass + quotes: el.getElementsByClassName 'quotelink' + backlinks: el.getElementsByClassName 'backlink' + fileInfo: false + img: false if fileInfo = $ '.fileInfo', el img = fileInfo.nextElementSibling.firstElementChild if img.alt isnt 'File deleted.'