Thread expansion mostly fixed.

This commit is contained in:
Nicolas Stepien 2012-04-30 09:47:50 +02:00
commit 755a21ac01
5 changed files with 69 additions and 68 deletions

View File

@ -1,6 +1,6 @@
// ==UserScript== // ==UserScript==
// @name 4chan x // @name 4chan x
// @version 2.29.3 // @version 2.29.4
// @namespace aeosynth // @namespace aeosynth
// @description Adds various features. // @description Adds various features.
// @copyright 2009-2011 James Campos <james.r.campos@gmail.com> // @copyright 2009-2011 James Campos <james.r.campos@gmail.com>
@ -19,7 +19,7 @@
* Copyright (c) 2009-2011 James Campos <james.r.campos@gmail.com> * Copyright (c) 2009-2011 James Campos <james.r.campos@gmail.com>
* Copyright (c) 2012 Nicolas Stepien <stepien.nicolas@gmail.com> * Copyright (c) 2012 Nicolas Stepien <stepien.nicolas@gmail.com>
* http://mayhemydg.github.com/4chan-x/ * http://mayhemydg.github.com/4chan-x/
* 4chan X 2.29.3 * 4chan X 2.29.4
* *
* Permission is hereby granted, free of charge, to any person * Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation * obtaining a copy of this software and associated documentation
@ -825,36 +825,30 @@
ExpandThread = { ExpandThread = {
init: function() { init: function() {
var a, span, _i, _len, _ref, _results; var a, span, _i, _len, _ref, _results;
_ref = $$('.omittedposts'); _ref = $$('.summary');
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
span = _ref[_i]; span = _ref[_i];
a = $.el('a', { a = $.el('a', {
textContent: "+ " + span.textContent, textContent: "+ " + span.textContent,
className: 'omittedposts', className: 'summary desktop',
href: 'javascript:;' href: 'javascript:;'
}); });
$.on(a, 'click', ExpandThread.cb.toggle); $.on(a, 'click', function() {
return ExpandThread.toggle(this.parentNode);
});
_results.push($.replace(span, a)); _results.push($.replace(span, a));
} }
return _results; return _results;
}, },
cb: {
toggle: function() {
var thread;
thread = this.parentNode;
return ExpandThread.toggle(thread);
}
},
toggle: function(thread) { toggle: function(thread) {
var a, backlink, num, pathname, prev, table, threadID, _i, _len, _ref, _ref1, _results; var a, backlink, container, div, next, num, pathname, _i, _len, _ref, _results;
threadID = thread.firstChild.id; pathname = "/" + g.BOARD + "/res/" + thread.id.slice(1);
pathname = "/" + g.BOARD + "/res/" + threadID; a = $('.summary', thread);
a = $('.omittedposts', thread);
switch (a.textContent[0]) { switch (a.textContent[0]) {
case '+': case '+':
if ((_ref = $('.op .container', thread)) != null) { if (container = $('.container', thread.firstElementChild)) {
_ref.textContent = ''; $.rm(container);
} }
a.textContent = a.textContent.replace('+', '\u00d7 Loading...'); a.textContent = a.textContent.replace('+', '\u00d7 Loading...');
return $.cache(pathname, (function() { return $.cache(pathname, (function() {
@ -876,14 +870,14 @@
return 5; return 5;
} }
})(); })();
table = $.x("following::br[@clear]/preceding::table[" + num + "]", a); div = $.x("following-sibling::div[last()]/preceding-sibling::div[" + (num - 1) + "]", a);
while ((prev = table.previousSibling) && (prev.nodeName !== 'A')) { while ((next = a.nextSibling) && next !== div) {
$.rm(prev); $.rm(next);
} }
_ref1 = $$('.backlink', $('.op', thread)); _ref = $$('.backlink', a.previousElementSibling);
_results = []; _results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
backlink = _ref1[_i]; backlink = _ref[_i];
if (!$.id(backlink.hash.slice(1))) { if (!$.id(backlink.hash.slice(1))) {
_results.push($.rm(backlink)); _results.push($.rm(backlink));
} else { } else {
@ -894,7 +888,7 @@
} }
}, },
parse: function(req, pathname, thread, a) { parse: function(req, pathname, thread, a) {
var doc, href, link, next, nodes, quote, reply, table, _i, _j, _len, _len1, _ref, _ref1; var doc, href, id, link, next, nodes, quote, reply, threadID, _i, _j, _len, _len1, _ref, _ref1;
if (req.status !== 200) { if (req.status !== 200) {
a.textContent = "" + req.status + " " + req.statusText; a.textContent = "" + req.status + " " + req.statusText;
$.off(a, 'click', ExpandThread.cb.toggle); $.off(a, 'click', ExpandThread.cb.toggle);
@ -903,29 +897,32 @@
a.textContent = a.textContent.replace('\u00d7 Loading...', '-'); a.textContent = a.textContent.replace('\u00d7 Loading...', '-');
doc = d.implementation.createHTMLDocument(''); doc = d.implementation.createHTMLDocument('');
doc.documentElement.innerHTML = req.response; doc.documentElement.innerHTML = req.response;
threadID = thread.id.slice(1);
nodes = []; nodes = [];
_ref = $$('.reply', doc); _ref = $$('.replyContainer', doc);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
reply = _ref[_i]; reply = _ref[_i];
table = d.importNode(reply.parentNode.parentNode.parentNode); reply = d.importNode(reply);
_ref1 = $$('.quotelink', table); _ref1 = $$('.quotelink', reply);
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
quote = _ref1[_j]; quote = _ref1[_j];
if (quote.hash === (href = quote.getAttribute('href'))) { href = quote.getAttribute('href');
if (quote.hash === href) {
quote.pathname = pathname; quote.pathname = pathname;
} else if (href !== quote.href) { } else if (href !== quote.href) {
quote.href = "res/" + href; quote.href = "res/" + href;
} }
} }
link = $('.quotejs', table); id = reply.firstElementChild.id.slice(2);
link.href = "res/" + thread.firstChild.id + "#" + reply.id; link = $('.postNum.desktop', reply).firstElementChild;
link.nextSibling.href = "res/" + thread.firstChild.id + "#q" + reply.id; link.href = "res/" + threadID + "#p" + id;
nodes.push(table); link.nextSibling.href = "res/" + threadID + "#q" + id;
nodes.push(reply);
} }
while ((next = a.nextSibling) && !next.clear) { while (next = a.nextSibling) {
$.rm(next); $.rm(next);
} }
return $.before(next, nodes); return $.after(a, nodes);
} }
}; };
@ -4206,7 +4203,7 @@
} }
}, },
namespace: '4chan_x.', namespace: '4chan_x.',
version: '2.29.3', version: '2.29.4',
callbacks: [], callbacks: [],
css: '\ css: '\
/* dialog styling */\ /* dialog styling */\

