Site Notice

hello, world

Difference between revisions of "User:机智的小鱼君/common.js"

From Project-EPB Commons
([InPageEdit] 没有编辑摘要)
([InPageEdit] 没有编辑摘要)
Line 30: Line 30:
 
     arr = arr.split('\n\*RandomBackgroundImg\*');
 
     arr = arr.split('\n\*RandomBackgroundImg\*');
 
   
 
   
     $('body.skin-oasis').css({
+
     $('#firstHeading').after('url('+arr+')');
      'background-image': 'url('+arr+')'
 
    });
 
 
   
 
   
 
   });
 
   });

Revision as of 17:58, 6 November 2019

mw.loader.load('https://common.wjghj.cn/js/InPageEdit-v2');

function getArrItem(arr, num) {
  var temp_array = new Array();
  for (var index in arr) {
    temp_array.push(arr[index]);
  }
  var return_array = new Array();
  for (var i = 0; i < num; i++) {
    if (temp_array.length > 0) {
      var arrIndex = Math.floor(Math.random() * temp_array.length);
      return_array[i] = temp_array[arrIndex];
      temp_array.splice(arrIndex, 1);
    } else {
      break;
    }
  }
  return return_array;
}
function randomBg() {
  new mw.Api().get({
    action: 'parse',
    page: 'MediaWiki:Custom-RandomBackground/List',
    prop: 'wikitext',
    format: 'json'
  }).done(function(data) {
    var wikitext = data.parse.wikitext['*'],
    arr = wikitext.split('\n\#RandomBackgroundList\#');
    delete arr[0];
    arr = arr.split('\n\*RandomBackgroundImg\*');
 
    $('#firstHeading').after('url('+arr+')');
 
  });
}
$(function(){
randomBg();
new mw.Api().get({
  action: 'query',
  meta: 'allmessages',
  ammessages: 'Custom-RandomBackground',
  amlang: mw.config.get('wgUserLanguage') || 'zh'
}).done(function(data) {
  var RandomBgMsg = data.query.allmessages[0]['*'];
  $('.wds-community-header__local-navigation .wds-tabs').append($('<li>').addClass('wds-tabs__tab').append($('<div>').addClass('wds-tabs__tab-label').append($('<a>').attr({
    'src': '#',
    'id': 'RandomBg'
  }).text(RandomBgMsg).prepend('<img 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;"/>&nbsp;').click(RandomBg))));
});
});