Fix support of inlined posts in other features.

This commit is contained in:
Nicolas Stepien 2012-05-03 11:03:15 +02:00
parent 1e50568520
commit e516eed4eb
2 changed files with 45 additions and 45 deletions

View File

@ -227,7 +227,6 @@
left = left < 10 ? '0px' : UI.width - left < 10 ? null : left + 'px'; left = left < 10 ? '0px' : UI.width - left < 10 ? null : left + 'px';
top = top < 10 ? '0px' : UI.height - top < 10 ? null : top + 'px'; top = top < 10 ? '0px' : UI.height - top < 10 ? null : top + 'px';
style = UI.el.style; style = UI.el.style;
$.log(left, top);
style.left = left; style.left = left;
style.top = top; style.top = top;
style.right = left === null ? '0px' : null; style.right = left === null ? '0px' : null;
@ -619,7 +618,7 @@
if (post.isInlined) { if (post.isInlined) {
return; return;
} }
isOP = /\bop\b/.test(post["class"]); isOP = post.id === post.threadId;
root = post.root; root = post.root;
for (key in Filter.filters) { for (key in Filter.filters) {
value = Filter[key](post); value = Filter[key](post);
@ -907,8 +906,8 @@
} }
quote.href = "res/" + href; quote.href = "res/" + href;
} }
id = reply.firstElementChild.id.slice(2); id = reply.id.slice(2);
link = $('.postNum.desktop', reply).firstElementChild; link = $('.postInfo > .postNum > a:first-child', reply);
link.href = "res/" + threadID + "#p" + id; link.href = "res/" + threadID + "#p" + id;
link.nextSibling.href = "res/" + threadID + "#q" + id; link.nextSibling.href = "res/" + threadID + "#q" + id;
nodes.push(reply); nodes.push(reply);
@ -2453,7 +2452,7 @@
dialog = UI.dialog('updater', 'bottom: 0; right: 0;', html); dialog = UI.dialog('updater', 'bottom: 0; right: 0;', html);
this.count = $('#count', dialog); this.count = $('#count', dialog);
this.timer = $('#timer', dialog); this.timer = $('#timer', dialog);
this.thread = $('.thread'); this.thread = $.id("t" + g.THREAD_ID);
_ref = $$('input', dialog); _ref = $$('input', dialog);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
input = _ref[_i]; input = _ref[_i];
@ -2712,7 +2711,7 @@
}, },
node: function(post) { node: function(post) {
var name, node; var name, node;
if (post["class"] === 'inline') { if (post.isInlined && !post.isCrosspost) {
return; return;
} }
name = $('.name', post.el); name = $('.name', post.el);
@ -2773,7 +2772,7 @@
node: function(post) { node: function(post) {
var img, link, nodes, _i, _len, _ref; var img, link, nodes, _i, _len, _ref;
img = post.img; img = post.img;
if (post["class"] === 'inline' || !img) { if (post.isInlined && !post.isCrosspost || !img) {
return; return;
} }
img = img.parentNode; img = img.parentNode;
@ -2794,7 +2793,7 @@
node: function(post) { node: function(post) {
var img; var img;
img = post.img; img = post.img;
if (!(img && /^Spoiler/.test(img.alt)) || post["class"] === 'inline') { if (!(img && /^Spoiler/.test(img.alt)) || post.isInlined && !post.isCrosspost) {
return; return;
} }
img.removeAttribute('style'); img.removeAttribute('style');
@ -2824,7 +2823,7 @@
}, },
node: function(post) { node: function(post) {
var node; var node;
if (post["class"] === 'inline') { if (post.isInlined && !post.isCrosspost) {
return; return;
} }
node = $('.postInfo > .dateTime', post.el); node = $('.postInfo > .dateTime', post.el);
@ -2919,7 +2918,7 @@
}, },
node: function(post) { node: function(post) {
var data, link, node, regexp, resolution, size, span, unit, _, _ref; 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; return;
} }
regexp = /^File: (<.+>)-\((?:Spoiler Image, )?([\d\.]+) (\w+), (\d+x\d+|PDF)/; regexp = /^File: (<.+>)-\((?:Spoiler Image, )?([\d\.]+) (\w+), (\d+x\d+|PDF)/;
@ -3207,7 +3206,7 @@
link = $('.postInfo > .postNum > a:first-child', newInline); link = $('.postInfo > .postNum > a:first-child', newInline);
link.href = "" + pathname + "#p" + id; link.href = "" + pathname + "#p" + id;
link.nextSibling.href = "" + pathname + "#q" + id; link.nextSibling.href = "" + pathname + "#q" + id;
$.addClass(newInline, 'crossquote'); $.addClass(newInline, 'crosspost');
return $.replace(inline, newInline); return $.replace(inline, newInline);
}, },
clone: function(id, el) { clone: function(id, el) {
@ -3324,7 +3323,7 @@
}, },
node: function(post) { node: function(post) {
var quote, _i, _len, _ref; var quote, _i, _len, _ref;
if (post["class"] === 'inline') { if (post.isInlined && !post.isCrosspost) {
return; return;
} }
_ref = post.quotes; _ref = post.quotes;
@ -3343,7 +3342,7 @@
}, },
node: function(post) { node: function(post) {
var path, quote, _i, _len, _ref; var path, quote, _i, _len, _ref;
if (post["class"] === 'inline') { if (post.isInlined && !post.isCrosspost) {
return; return;
} }
_ref = post.quotes; _ref = post.quotes;
@ -3366,7 +3365,7 @@
}, },
node: function(post) { node: function(post) {
var a, board, data, i, id, index, m, node, nodes, quote, quotes, snapshot, text, _i, _j, _len, _ref; 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; return;
} }
snapshot = d.evaluate('.//text()[not(parent::a)]', post.el.lastElementChild, null, 6, null); snapshot = d.evaluate('.//text()[not(parent::a)]', post.el.lastElementChild, null, 6, null);
@ -3384,7 +3383,7 @@
nodes.push($.tn(text)); nodes.push($.tn(text));
} }
id = quote.match(/\d+$/)[0]; 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', { nodes.push(a = $.el('a', {
textContent: "" + quote + "\u00A0(Dead)" textContent: "" + quote + "\u00A0(Dead)"
})); }));
@ -3487,7 +3486,7 @@
return; return;
} }
el = post.el; el = post.el;
if (el.hidden) { if (el.hidden || /\bop\b/.test(post["class"]) || post.isInlined) {
return; return;
} }
count = Unread.replies.push(el); count = Unread.replies.push(el);
@ -3743,7 +3742,7 @@
} }
a = post.img.parentNode; a = post.img.parentNode;
$.on(a, 'click', ImageExpand.cb.toggle); $.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); return ImageExpand.expand(post.img);
} }
}, },
@ -4147,6 +4146,7 @@
id: el.id.slice(1), id: el.id.slice(1),
threadId: g.THREAD_ID || $.x('ancestor::div[@class="thread"]', node).id.slice(1), threadId: g.THREAD_ID || $.x('ancestor::div[@class="thread"]', node).id.slice(1),
isInlined: /\binline\b/.test(klass), isInlined: /\binline\b/.test(klass),
isCrosspost: /\bcrosspost\b/.test(klass),
quotes: el.getElementsByClassName('quotelink'), quotes: el.getElementsByClassName('quotelink'),
backlinks: el.getElementsByClassName('backlink'), backlinks: el.getElementsByClassName('backlink'),
fileInfo: false, fileInfo: false,

