More efficient prettifying.
This commit is contained in:
parent
9b210f1501
commit
81b6d97c59
@ -747,6 +747,7 @@
|
|||||||
}
|
}
|
||||||
quote.href = "res/" + href;
|
quote.href = "res/" + href;
|
||||||
}
|
}
|
||||||
|
Main.prettify(node);
|
||||||
post = {
|
post = {
|
||||||
el: node,
|
el: node,
|
||||||
threadId: threadID,
|
threadId: threadID,
|
||||||
@ -768,8 +769,7 @@
|
|||||||
if (Conf['Indicate Cross-thread Quotes']) {
|
if (Conf['Indicate Cross-thread Quotes']) {
|
||||||
QuoteCT.node(post);
|
QuoteCT.node(post);
|
||||||
}
|
}
|
||||||
$.replace(a.parentNode.parentNode, node);
|
return $.replace(a.parentNode.parentNode, node);
|
||||||
return Main.prettify();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -3258,7 +3258,7 @@
|
|||||||
return $.off(this, 'mouseout click', QuotePreview.mouseout);
|
return $.off(this, 'mouseout click', QuotePreview.mouseout);
|
||||||
},
|
},
|
||||||
parse: function(req, id) {
|
parse: function(req, id) {
|
||||||
var doc, fileInfo, img, node, post, qp;
|
var bq, doc, fileInfo, img, node, post, qp;
|
||||||
if (!((qp = UI.el) && qp.textContent === ("Loading " + id + "..."))) {
|
if (!((qp = UI.el) && qp.textContent === ("Loading " + id + "..."))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3270,7 +3270,9 @@
|
|||||||
doc.documentElement.innerHTML = req.response;
|
doc.documentElement.innerHTML = req.response;
|
||||||
node = doc.getElementById("p" + id);
|
node = doc.getElementById("p" + id);
|
||||||
qp.innerHTML = node.innerHTML;
|
qp.innerHTML = node.innerHTML;
|
||||||
Main.prettify();
|
bq = $('blockquote', qp);
|
||||||
|
bq.id += '_qp';
|
||||||
|
Main.prettify(bq);
|
||||||
post = {
|
post = {
|
||||||
el: qp
|
el: qp
|
||||||
};
|
};
|
||||||
@ -4125,6 +4127,7 @@
|
|||||||
threadId: g.THREAD_ID || $.x('ancestor::div[parent::div[@class="board"]]', node).id.slice(1),
|
threadId: g.THREAD_ID || $.x('ancestor::div[parent::div[@class="board"]]', node).id.slice(1),
|
||||||
isInlined: /\binline\b/.test(rootClass),
|
isInlined: /\binline\b/.test(rootClass),
|
||||||
isCrosspost: /\bcrosspost\b/.test(rootClass),
|
isCrosspost: /\bcrosspost\b/.test(rootClass),
|
||||||
|
blockquote: el.lastElementChild,
|
||||||
quotes: el.getElementsByClassName('quotelink'),
|
quotes: el.getElementsByClassName('quotelink'),
|
||||||
backlinks: el.getElementsByClassName('backlink'),
|
backlinks: el.getElementsByClassName('backlink'),
|
||||||
fileInfo: false,
|
fileInfo: false,
|
||||||
@ -4137,6 +4140,7 @@
|
|||||||
post.img = img;
|
post.img = img;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Main.prettify(post.blockquote);
|
||||||
return post;
|
return post;
|
||||||
},
|
},
|
||||||
node: function(nodes, notify) {
|
node: function(nodes, notify) {
|
||||||
@ -4155,7 +4159,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Main.prettify();
|
|
||||||
},
|
},
|
||||||
observer: function(mutations) {
|
observer: function(mutations) {
|
||||||
var addedNode, mutation, nodes, _i, _j, _len, _len1, _ref;
|
var addedNode, mutation, nodes, _i, _j, _len, _len1, _ref;
|
||||||
@ -4181,11 +4184,20 @@
|
|||||||
return Main.node([Main.preParse(target)]);
|
return Main.node([Main.preParse(target)]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
prettify: function() {
|
prettify: function(bq) {
|
||||||
|
var code;
|
||||||
if (!Main.hasCodeTags) {
|
if (!Main.hasCodeTags) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return $.globalEval('window.prettyPrint()');
|
code = function() {
|
||||||
|
var pre, _i, _len, _ref;
|
||||||
|
_ref = document.getElementById('_id_').getElementsByClassName('prettyprint');
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
pre = _ref[_i];
|
||||||
|
pre.innerHTML = prettyPrintOne(pre.innerHTML.replace(/\s/g, ' '));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return $.globalEval(("(" + code + ")()").replace('_id_', bq.id));
|
||||||
},
|
},
|
||||||
namespace: '4chan_x.',
|
namespace: '4chan_x.',
|
||||||
version: '2.30.4',
|
version: '2.30.4',
|
||||||
|
|||||||
@ -576,6 +576,7 @@ ExpandComment =
|
|||||||
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
|
||||||
|
Main.prettify node
|
||||||
post =
|
post =
|
||||||
el: node
|
el: node
|
||||||
threadId: threadID
|
threadId: threadID
|
||||||
@ -592,7 +593,6 @@ ExpandComment =
|
|||||||
if Conf['Indicate Cross-thread Quotes']
|
if Conf['Indicate Cross-thread Quotes']
|
||||||
QuoteCT.node post
|
QuoteCT.node post
|
||||||
$.replace a.parentNode.parentNode, node
|
$.replace a.parentNode.parentNode, node
|
||||||
Main.prettify()
|
|
||||||
|
|
||||||
ExpandThread =
|
ExpandThread =
|
||||||
init: ->
|
init: ->
|
||||||
@ -2478,7 +2478,9 @@ QuotePreview =
|
|||||||
|
|
||||||
node = doc.getElementById "p#{id}"
|
node = doc.getElementById "p#{id}"
|
||||||
qp.innerHTML = node.innerHTML
|
qp.innerHTML = node.innerHTML
|
||||||
Main.prettify()
|
bq = $ 'blockquote', qp
|
||||||
|
bq.id += '_qp'
|
||||||
|
Main.prettify bq
|
||||||
post =
|
post =
|
||||||
el: qp
|
el: qp
|
||||||
if fileInfo = $ '.fileInfo', qp
|
if fileInfo = $ '.fileInfo', qp
|
||||||
@ -3140,6 +3142,7 @@ Main =
|
|||||||
threadId: g.THREAD_ID or $.x('ancestor::div[parent::div[@class="board"]]', node).id[1..]
|
threadId: g.THREAD_ID or $.x('ancestor::div[parent::div[@class="board"]]', node).id[1..]
|
||||||
isInlined: /\binline\b/.test rootClass
|
isInlined: /\binline\b/.test rootClass
|
||||||
isCrosspost: /\bcrosspost\b/.test rootClass
|
isCrosspost: /\bcrosspost\b/.test rootClass
|
||||||
|
blockquote: el.lastElementChild
|
||||||
quotes: el.getElementsByClassName 'quotelink'
|
quotes: el.getElementsByClassName 'quotelink'
|
||||||
backlinks: el.getElementsByClassName 'backlink'
|
backlinks: el.getElementsByClassName 'backlink'
|
||||||
fileInfo: false
|
fileInfo: false
|
||||||
@ -3149,6 +3152,7 @@ Main =
|
|||||||
if img.alt isnt 'File deleted.'
|
if img.alt isnt 'File deleted.'
|
||||||
post.fileInfo = fileInfo
|
post.fileInfo = fileInfo
|
||||||
post.img = img
|
post.img = img
|
||||||
|
Main.prettify post.blockquote
|
||||||
post
|
post
|
||||||
node: (nodes, notify) ->
|
node: (nodes, notify) ->
|
||||||
for callback in Main.callbacks
|
for callback in Main.callbacks
|
||||||
@ -3156,7 +3160,6 @@ Main =
|
|||||||
callback node for node in nodes
|
callback node for node in nodes
|
||||||
catch err
|
catch err
|
||||||
alert "4chan X (#{Main.version}) error: #{err.message}\nhttp://mayhemydg.github.com/4chan-x/#bug-report\n\n#{err.stack}" if notify
|
alert "4chan X (#{Main.version}) error: #{err.message}\nhttp://mayhemydg.github.com/4chan-x/#bug-report\n\n#{err.stack}" if notify
|
||||||
Main.prettify()
|
|
||||||
return
|
return
|
||||||
observer: (mutations) ->
|
observer: (mutations) ->
|
||||||
nodes = []
|
nodes = []
|
||||||
@ -3170,10 +3173,13 @@ Main =
|
|||||||
if /\bpostContainer\b/.test target.className
|
if /\bpostContainer\b/.test target.className
|
||||||
Main.node [Main.preParse target]
|
Main.node [Main.preParse target]
|
||||||
|
|
||||||
prettify: ->
|
prettify: (bq) ->
|
||||||
return unless Main.hasCodeTags
|
return unless Main.hasCodeTags
|
||||||
# window.prettyPrintOne(html) does not preserve indentation
|
code = ->
|
||||||
$.globalEval 'window.prettyPrint()'
|
for pre in document.getElementById('_id_').getElementsByClassName 'prettyprint'
|
||||||
|
pre.innerHTML = prettyPrintOne pre.innerHTML.replace /\s/g, ' '
|
||||||
|
return
|
||||||
|
$.globalEval "(#{code})()".replace '_id_', bq.id
|
||||||
|
|
||||||
namespace: '4chan_x.'
|
namespace: '4chan_x.'
|
||||||
version: '2.30.4'
|
version: '2.30.4'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user