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 str = "", 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( { margin: '5px 5px 5px 5px' } ),				this.button2.$element					.css( { margin: '5px 5px 5px 5px' } )			); };

OO.inheritClass( Query, OO.ui.Widget ); //1111111111111111111111111111111111111111111111111111111111111111   Query.prototype.btnClick1 = function  { count1 = 1; if ( count1 === 1 ) { this.button2.setDisabled( true );

var url = 'https://en.wikipedia.org/w/api.php';

var params = { action: 'query', prop: 'revisions', titles: mw.config.get('wgPageName'), rprop: 'user', rvlimit: '1', format: 'json' };

url = url + '?origin=*'; Object.keys( params ).forEach( function ( key ) {					url += '&' + key + '=' + params[ key ];				} ); var urlfirst = url + '&rvdir=older'; var urllast = url + '&rvdir=newer'; fetch( url ) .then( function ( response ) {						return response.json;					} ) .then( function ( response ) {					str =" ";					for (var page in response.query.pages) {						for (var revision in response.query.pages[page].revisions) {							 str += response.query.pages[page].revisions[revision].user ;								 }							}					} ) .catch( function ( error ) {						console.log( error );					} );

this.result1 = new OO.ui.LabelWidget( {					label : new OO.ui.HtmlSnippet( str ),					classes: [ 'result1' ]				} );

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

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

this.$element.append(					this.result1.$element						.css( { display: 'block', margin: '10px 0', padding: '15px', backgroundColor: '#addfad', borderRadius: '10px' } ),					this.backButton.$element				); }		};

//2222222222222222222222222222222222222222222222222222222		Query.prototype.btnClick2 = function { count2=1; if ( count2 ===1 ) { this.button1.setDisabled( true ); var url = 'https://en.wikipedia.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;					    str = ;					     var title =;						// str = "new OO.ui.HtmlSnippet('"; for ( var page in pages ) { title = pages[ page ].title; str += ""+title+""+' :  '+pages[ page ].count + " "; }						// str+="')";						// queryWidget.result.setLabelElement( str );					} ) .catch( function ( error ) {						console.log( error );					} );

this.result2 = new OO.ui.LabelWidget( {					label: new OO.ui.HtmlSnippet( str ),					classes: [ 'result2' ]				} );

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

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

this.$element.append(					this.result2.$element						.css( { display: 'block', margin: '10px 0', padding: '15px', backgroundColor: '#addfad', borderRadius: '10px' } ),					this.backButton.$element				); }		};

// Defines the action/behaviour when the back button is clicked. Query.prototype.backBtnClick = function { this.button1.setDisabled( false ); this.button2.setDisabled( false );

$( '.result1' ).remove; $( '.result2' ).remove; $( '.backBtn' ).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 ) ); } ); } );