Something that really bugs me about discourse (the software this forum uses)…
Large code blocks are difficult to read
When you consider they are likely to contain the most relevant information in the post, that’s extraordinarily annoying.
This post shows you a way to lift the code blocks out of the post and place them in a new window.
You’ll still need to scroll if the post is large, but it’s much better than it looks in the forum post, IMO.
Process
- Bring up the DevTools, open the console.
- Paste the following code into the console:
dump = function(post) {
var win = window.open("");
var style = win.document.createElement("style");
style.innerText = "body {background-color:#444;color:#ccc;}";
style.innerText += "#dump {font:normal 17px sans-serif;max-height:98vh;max-width:99vw;overflow:auto;scrollbar-color:#ace #444;scrollbar-width:thin;}}";
style.innerText += "#dump div {font:normal 17px sans serif;background-color:#555;margin:0 0 2em 2em;}";
style.innerText += "pre {font:normal 16px monospace;padding:10px 10px;white-space:pre;}";
win.document.body.appendChild(style);
var div = win.document.createElement("div");
div.id = "dump";
var codes = "";
var allcodes = document.querySelectorAll(post + " pre code");
for(var i = 0; i < allcodes.length; i++) {
codes += "Code block:<br><div><pre><code>" + allcodes[i].innerHTML + "</code></pre></div>";
}
div.innerHTML = codes;
win.document.body.appendChild(div);
}
dump("#post_1");
-
You will need to replace the id in
dump("#post_1")
with the id of the post you want to inspect. -
Then hit return and a new window will popup with ALL the code blocks laid out for your viewing pleasure
And because @bionel is a complete ass and pointed out I’d made a poor choice for
<pre>
whitespace handling, here’s the ALL NEW FIXED version dogfooding the code above:
Competition! Big Prizes!!!
It would be nice to automate this little tool. A Tampermonkey script could do this easily and remove the need to use the console.
What are you waiting for? Go!