View File

@ -2,7 +2,7 @@
{exec} = require 'child_process' {exec} = require 'child_process'
fs = require 'fs' fs = require 'fs'
VERSION = '2.29.3' VERSION = '2.29.4'
HEADER = """ HEADER = """
// ==UserScript== // ==UserScript==

View File

@ -1,6 +1,9 @@
master master
2.29.4
- Mayhem - Mayhem
Auto-GIF will not run in /gif/. Auto-GIF will not run in /gif/.
Fix QR filetype checking.
2.29.3 2.29.3
- Mayhem - Mayhem

View File

@ -1 +1 @@
postMessage({version:'2.29.3'},'*') postMessage({version:'2.29.4'},'*')

View File

@ -550,7 +550,7 @@ Filter =
name: (post) -> name: (post) ->
$('.name', post.el).textContent or false $('.name', post.el).textContent or false
uniqueid: (post) -> uniqueid: (post) ->
# NEW FORMAT ??? # NEW HTML ???
if uid = $ '.posteruid', post.el if uid = $ '.posteruid', post.el
return uid.textContent return uid.textContent
false false
@ -656,29 +656,24 @@ ExpandComment =
ExpandThread = ExpandThread =
init: -> init: ->
for span in $$ '.omittedposts' for span in $$ '.summary'
a = $.el 'a', a = $.el 'a',
textContent: "+ #{span.textContent}" textContent: "+ #{span.textContent}"
className: 'omittedposts' className: 'summary desktop'
href: 'javascript:;' href: 'javascript:;'
$.on a, 'click', ExpandThread.cb.toggle $.on a, 'click', -> ExpandThread.toggle @parentNode
$.replace span, a $.replace span, a
cb:
toggle: ->
thread = @parentNode
ExpandThread.toggle thread
toggle: (thread) -> toggle: (thread) ->
threadID = thread.firstChild.id pathname = "/#{g.BOARD}/res/#{thread.id[1..]}"
pathname = "/#{g.BOARD}/res/#{threadID}" a = $ '.summary', thread
a = $ '.omittedposts', thread
# \u00d7 is &times; # \u00d7 is &times;
switch a.textContent[0] switch a.textContent[0]
when '+' when '+'
$('.op .container', thread)?.textContent = '' if container = $ '.container', thread.firstElementChild
$.rm container
a.textContent = a.textContent.replace '+', '\u00d7 Loading...' a.textContent = a.textContent.replace '+', '\u00d7 Loading...'
$.cache pathname, (-> ExpandThread.parse @, pathname, thread, a) $.cache pathname, (-> ExpandThread.parse @, pathname, thread, a)
@ -693,11 +688,11 @@ ExpandThread =
when 'b', 'vg' then 3 when 'b', 'vg' then 3
when 't' then 1 when 't' then 1
else 5 else 5
table = $.x "following::br[@clear]/preceding::table[#{num}]", a div = $.x "following-sibling::div[last()]/preceding-sibling::div[#{num - 1}]", a
while (prev = table.previousSibling) and (prev.nodeName isnt 'A') while (next = a.nextSibling) and next isnt div
$.rm prev $.rm next
for backlink in $$ '.backlink', $ '.op', thread for backlink in $$ '.backlink', a.previousElementSibling
$.rm backlink if !$.id backlink.hash[1..] $.rm backlink unless $.id backlink.hash[1..]
parse: (req, pathname, thread, a) -> parse: (req, pathname, thread, a) ->
@ -711,22 +706,28 @@ ExpandThread =
doc = d.implementation.createHTMLDocument '' doc = d.implementation.createHTMLDocument ''
doc.documentElement.innerHTML = req.response doc.documentElement.innerHTML = req.response
nodes = [] threadID = thread.id[1..]
for reply in $$ '.reply', doc nodes = []
table = d.importNode reply.parentNode.parentNode.parentNode for reply in $$ '.replyContainer', doc
for quote in $$ '.quotelink', table reply = d.importNode reply
if quote.hash is href = quote.getAttribute 'href' # Add pathname to in-thread quotes for quote in $$ '.quotelink', reply
href = quote.getAttribute 'href'
if quote.hash is href # Add pathname to in-thread quotes
quote.pathname = pathname quote.pathname = pathname
# NEW HTML ???
# OP quotes have different href attribute than normal quotes.
# Waiting for a reply from moot.
else if href isnt quote.href # Fix cross-thread links, not cross-board ones else if href isnt quote.href # Fix cross-thread links, not cross-board ones
quote.href = "res/#{href}" quote.href = "res/#{href}"
link = $ '.quotejs', table id = reply.firstElementChild.id[2..]
link.href = "res/#{thread.firstChild.id}##{reply.id}" link = $('.postNum.desktop', reply).firstElementChild
link.nextSibling.href = "res/#{thread.firstChild.id}#q#{reply.id}" link.href = "res/#{threadID}#p#{id}"
nodes.push table link.nextSibling.href = "res/#{threadID}#q#{id}"
nodes.push reply
# eat everything, then replace with fresh full posts # eat everything, then replace with fresh full posts
while (next = a.nextSibling) and not next.clear #br[clear] while next = a.nextSibling
$.rm next $.rm next
$.before next, nodes $.after a, nodes
ReplyHiding = ReplyHiding =
init: -> init: ->
@ -3220,7 +3221,7 @@ Main =
Main.node [Main.preParse target] Main.node [Main.preParse target]
namespace: '4chan_x.' namespace: '4chan_x.'
version: '2.29.3' version: '2.29.4'
callbacks: [] callbacks: []
css: ' css: '
/* dialog styling */ /* dialog styling */