Difference between revisions of "MediaWiki:Common.js"

From Life After BOB Wiki
Jump to navigation Jump to search
Line 2: Line 2:
  
 
//open external links in new tab
 
//open external links in new tab
$( function () {
+
 
$( '.external free' ).on( 'click', function () {
+
$( '.external free' ).on( 'click', 'a', function (e) {
var otherWindow = window.open();
+
    e.preventDefault();
otherWindow.opener = null;
+
    var url = $(this a).attr('href');  
otherWindow.location = this;
+
    console.log(url);
return false;
+
    window.open(url, '_blank');
 
} );
 
} );
} );
+
 
  
 
mw.loader.using( 'mediawiki.api', function () {  
 
mw.loader.using( 'mediawiki.api', function () {  

Revision as of 14:15, 9 June 2021

/* Any JavaScript here will be loaded for all users on every page load. */

//open external links in new tab

$( '.external free' ).on( 'click', 'a', function (e) {
    e.preventDefault(); 
    var url = $(this a).attr('href'); 
    console.log(url);
    window.open(url, '_blank');
	} );


mw.loader.using( 'mediawiki.api', function () { 
var params = {
		action: 'query',
		format: 'json',
		list: 'random',
		rnlimit: '1',
                rnnamespace:'0'
	},
	api = new mw.Api();

api.get( params ).done( function ( data ) {
	var randoms = data.query.random,
		r;
	for ( r in randoms ) {
		console.log( randoms[ r ].title);
	}
        var randomString = "<a href='http://lifeafterbob.wiki/view/"+randoms[0].title+"'>"+randoms[0].title+"</a>"
        console.log(randomString);
        $("#randompage").append(randomString);


} );


} )