View File

@ -194,7 +194,6 @@ UI =
#using null instead of '' is 4% faster #using null instead of '' is 4% faster
#these 4 statements are 40% faster than 1 style.cssText #these 4 statements are 40% faster than 1 style.cssText
{style} = UI.el {style} = UI.el
$.log left, top
style.left = left style.left = left
style.top = top style.top = top
style.right = if left is null then '0px' else null style.right = if left is null then '0px' else null
@ -510,7 +509,7 @@ Filter =
node: (post) -> node: (post) ->
return if post.isInlined return if post.isInlined
isOP = /\bop\b/.test post.class isOP = post.id is post.threadId
{root} = post {root} = post
for key of Filter.filters for key of Filter.filters
value = Filter[key] post value = Filter[key] post
@ -706,8 +705,8 @@ ExpandThread =
href = quote.getAttribute 'href' href = quote.getAttribute 'href'
continue if href[0] is '/' # Cross-board quote continue if href[0] is '/' # Cross-board quote
quote.href = "res/#{href}" # Fix pathnames quote.href = "res/#{href}" # Fix pathnames
id = reply.firstElementChild.id[2..] id = reply.id[2..]
link = $('.postNum.desktop', reply).firstElementChild link = $ '.postInfo > .postNum > a:first-child', reply
link.href = "res/#{threadID}#p#{id}" link.href = "res/#{threadID}#p#{id}"
link.nextSibling.href = "res/#{threadID}#q#{id}" link.nextSibling.href = "res/#{threadID}#q#{id}"
nodes.push reply nodes.push reply
@ -1945,7 +1944,7 @@ Updater =
@count = $ '#count', dialog @count = $ '#count', dialog
@timer = $ '#timer', dialog @timer = $ '#timer', dialog
@thread = $ '.thread' @thread = $.id "t#{g.THREAD_ID}"
for input in $$ 'input', dialog for input in $$ 'input', dialog
if input.type is 'checkbox' if input.type is 'checkbox'
@ -2156,7 +2155,7 @@ Anonymize =
init: -> init: ->
Main.callbacks.push @node Main.callbacks.push @node
node: (post) -> node: (post) ->
return if post.class is 'inline' return if post.isInlined and not post.isCrosspost
name = $ '.name', post.el name = $ '.name', post.el
name.textContent = 'Anonymous' name.textContent = 'Anonymous'
if node = name.nextElementSibling if node = name.nextElementSibling
@ -2195,7 +2194,7 @@ Sauce =
node: (post) -> node: (post) ->
{img} = 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 img = img.parentNode
nodes = [] nodes = []
for link in Sauce.links for link in Sauce.links
@ -2208,10 +2207,10 @@ RevealSpoilers =
Main.callbacks.push @node Main.callbacks.push @node
node: (post) -> node: (post) ->
{img} = 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 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'}"
Time = Time =
init: -> init: ->
@ -2236,7 +2235,7 @@ Time =
Main.callbacks.push @node Main.callbacks.push @node
node: (post) -> node: (post) ->
return if post.class is 'inline' return if post.isInlined and not post.isCrosspost
node = $ '.postInfo > .dateTime', post.el node = $ '.postInfo > .dateTime', post.el
Time.date = Time.parse node.textContent Time.date = Time.parse node.textContent
node.textContent = Time.funk(Time) node.textContent = Time.funk(Time)
@ -2296,7 +2295,7 @@ FileInfo =
@setFormats() @setFormats()
Main.callbacks.push @node Main.callbacks.push @node
node: (post) -> 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)/ regexp = /^File: (<.+>)-\((?:Spoiler Image, )?([\d\.]+) (\w+), (\d+x\d+|PDF)/
[_, link, size, unit, resolution] = [_, link, size, unit, resolution] =
node.innerHTML.match regexp node.innerHTML.match regexp
@ -2482,7 +2481,7 @@ QuoteInline =
link = $ '.postInfo > .postNum > a:first-child', newInline link = $ '.postInfo > .postNum > a:first-child', newInline
link.href = "#{pathname}#p#{id}" link.href = "#{pathname}#p#{id}"
link.nextSibling.href = "#{pathname}#q#{id}" link.nextSibling.href = "#{pathname}#q#{id}"
$.addClass newInline, 'crossquote' $.addClass newInline, 'crosspost'
$.replace inline, newInline $.replace inline, newInline
clone: (id, el) -> clone: (id, el) ->
@ -2558,7 +2557,7 @@ QuoteOP =
init: -> init: ->
Main.callbacks.push @node Main.callbacks.push @node
node: (post) -> node: (post) ->
return if post.class is 'inline' return if post.isInlined and not post.isCrosspost
for quote in post.quotes for quote in post.quotes
if quote.hash[2..] is post.threadId if quote.hash[2..] is post.threadId
# \u00A0 is nbsp # \u00A0 is nbsp
@ -2569,7 +2568,7 @@ QuoteCT =
init: -> init: ->
Main.callbacks.push @node Main.callbacks.push @node
node: (post) -> node: (post) ->
return if post.class is 'inline' return if post.isInlined and not post.isCrosspost
for quote in post.quotes for quote in post.quotes
unless quote.hash unless quote.hash
# Make sure this isn't a link to the board we're on. # Make sure this isn't a link to the board we're on.
@ -2585,7 +2584,7 @@ Quotify =
init: -> init: ->
Main.callbacks.push @node Main.callbacks.push @node
node: (post) -> node: (post) ->
return if post.class is 'inline' return if post.isInlined and not post.isCrosspost
# XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE is 6 # XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE is 6
# Get all the text nodes that are not inside an anchor. # Get all the text nodes that are not inside an anchor.
@ -2613,7 +2612,7 @@ Quotify =
m[1] m[1]
else else
# Get the post's board, whether it's inlined or not. # 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', nodes.push a = $.el 'a',
# \u00A0 is nbsp # \u00A0 is nbsp
@ -2695,7 +2694,7 @@ Unread =
return return
{el} = post {el} = post
# new HTML ??? # 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 count = Unread.replies.push el
Unread.update count is 1 Unread.update count is 1
@ -2867,7 +2866,7 @@ ImageExpand =
return unless post.img return unless post.img
a = post.img.parentNode a = post.img.parentNode
$.on a, 'click', ImageExpand.cb.toggle $.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 ImageExpand.expand post.img
cb: cb:
toggle: (e) -> toggle: (e) ->
@ -3180,16 +3179,17 @@ Main =
el = $ '.post', node el = $ '.post', node
klass = el.className klass = el.className
post = post =
root: node root: node
el: el el: el
class: klass class: klass
id: el.id[1..] id: el.id[1..]
threadId: g.THREAD_ID or $.x('ancestor::div[@class="thread"]', node).id[1..] threadId: g.THREAD_ID or $.x('ancestor::div[@class="thread"]', node).id[1..]
isInlined: /\binline\b/.test klass isInlined: /\binline\b/.test klass
quotes: el.getElementsByClassName 'quotelink' isCrosspost: /\bcrosspost\b/.test klass
backlinks: el.getElementsByClassName 'backlink' quotes: el.getElementsByClassName 'quotelink'
fileInfo: false backlinks: el.getElementsByClassName 'backlink'
img: false fileInfo: false
img: false
if fileInfo = $ '.fileInfo', el if fileInfo = $ '.fileInfo', el
img = fileInfo.nextElementSibling.firstElementChild img = fileInfo.nextElementSibling.firstElementChild
if img.alt isnt 'File deleted.' if img.alt isnt 'File deleted.'