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"); //     } //   }); // } //   ); // });

mw.loader.using( 'oojs-ui-core' ).done( function {    var Query = function ( config ) {			config = config || {};      // Call parent constructor      Query.parent.call( this, config );      this.button1 = new OO.ui.ButtonWidget( { label: 'Most viewed pages', } );     this.button2 = new OO.ui.ButtonWidget( { label: 'Check your IP', } );     this.result = new OO.ui.LabelWidget( { classes: [ 'result' ] } );     this.button1.connect( this, { click: 'onClickButton1' } );			this.button2.connect( this, { click: 'onClickButton2' } );      this.$element.append( this.button1.$element .css( { margin: '5px 0 20px 0' } ), this.button2.$element .css( { margin: '5px 0 20px 0' } ) );		};   OO.inheritClass( Query, OO.ui.Widget );    Query.prototype.onClickButton1 = function  {      this.button2.setDisabled( true );      var str = '';      var url = 'https://en.wikipedia.org/w/api.php';				var params = {					action: 'query',        			format: 'json',					prop: 'pageviews',        			generator: 'mostviewed',        			pvipdays: '1',        			gpvimlimit: '5',    			 };				url = url + '?origin=*';				Object.keys( params ).forEach( function ( key ) { url += '&' + key + '=' + params[ key ]; } );       fetch( url )					.then( function ( data ) { return response.json; } )       	.then( function ( data ) { var pages = data.query.pages; for( var page in pages ){ str += pages[ page ].title + '\n'; }           result.setLable( str ); } )         .catch( function ( error ) { console.log( error ); } );   };    var queryWidget = new Query;    var myPopUpButton = new OO.ui.PopupButtonWidget( { label: 'Query', popup: { $content: queryWidget.$element, padded: true }		} );	$( '#bodyContent' ).append( myPopUpButton.$element );	    } );