User:A. Amritesh/common.js

// importScript('User:SSethi (WMF)/Sandbox/SimpleUserScriptExamples.js'); // mw.loader.using( 'oojs-ui-widgets' ).done(function{ // var buttonIcon = new OO.ui.ButtonWidget( { // 	icon: 'upTriangle', // 	title: 'Up', // 	classes:[ 'my-button'] // } );   // $( '#mw-content-text' ).after(buttonIcon.$element ); // // buttonIcon.setIcon( 'upTriangle' ); // $('.my-button').css('float','right'); // $('.my-button').css('padding','0.5em 0em'); // buttonIcon.on('click', function{$(window).scrollTop(0);}); // // .onClick(document.getElementById(firstHeading).focus({preventScroll:false})) // }); // mw.loader.using( 'oojs-ui-widgets' ).done(function{ // var toggleSwitch = new OO.ui.PopupButtonWidget({ // 	label: 'Dark Focus', // 	classes:[ 'my-togglebtn'], // 	popup: { // 		$content: $( ' Reload to disable. ' ), // 		padded: true, // 		align: 'forwards' // 	} // });

// $('#bodyContent').prepend( toggleSwitch.$element ); // $('.my-togglebtn').css('float','right'); // $('.my-togglebtn').css('padding','0.5em 0em'); // toggleSwitch.on('click',function focus{ // 	$('.my-togglebtn').css('background-color','black'); // 	$('.my-togglebtn').css('color','white'); // 	$("p").on({ //  mouseenter: function{ //    $(this).css("background-color", "black"); //    $(this).css("color", "white"); //  }, //   mouseleave: function{ //    $(this).css("background-color", "white"); //    $(this).css("color", "black"); //    } // 	});

// $("pre,code,table").on({ //  mouseenter: function{ //     $(this).css("background-color", "black"); //     $(this).css("color", "white"); //   }, //   mouseleave: function{ //     $(this).css("background-color", "#f8f9fa"); //     $(this).css("color", "black"); //     } //   }); // } //   ); // });

$( document ).ready( function {	mw.loader.using( 'oojs-ui-core' ).done( function  { var str1 = '', str2 = '', count1 = 0, count2 = 0;

var Query = function ( config ) { config = config || {};

Query.parent.call( this, config );

this.button1 = new OO.ui.ButtonWidget( {				label: ' Editors ',			} );

this.button2 = new OO.ui.ButtonWidget( {				label: ' Mostviewed Pages ',			} );

this.button1.connect( this, { click: 'btnClick1' } ); this.button2.connect( this, { click: 'btnClick2' } );

this.$element.append(				this.button1.$element					.css( { padding: '5px 5px', margin: '5px 18px' }),				this.button2.$element					.css( { padding: '5px 5px', margin: '5px 18px' })			); };

OO.inheritClass( Query, OO.ui.Widget ); //1111111111111111111111111111111111111111111111111111111111111111   	Query.prototype.btnClick1 = function  { count1++; if ( count1 == 1 ) { this.button2.setDisabled( true ); var url = 'https://www.mediawiki.org/w/api.php'; var params = { action: 'query', prop: 'revisions', titles: mw.config.get( "wgPageName" ), rprop: 'user', rvlimit: '1', rvslots: "main", format: 'json', formatversion: '2' };

url = url + '?origin=*'; Object.keys( params ).forEach( function ( key ) {					url += '&' + key + '=' + params[ key ];				} ); var urllast = url + '&rvdir=older'; var urlfirst = url + '&rvdir=newer'; fetch( urlfirst ) .then( function ( response ) {						return response.json;					} ) .then( function ( response ) {						str1 = 'First Editor : ';						for ( var page in response.query.pages ) {							for ( var rev in response.query.pages[page].revisions ) {								var user = response.query.pages[page].revisions[rev].user;								str1 += "" + user + "" + " ";							}						}					} ) .catch( function ( error ) {						console.log( error );					} ); fetch( urllast ) .then( function ( response ) {						return response.json;					} ) .then( function ( response ) {						str1 +='Last Editor : ';						for ( var page in response.query.pages ) {							for ( var rev in response.query.pages[page].revisions ) {									var user = response.query.pages[page].revisions[rev].user;									str1 += "" + user + "";							}						}					} ) .catch( function ( error ) {						console.log( error );					} ); if(str1 == '' ){ str1 = 'Please try again.'; }				this.result = new OO.ui.LabelWidget( {					label : new OO.ui.HtmlSnippet( str1 ),					classes: [ 'result' ]				} );

this.backButton = new OO.ui.ButtonWidget( {					label: 'Back...',					classes: [ 'back' ]				} );

this.backButton.connect( this, { click: 'backClick' } );

this.$element.append(					this.result.$element						.css( { display: 'block', border: '1px solid', backgroundColor: '#eaecf0', margin: '10px 0', padding: '15px' } ),					this.backButton.$element				); }		};

//2222222222222222222222222222222222222222222222222222222		Query.prototype.btnClick2 = function { count2++; if ( count2 == 1 ) { this.button1.setDisabled( true ); var url = 'https://www.mediawiki.org/w/api.php'; // 				var params = { action: 'query', list: 'mostviewed', pvimlimit: '5', pvimmetric: 'pageviews', format: 'json' };

url = url + '?origin=*'; Object.keys( params ).forEach( function ( key ) {					url += '&' + key + '=' + params[ key ];				} );

fetch( url ) .then( function ( response ) {						return response.json;					} ) .then( function ( response ) {						var pages = response.query.mostviewed;					   str2 = ;					    var title =;						for ( var page in pages ) {							title = pages[ page ].title;            				str2 += "" +             					title + "" + '  :  ' + pages[ page ].count + " ";						}					} ) .catch( function ( error ) {						console.log( error );					} ); if(str2 == '' ){ str2 = 'Please try again.'; }				this.result = new OO.ui.LabelWidget( {					label: new OO.ui.HtmlSnippet( str2 ),					classes: [ 'result' ]				} ); this.backButton = new OO.ui.ButtonWidget( {					label: 'Back...',					classes: [ 'back' ]				} );

this.backButton.connect( this, { click: 'backClick' } );

this.$element.append(					this.result.$element						.css( { display: 'block', border: '1px solid', backgroundColor: '#eaecf0', margin: '10px 0', padding: '15px' } ),					this.backButton.$element				); }		};

// Defines the action/behaviour when the back button is clicked. Query.prototype.backClick = function { this.button1.setDisabled( false ); this.button2.setDisabled( false ); $( '.result' ).remove; $( '.back' ).remove; count1 = 0; count2 = 0; };

// The following creates a custom widget and a pop up button object. var queryWidget = new Query;

var myPopUpButton = new OO.ui.PopupButtonWidget( {			label: 'Query',			popup: {				$content: queryWidget.$element,				padded: true			}		} );

// Shows the pop up button on the personal navigation bar of the user at the // Top right corner. $( '#p-personal ul' ) .prepend( $( '' ).append( myPopUpButton.$element ) ); } ); } );