Final fix for Show Stubs, Reply Hiding and Filtering. These should be independant.

This commit is contained in:
Nicolas Stepien 2012-05-01 18:18:41 +02:00
parent 359d508c30
commit 6ffa33bd67
2 changed files with 73 additions and 58 deletions

View File

@ -617,12 +617,12 @@
}; };
}, },
node: function(post) { node: function(post) {
var el, filter, firstThread, isOP, key, result, thisThread, value, _i, _len, _ref; var filter, firstThread, isOP, key, result, root, thisThread, value, _i, _len, _ref;
if (post.isInlined) { if (post.isInlined) {
return; return;
} }
isOP = /\bop\b/.test(post["class"]); isOP = /\bop\b/.test(post["class"]);
el = post.el; root = post.root;
for (key in Filter.filters) { for (key in Filter.filters) {
value = Filter[key](post); value = Filter[key](post);
if (value === false) { if (value === false) {
@ -637,18 +637,18 @@
if (result === true) { if (result === true) {
if (isOP) { if (isOP) {
if (!g.REPLY) { if (!g.REPLY) {
ThreadHiding.hide(post.root.parentNode); ThreadHiding.hide(root.parentNode);
} else { } else {
continue; continue;
} }
} else { } else {
ReplyHiding.hide(post.root); ReplyHiding.hide(root);
} }
return; return;
} }
$.addClass((isOP ? post.root.parentNode : post.root), result[0]); $.addClass((isOP ? root.parentNode : root), result[0]);
if (isOP && result[1] && !g.REPLY) { if (isOP && result[1] && !g.REPLY) {
thisThread = el.parentNode.parentNode; thisThread = root.parentNode;
if (firstThread = $('div[class=thread]')) { if (firstThread = $('div[class=thread]')) {
$.before(firstThread.parentNode, [thisThread, thisThread.nextElementSibling]); $.before(firstThread.parentNode, [thisThread, thisThread.nextElementSibling]);
} }
@ -748,7 +748,7 @@
if ((el = $.id(quote.hash.slice(1))) && el.hidden) { if ((el = $.id(quote.hash.slice(1))) && el.hidden) {
$.addClass(quote, 'filtered'); $.addClass(quote, 'filtered');
if (Conf['Recursive Filtering']) { if (Conf['Recursive Filtering']) {
ReplyHiding.hide(post.root.firstElementChild); ReplyHiding.hide(post.root);
} }
} }
} }
@ -929,28 +929,29 @@
if (post.isInlined || /\bop\b/.test(post["class"])) { if (post.isInlined || /\bop\b/.test(post["class"])) {
return; return;
} }
button = post.el.previousElementSibling; button = post.root.firstElementChild;
$.addClass(button, 'hide_reply_button'); $.addClass(button, 'hide_reply_button');
button.innerHTML = '<a href="javascript:;"><span>[ - ]</span></a>'; button.innerHTML = '<a href="javascript:;"><span>[ - ]</span></a>';
$.on(button.firstChild, 'click', ReplyHiding.toggle); $.on(button.firstChild, 'click', ReplyHiding.toggle);
if (post.id in g.hiddenReplies) { if (post.id in g.hiddenReplies) {
return ReplyHiding.hide(post.root.firstElementChild); return ReplyHiding.hide(post.root);
} }
}, },
toggle: function() { toggle: function() {
var button, id, quote, quotes, _i, _j, _len, _len1; var button, id, quote, quotes, root, _i, _j, _len, _len1;
button = this.parentNode; button = this.parentNode;
id = button.id.slice(2); root = button.parentNode;
id = root.id.slice(2);
quotes = $$(".quotelink[href$='#p" + id + "'], .backlink[href='#p" + id + "']"); quotes = $$(".quotelink[href$='#p" + id + "'], .backlink[href='#p" + id + "']");
if (button.nextElementSibling.hidden) { if (/\bstub\b/.test(button.className)) {
ReplyHiding.show(button); ReplyHiding.show(root);
for (_i = 0, _len = quotes.length; _i < _len; _i++) { for (_i = 0, _len = quotes.length; _i < _len; _i++) {
quote = quotes[_i]; quote = quotes[_i];
$.removeClass(quote, 'filtered'); $.removeClass(quote, 'filtered');
} }
delete g.hiddenReplies[id]; delete g.hiddenReplies[id];
} else { } else {
ReplyHiding.hide(button); ReplyHiding.hide(root);
for (_j = 0, _len1 = quotes.length; _j < _len1; _j++) { for (_j = 0, _len1 = quotes.length; _j < _len1; _j++) {
quote = quotes[_j]; quote = quotes[_j];
$.addClass(quote, 'filtered'); $.addClass(quote, 'filtered');
@ -959,27 +960,36 @@
} }
return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies);
}, },
hide: function(button) { hide: function(root) {
if (button.nextElementSibling.hidden) { var button, el, stub;
button = root.firstElementChild;
if (button.hidden) {
return; return;
} }
button.nextElementSibling.hidden = true; button.hidden = true;
$.addClass(button, 'hidden_reply'); el = root.lastElementChild;
el.hidden = true;
if (!Conf['Show Stubs']) { if (!Conf['Show Stubs']) {
button.hidden = true;
return; return;
} }
button.firstChild.firstChild.textContent = '[ + ]'; stub = $.el('div', {
return $.add(button.firstChild, $.tn(" " + ($('.nameBlock', button.nextElementSibling).textContent))); className: 'hide_reply_button stub',
innerHTML: '<a href="javascript:;"><span>[ + ]</span> </a>'
});
$.add(stub.firstChild, $.tn($('.nameBlock', el).textContent));
$.on(stub.firstChild, 'click', ReplyHiding.toggle);
return $.after(button, stub);
}, },
show: function(button) { show: function(root) {
button.nextElementSibling.hidden = false; var button, el;
$.removeClass(button, 'hidden_reply'); el = root.lastElementChild;
button = root.firstElementChild;
el.hidden = false;
button.hidden = false;
if (!Conf['Show Stubs']) { if (!Conf['Show Stubs']) {
button.hidden = false;
return; return;
} }
return button.firstChild.innerHTML = '<span>[ - ]</span>'; return $.rm(button.nextElementSibling);
} }
}; };
@ -2783,7 +2793,7 @@
node: function(post) { node: function(post) {
var img; var img;
img = post.img; img = post.img;
if (!(img && /\bimgspoiler\b/.test(img.parentNode.className)) || post["class"] === 'inline') { if (!(img && /^Spoiler/.test(img.alt)) || post["class"] === 'inline') {
return; return;
} }
img.removeAttribute('style'); img.removeAttribute('style');
@ -4120,7 +4130,7 @@
}, },
preParse: function(node) { preParse: function(node) {
var el, fileInfo, img, klass, post; var el, fileInfo, img, klass, post;
el = $('.post', node); el = node.lastElementChild;
klass = el.className; klass = el.className;
post = { post = {
root: node, root: node,

View File

@ -514,7 +514,7 @@ Filter =
node: (post) -> node: (post) ->
return if post.isInlined return if post.isInlined
isOP = /\bop\b/.test post.class isOP = /\bop\b/.test post.class
{el} = post {root} = post
for key of Filter.filters for key of Filter.filters
value = Filter[key] post value = Filter[key] post
if value is false if value is false
@ -528,18 +528,18 @@ Filter =
if result is true if result is true
if isOP if isOP
unless g.REPLY unless g.REPLY
ThreadHiding.hide post.root.parentNode ThreadHiding.hide root.parentNode
else else
continue continue
else else
ReplyHiding.hide post.root ReplyHiding.hide root
return return
# Highlight # Highlight
$.addClass (if isOP then post.root.parentNode else post.root), result[0] $.addClass (if isOP then root.parentNode else root), result[0]
if isOP and result[1] and not g.REPLY if isOP and result[1] and not g.REPLY
# Put the highlighted OPs' threads on top of the board pages... # Put the highlighted OPs' threads on top of the board pages...
thisThread = el.parentNode.parentNode thisThread = root.parentNode
# ...before the first non highlighted thread. # ...before the first non highlighted thread.
if firstThread = $ 'div[class=thread]' if firstThread = $ 'div[class=thread]'
$.before firstThread.parentNode, [thisThread, thisThread.nextElementSibling] $.before firstThread.parentNode, [thisThread, thisThread.nextElementSibling]
@ -601,7 +601,7 @@ StrikethroughQuotes =
for quote in post.quotes for quote in post.quotes
if (el = $.id quote.hash[1..]) and el.hidden if (el = $.id quote.hash[1..]) and el.hidden
$.addClass quote, 'filtered' $.addClass quote, 'filtered'
ReplyHiding.hide post.root.firstElementChild if Conf['Recursive Filtering'] ReplyHiding.hide post.root if Conf['Recursive Filtering']
return return
ExpandComment = ExpandComment =
@ -725,51 +725,56 @@ ReplyHiding =
node: (post) -> node: (post) ->
return if post.isInlined or /\bop\b/.test post.class return if post.isInlined or /\bop\b/.test post.class
button = post.el.previousElementSibling button = post.root.firstElementChild
$.addClass button, 'hide_reply_button' $.addClass button, 'hide_reply_button'
button.innerHTML = '<a href="javascript:;"><span>[ - ]</span></a>' button.innerHTML = '<a href="javascript:;"><span>[ - ]</span></a>'
$.on button.firstChild, 'click', ReplyHiding.toggle $.on button.firstChild, 'click', ReplyHiding.toggle
if post.id of g.hiddenReplies if post.id of g.hiddenReplies
ReplyHiding.hide post.root.firstElementChild ReplyHiding.hide post.root
toggle: -> toggle: ->
button = @parentNode button = @parentNode
id = button.id[2..] root = button.parentNode
id = root.id[2..]
quotes = $$ ".quotelink[href$='#p#{id}'], .backlink[href='#p#{id}']" quotes = $$ ".quotelink[href$='#p#{id}'], .backlink[href='#p#{id}']"
if button.nextElementSibling.hidden if /\bstub\b/.test button.className
ReplyHiding.show button ReplyHiding.show root
for quote in quotes for quote in quotes
$.removeClass quote, 'filtered' $.removeClass quote, 'filtered'
delete g.hiddenReplies[id] delete g.hiddenReplies[id]
else else
ReplyHiding.hide button ReplyHiding.hide root
for quote in quotes for quote in quotes
$.addClass quote, 'filtered' $.addClass quote, 'filtered'
g.hiddenReplies[id] = Date.now() g.hiddenReplies[id] = Date.now()
$.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies
hide: (button) -> hide: (root) ->
return if button.nextElementSibling.hidden # already hidden once by filter button = root.firstElementChild
button.nextElementSibling.hidden = true return if button.hidden # already hidden once by filter
$.addClass button, 'hidden_reply' button.hidden = true
el = root.lastElementChild
el.hidden = true
unless Conf['Show Stubs'] return unless Conf['Show Stubs']
button.hidden = true
return
button.firstChild.firstChild.textContent = '[ + ]' stub = $.el 'div',
$.add button.firstChild, $.tn " #{$('.nameBlock', button.nextElementSibling).textContent}" className: 'hide_reply_button stub'
innerHTML: '<a href="javascript:;"><span>[ + ]</span> </a>'
$.add stub.firstChild, $.tn $('.nameBlock', el).textContent
$.on stub.firstChild, 'click', ReplyHiding.toggle
$.after button, stub
show: (button) -> show: (root) ->
button.nextElementSibling.hidden = false el = root.lastElementChild
$.removeClass button, 'hidden_reply' button = root.firstElementChild
el.hidden = false
button.hidden = false
unless Conf['Show Stubs'] return unless Conf['Show Stubs']
button.hidden = false
return
button.firstChild.innerHTML = '<span>[ - ]</span>' $.rm button.nextElementSibling
Keybinds = Keybinds =
init: -> init: ->
@ -2203,7 +2208,7 @@ RevealSpoilers =
Main.callbacks.push @node Main.callbacks.push @node
node: (post) -> node: (post) ->
{img} = post {img} = post
if not (img and /\bimgspoiler\b/.test img.parentNode.className) or post.class is 'inline' if not (img and /^Spoiler/.test img.alt) or post.class is 'inline'
return return
img.removeAttribute 'style' 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')}"
@ -3166,7 +3171,7 @@ Main =
window.location = "https://raw.github.com/mayhemydg/4chan-x/#{version}/4chan_x.user.js" window.location = "https://raw.github.com/mayhemydg/4chan-x/#{version}/4chan_x.user.js"
preParse: (node) -> preParse: (node) ->
el = $ '.post', node el = node.lastElementChild
klass = el.className klass = el.className
post = post =
root: node root: node