Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

Description

This is a small userscript I made that shows the amount of characters in a code block above it. It is mainly for the http://codegolf.stackexchange.com site.

Screenshot

(This is just some random answer on codegolf.SE.)

image

Code

(minified)

$("pre code").each(function(){$(this).parent().before('<div style="border: 1px dotted #C0D4DB; border-bottom: none; border-radius: 5px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; padding: 3px; font: 12px monospace; display: inline; background-color: #F7FDFF; margin-left: 5px">'+$(this).text().trim().replace(/&amp;|&lt;|&gt;|&quot;|&#039;/g," ").length+" chars</div>")})

Type javascript: in the URL bar, and paste this after it. (or just paste it into the console)

Userscript

http://userscripts.org/scripts/show/178565

share|improve this question
    
I wrote a similar script a long time back but later abandoned it. I like the style of yours. –  Nathan Osman Oct 19 '13 at 3:57
    
Just a bit of clarification if you don't mind: /&amp;|&lt;|&gt;|&quot;|&#039;/g. Wouldn't this not count characters when someone uses html entities for codegolf? –  Mhmd Feb 15 at 18:08
    
@user689 It replaces them with spaces, so it still counts them. –  Doorknob Feb 15 at 18:10
    
But it would count them as a 1 character and not 4. Why are you using this in the first place? –  Mhmd Feb 15 at 18:12
    
@user689 Because they are one character, not 4. If I didn't have that they would be counted as 4. –  Doorknob Feb 15 at 18:12
    
Thanks I didn't know about that. –  Mhmd Feb 15 at 18:13
add comment

You must log in to answer this question.

Browse other questions tagged .