Site Notice

hello, world

User:机智的小鱼君/common.js

From Project-EPB Commons
< User:机智的小鱼君
Revision as of 12:33, 8 November 2019 by 机智的小鱼君 (talk | contribs) ([InPageEdit] 没有编辑摘要)


Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
mw.loader.load('https://common.wjghj.cn/js/InPageEdit-v2');


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 randomBg() {
  new mw.Api().get({
    action: 'parse',
    page: 'MediaWiki:Custom-RandomBackground/List',
    prop: 'wikitext',
    format: 'json'
  }).done(function(data) {
    var wikitext = data.parse.wikitext['*'],
    json = JSON.parse(wikitext),
    item = getRandomArrayElements(json.list,1),
    // item = json.list[0],
    img = item[0].img,
    des = item[0].des;
 
    $('#firstHeading').after('<br>arr: '+ JSON.stringify(item) +'<br>image url: url(' + img + ')<br>Description: '+des);
 
  });
}
$(function(){
randomBg();
$('#firstHeading').click(randomBg)
});