- Go to http://gistlet.com/?gist=726b25f6d0740bd0fc08
- Drag the bookmark to your URL bar
- You're done!
-
-
Save klamping/726b25f6d0740bd0fc08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var codeBlocks = document.getElementsByTagName('pre'), | |
codeLines = 0, | |
body = document.getElementsByTagName('body')[0], | |
text = function(el) { | |
if (el.innerText) return el.innerText; | |
return el.textContent; | |
}; | |
var trimEmptyLines = function (lines) { | |
return lines.filter(function (line) { | |
return line.length > 0; | |
}) | |
}; | |
var wordCount = text(body).split(' ').length; | |
for (var i = codeBlocks.length - 1; i >= 0; i--) { | |
var code = text(codeBlocks[i]); | |
if (code) { | |
codeLines += trimEmptyLines(code.split('\n')).length; | |
wordCount -= code.split(' ').length; | |
} | |
} | |
var total = wordCount + codeLines * 10; | |
var list = []; | |
list.push(wordCount + ' words (not including code)'); | |
list.push(codeLines + ' lines of code (counting for ' + codeLines * 10 + ' words)'); | |
list.push(total + ' total'); | |
var message = 'Article has:'; | |
message += '<ul style="margin: 0;padding-left: 20px;"><li>'; | |
message += list.join('</li><li>'); | |
message += '</li></ul>'; | |
var el = document.createElement('p'); | |
el.style.color = '#000'; | |
el.style.position = 'relative'; | |
el.style['z-index'] = 1000000; | |
el.style.border = '1px solid #999'; | |
el.style.padding = '10px'; | |
el.style.margin = '10px'; | |
el.style.background = '#FFF'; | |
el.style['border-radius'] = '2px'; | |
el.innerHTML = message; | |
body.insertBefore(el, body.firstChild); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment