Site Notice
hello, world
User:机智的小鱼君/common.js
From Project-EPB Commons
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 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\#');
arr = arr[1].split('\*RandomBackgroundImg\*');
delete arr[0];
$('#firstHeading').after('url(' + getArrItem(arr,1) + ')');
});
}
$(function(){
randomBg();
$('#firstHeading').click(randomBg)
});