< User:GoldenRing
Browse history interactively ← Previous edit Next edit → Content deleted Content addedInline
Revision as of 16:03, 26 September 2020
// This function shamelessly copied from https://stackoverflow.com/a/11348383/274460
$.fn.ignore = function(sel){
return this.clone().find(sel||">*").remove().end();
};
function countWords(h) {
$(h).each(function(i, match) {
var elements = $(match).nextUntil(h);
elements.find(':hidden').addClass('wordcount-ignore');
elements.find('*').filter(function() { return $(this).css('text-decoration').match(/line-through/); }).addClass('wordcount-ignore');
elements.find('div#siteSub').addClass('wordcount-ignore');
elements.find('div#contentSub').addClass('wordcount-ignore');
elements.find('div#jump-to-nav').addClass('wordcount-ignore');
elements = elements.not('.wordcount-ignore');
var text = elements.ignore('span.localcomments').ignore('.wordcount-ignore').text();
var search = /(\d{1,2}):(\d{2}), (\d{1,2}) (+) (\d{4}) \(UTC\)/g;
text = text.replace(search, '');
text = text.split(/\s/).filter(function(d) { return d.length > 0; })
.filter(function(d) { return d.match(//); });
var count = text.length;
$(match).append($('<span class="mw-editsection">' + count.toLocaleString() + ' words</span>'));
});
}
$(document).ready(function() {
$('#p-cactions').children('ul.menu').append($('<li><a id="ca-wordcount" title="Add word counts to each section " accesskey="c">Word Count</a></li>'));
$('#ca-wordcount').click(function() {
countWords('h1');
countWords('h2');
countWords('h3');
});
});
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.
**DISCLAIMER** We are not affiliated with Wikipedia, and Cloudflare.
The information presented on this site is for general informational purposes only and does not constitute medical advice.
You should always have a personal consultation with a healthcare professional before making changes to your diet, medication, or exercise routine.
AI helps with the correspondence in our chat.
We participate in an affiliate program. If you buy something through a link, we may earn a commission 💕
↑