MediaWiki:Gadget-Prosesize.js: Difference between revisions

Content deleted Content added
Only apply to the real text content output; this fixes duplicate instances of the stats being shown
Update to get data from prosesize toolforge tool - is more accurate
Line 104:
 
function main() {
var prosePromise, proseValue, refValue, refHtmlValue, proseHtmlValue;
// eslint-disable-next-line no-jquery/no-global-selector
var parserOutput = $( '#mw-content-text .mw-parser-output' );
Line 135:
parserOutput.children( 'p' ).removeClass( 'prosesize-highlight' );
} else {
// Use prosesize API to get a more accurate prose size account
// The calculations below are left in for the highlighting
prosePromise = $.getJSON( 'https://prosesize.toolforge.org/api/en.wikipedia.org/' + mw.config.get( 'wgPageName' ) );
 
// Calculate prose size and size of reference markers ([1] etc)
parserOutput.children( 'p' ).each( function () {
Line 150 ⟶ 154:
refSizeHtml = this.innerHTML.length;
} );
 
// Add the relevant outputs once we have fetched the prose size.
proseValue = sizeElement( 'prose-size', 'Prose size (text only):', proseSize - refmarksize, ' (' + wordCount + ' words) "readable prose size"' );
prosePromise.then( function( data ) {
refValue = sizeElement( 'ref-size', 'References (text only):', refSize + refmarksize );
proseSize = data.prose_size;
refHtmlValue = sizeElement( 'ref-size-html', 'References (including all HTML code):', refSizeHtml + refmarkSizeHtml );
wordCount = data.word_count;
proseHtmlValue = sizeElement( 'prose-size-html', 'Prose size (including all HTML code):', proseSizeHtml - refmarkSizeHtml );
proseValue = sizeElement( 'prose-size', 'Prose size (text only):', proseSize - refmarksize, ' (' + wordCount + ' words) "readable prose size"' );
output.append( proseHtmlValue, refHtmlValue, proseValue, refValue );
refValue = sizeElement( 'ref-size', 'References (text only):', refSize + refmarksize );
parserOutput.prepend( combined );
refHtmlValue = sizeElement( 'ref-size-html', 'References (including all HTML code):', refSizeHtml + refmarkSizeHtml );
getFileSize( proseHtmlValue );
proseHtmlValue = sizeElement( 'prose-size-html', 'Prose size (including all HTML code):', proseSizeHtml - refmarkSizeHtml );
getRevisionSize( proseValue );
output.append( proseHtmlValue, refHtmlValue, proseValue, refValue );
parserOutput.prepend( combined );
getFileSize( proseHtmlValue );
getRevisionSize( proseValue );
})
}
}