Site Notice
hello, world
Difference between revisions of "User:机智的小鱼君/common.js"
From Project-EPB Commons
([InPageEdit] 没有编辑摘要) |
([InPageEdit] 没有编辑摘要) |
||
Line 26: | Line 26: | ||
}).done(function(data){ | }).done(function(data){ | ||
var wikitext = data.parse.text['*'], | var wikitext = data.parse.text['*'], | ||
− | arr = wikitext.find('pre#randomBgList').split('\n'); | + | arr = $(wikitext).find('pre#randomBgList').split('\n'); |
$('#firstHeading').after( | $('#firstHeading').after( | ||
$('<span>').text(getArrItem(arr,1)) | $('<span>').text(getArrItem(arr,1)) |
Revision as of 17:13, 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(){
new mw.Api().get({
action: 'parse',
page: 'mediawiki:getArrItem',
prop: 'text',
dormat: 'json'
}).done(function(data){
var wikitext = data.parse.text['*'],
arr = $(wikitext).find('pre#randomBgList').split('\n');
$('#firstHeading').after(
$('<span>').text(getArrItem(arr,1))
);
});
});