MediaWiki:RandomBackgroundList.js

/** * Random Background List **/ $(function { // Function get random arr  function getRandomArrayElements(arr, count) {    var shuffled = arr.slice(0),    i = arr.length,    min = i - count,    temp,    index;    while (i-->min) {      index = Math.floor((i + 1) * Math.random);      temp = shuffled[index];      shuffled[index] = shuffled[i];      shuffled[i] = temp;    }    return shuffled.slice(min);  }

// Function get list function randomBg { new mw.Api.get({     action: 'parse',      page: 'MediaWiki:Custom-random-background-list',      prop: 'wikitext',      format: 'json'    }).done(function(data) {      var wikitext = data.parse.wikitext['*'],      json = JSON.parse(wikitext),      item = getRandomArrayElements(json.list, 1),      img = item[0].img,      des = item[0].des;

$('body.skin-oasis').css({       'background-image': 'url(' + img + ')'      });

if ($('.background-license-description').length === 0) { $('.license-description').append(         $(' ',{ 'class': 'background-license-description' })       );      }      if (des !== undefined) { $('.background-license-description').text(des); } else { $('.background-license-description').text(''); }

}); }  // Do random when page load  randomBg;

// Add button function init(i18n) { $('.wds-community-header__local-navigation .wds-tabs').append(     $('',{'class':'wds-tabs__tab'}).append( $(' ',{'class':'wds-tabs__tab-label'}).append(         $(' ',{ 'src': 'https://vignette.wikia.nocookie.net/no-game-no-life/images/7/70/Random.png/revision/latest?cb=20190616113051&format=original&path-prefix=zh', 'style': 'width:12px;height:12px;' }),         $('',{ 'src': 'javascript:;', 'id': 'RandomBg' })         .text(i18n.msg('RandomBackground').escape)          .click(randomBg)        ) )   );  }  mw.hook('dev.i18n').add(function(i18no) {    i18no.loadMessages('RandomBackgroundList').then(init);  }); importArticle({   type: 'script',    article: 'u:dev:MediaWiki:I18n-js/code.js'  }); });