From cc04f1b9e9d5bb33d7dd9d6f238f028942f73406 Mon Sep 17 00:00:00 2001 From: James Campos Date: Tue, 15 Jan 2013 23:27:21 -0800 Subject: [PATCH 1/4] post.hasPdf --- 4chan_x.user.js | 12 +++++++----- script.coffee | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 992e74ebc..fb5803d1d 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -4630,7 +4630,7 @@ return; } $.id('postcount').textContent = ++ThreadStats.posts; - if (!post.img) { + if (!post.img || post.hasPdf) { return; } imgcount = $.id('imagecount'); @@ -4920,7 +4920,7 @@ return Main.callbacks.push(this.node); }, node: function(post) { - if (!post.img) { + if (!post.img || post.hasPdf) { return; } return $.on(post.img, 'mouseover', ImageHover.mouseover); @@ -5025,7 +5025,7 @@ }, node: function(post) { var a; - if (!post.img) { + if (!post.img || post.hasPdf) { return; } a = post.img.parentNode; @@ -5544,7 +5544,7 @@ } }, preParse: function(node) { - var el, img, parentClass, post; + var el, img, imgParent, parentClass, post; parentClass = node.parentNode.className; el = $('.post', node); post = { @@ -5563,8 +5563,10 @@ img: false }; if (img = $('img[data-md5]', el)) { - post.fileInfo = img.parentNode.previousElementSibling; + imgParent = img.parentNode; post.img = img; + post.fileInfo = imgParent.previousElementSibling; + post.hasPdf = /\.pdf$/.test(imgParent.href); } Main.prettify(post.blockquote); return post; diff --git a/script.coffee b/script.coffee index a0a18901b..8f8021a83 100644 --- a/script.coffee +++ b/script.coffee @@ -3796,7 +3796,7 @@ ThreadStats = node: (post) -> return if post.isInlined $.id('postcount').textContent = ++ThreadStats.posts - return unless post.img + return if (!post.img or post.hasPdf) imgcount = $.id 'imagecount' imgcount.textContent = ++ThreadStats.images if ThreadStats.images > ThreadStats.imgLimit @@ -4012,7 +4012,7 @@ ImageHover = init: -> Main.callbacks.push @node node: (post) -> - return unless post.img + return if (!post.img or post.hasPdf) $.on post.img, 'mouseover', ImageHover.mouseover mouseover: -> # Make sure to remove the previous image hover @@ -4078,7 +4078,7 @@ ImageExpand = @dialog() node: (post) -> - return unless post.img + return if (!post.img or post.hasPdf) a = post.img.parentNode $.on a, 'click', ImageExpand.cb.toggle if ImageExpand.on and !post.el.hidden @@ -4506,8 +4506,10 @@ Main = if img = $ 'img[data-md5]', el # Make sure to not add deleted images, # those do not have a data-md5 attribute. - post.fileInfo = img.parentNode.previousElementSibling + imgParent = img.parentNode post.img = img + post.fileInfo = imgParent.previousElementSibling + post.hasPdf = /\.pdf$/.test imgParent.href Main.prettify post.blockquote post node: (nodes, notify) -> From 92adcaf28a1ce746d126eaed24d01c7847f6ebba Mon Sep 17 00:00:00 2001 From: James Campos Date: Tue, 15 Jan 2013 23:28:56 -0800 Subject: [PATCH 2/4] ImageExpand.expand: return if pdf --- 4chan_x.user.js | 10 +++++++--- script.coffee | 9 +++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index fb5803d1d..9a665b310 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -5127,20 +5127,24 @@ thumb.nextSibling.hidden = true; return $.rmClass(thumb.parentNode.parentNode.parentNode, 'image_expanded'); }, - expand: function(thumb, url) { + expand: function(thumb, src) { var a, img; if ($.x('ancestor-or-self::*[@hidden]', thumb)) { return; } + a = thumb.parentNode; + src || (src = a.href); + if (/\.pdf$/.test(src)) { + return; + } thumb.hidden = true; $.addClass(thumb.parentNode.parentNode.parentNode, 'image_expanded'); if (img = thumb.nextSibling) { img.hidden = false; return; } - a = thumb.parentNode; img = $.el('img', { - src: url || a.href + src: src }); $.on(img, 'error', ImageExpand.error); return $.add(a, img); diff --git a/script.coffee b/script.coffee index 8f8021a83..7d8759332 100644 --- a/script.coffee +++ b/script.coffee @@ -4144,18 +4144,19 @@ ImageExpand = thumb.nextSibling.hidden = true $.rmClass thumb.parentNode.parentNode.parentNode, 'image_expanded' - expand: (thumb, url) -> + expand: (thumb, src) -> # Do not expand images of hidden/filtered replies, or already expanded pictures. return if $.x 'ancestor-or-self::*[@hidden]', thumb + a = thumb.parentNode + src or= a.href + return if /\.pdf$/.test src thumb.hidden = true $.addClass thumb.parentNode.parentNode.parentNode, 'image_expanded' if img = thumb.nextSibling # Expand already loaded picture img.hidden = false return - a = thumb.parentNode - img = $.el 'img', - src: url or a.href + img = $.el 'img', { src } $.on img, 'error', ImageExpand.error $.add a, img From 1b81a791051ca552af958a87dde2b30007aaa7db Mon Sep 17 00:00:00 2001 From: James Campos Date: Wed, 16 Jan 2013 02:31:48 -0800 Subject: [PATCH 3/4] tweak --- 4chan_x.user.js | 2 +- script.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 9a665b310..66b391c1b 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -4630,7 +4630,7 @@ return; } $.id('postcount').textContent = ++ThreadStats.posts; - if (!post.img || post.hasPdf) { + if (!post.img) { return; } imgcount = $.id('imagecount'); diff --git a/script.coffee b/script.coffee index 7d8759332..1f41b1973 100644 --- a/script.coffee +++ b/script.coffee @@ -3796,7 +3796,7 @@ ThreadStats = node: (post) -> return if post.isInlined $.id('postcount').textContent = ++ThreadStats.posts - return if (!post.img or post.hasPdf) + return unless post.img imgcount = $.id 'imagecount' imgcount.textContent = ++ThreadStats.images if ThreadStats.images > ThreadStats.imgLimit From ac6dd4368202b8d3d13a1cad92c62bec14554590 Mon Sep 17 00:00:00 2001 From: James Campos Date: Wed, 16 Jan 2013 02:33:04 -0800 Subject: [PATCH 4/4] changelog --- changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog b/changelog index ba12ffb8f..db000d913 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,6 @@ master +- James Campos + Don't expand pdfs - Mayhem Add /po/ archive redirection for threads, images and post resurrection.