Jump to content

User:קיפודנחש/viewstats.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
mw.loader.using( 'mediawiki.util' ).done( function() {
$( mw.util.addPortletLink( 'p-cactions', "#", 'View statistics' ) )
.click( function() {
	mw.loader.using( ['mediawiki.api', 'jquery.ui' ], function() {
		var api = new mw.Api(),
		pageName = mw.config.get( 'wgPageName' );
	api.get( { 
			action: 'parse', 
			text: '{{PageViews graph | 60 | ' + pageName + '}}',
			pst: 1
			} 
		)
		.done( function( data ) {
			if ( data && data.parse && data.parse.text && data.parse.text['*'] ) {
				var content = data.parse.text['*'];
				$( '<div>' )
					.dialog( { 
						title: 'Page view statistics',
						width: 'auto', 
						height: 'auto',
						position: [$('body').width() * 0.2, $('body').height() * 0.1]
					} )
					.append( content );
			}
		} );
	} );
} );
} );