This commit is contained in:
Nicolas Stepien 2012-05-27 16:22:15 +02:00
parent bccee036b2
commit b059bb7fd1
3 changed files with 38 additions and 12 deletions

View File

@ -449,6 +449,14 @@
},
open: function(url) {
return (GM_openInTab || window.open)(location.protocol + url, '_blank');
},
globalEval: function(code) {
var script;
script = $.el('script', {
textContent: code
});
$.add(d.head, script);
return $.rm(script);
}
});
@ -760,7 +768,8 @@
if (Conf['Indicate Cross-thread Quotes']) {
QuoteCT.node(post);
}
return $.replace(a.parentNode.parentNode, node);
$.replace(a.parentNode.parentNode, node);
return Main.prettify();
}
};
@ -1356,7 +1365,7 @@
return setTimeout(this.asyncInit);
},
asyncInit: function() {
var link, script;
var link;
if (Conf['Hide Original Post Form']) {
link = $.el('h1', {
innerHTML: "<a href=javascript:;>" + (g.REPLY ? 'Quick Reply' : 'New Thread') + "</a>"
@ -1370,11 +1379,7 @@
});
$.before($.id('postForm'), link);
}
script = $.el('script', {
textContent: 'Recaptcha.focus_response_field=function(){}'
});
$.add(d.head, script);
$.rm(script);
$.globalEval('Recaptcha.focus_response_field=function(){}');
if (Conf['Persistent QR']) {
QR.dialog();
if (Conf['Auto Hide QR']) {
@ -3282,8 +3287,9 @@
Time.node(post);
}
if (Conf['File Info Formatting']) {
return FileInfo.node(post);
FileInfo.node(post);
}
return Main.prettify();
}
};
@ -4060,6 +4066,7 @@
});
}
}
Main.hasCodeTags = !!$('script[src="//static.4chan.org/js/prettify/prettify.js"]');
board = $('.board');
nodes = [];
_ref1 = $$('.postContainer', board);
@ -4148,6 +4155,7 @@
}
}
}
Main.prettify();
},
observer: function(mutations) {
var addedNode, mutation, nodes, _i, _j, _len, _len1, _ref;
@ -4173,6 +4181,12 @@
return Main.node([Main.preParse(target)]);
}
},
prettify: function() {
if (!Main.hasCodeTags) {
return;
}
return $.globalEval('window.prettyPrint()');
},
namespace: '4chan_x.',
version: '2.30.4',
callbacks: [],

View File

@ -1,6 +1,7 @@
master
- Mayhem
Fix syntax highlighting in code of fetched posts on /g/.
Add quick [code] tags keybind (alt+c).
2.30.4

View File

@ -346,6 +346,10 @@ $.extend $,
return
open: (url) ->
(GM_openInTab or window.open) location.protocol + url, '_blank'
globalEval: (code) ->
script = $.el 'script', textContent: code
$.add d.head, script
$.rm script
$.cache.requests = {}
@ -588,6 +592,7 @@ ExpandComment =
if Conf['Indicate Cross-thread Quotes']
QuoteCT.node post
$.replace a.parentNode.parentNode, node
Main.prettify()
ExpandThread =
init: ->
@ -1014,10 +1019,7 @@ QR =
$.before $.id('postForm'), link
# Prevent original captcha input from being focused on reload.
script = $.el 'script',
textContent: 'Recaptcha.focus_response_field=function(){}'
$.add d.head, script
$.rm script
$.globalEval 'Recaptcha.focus_response_field=function(){}'
if Conf['Persistent QR']
QR.dialog()
@ -2489,6 +2491,7 @@ QuotePreview =
Time.node post
if Conf['File Info Formatting']
FileInfo.node post
Main.prettify()
QuoteOP =
init: ->
@ -3088,6 +3091,8 @@ Main =
if Conf['Index Navigation']
setTimeout -> Nav.init()
Main.hasCodeTags = !! $ 'script[src="//static.4chan.org/js/prettify/prettify.js"]'
board = $ '.board'
nodes = []
for node in $$ '.postContainer', board
@ -3151,6 +3156,7 @@ Main =
callback node for node in nodes
catch err
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
observer: (mutations) ->
nodes = []
@ -3164,6 +3170,11 @@ Main =
if /\bpostContainer\b/.test target.className
Main.node [Main.preParse target]
prettify: ->
return unless Main.hasCodeTags
# window.prettyPrintOne(html) does not preserve indentation
$.globalEval 'window.prettyPrint()'
namespace: '4chan_x.'
version: '2.30.4'
callbacks: []