MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第19行: | 第19行: | ||
/* 随机选择背景 */ | /* 随机选择背景 */ | ||
var bg_links = ['url(https://i.loli.net/2020/01/19/31GwqBplCKDaMHW.jpg)', 'url(https://i.loli.net/2020/01/19/PpvFBOdT8DArt47.jpg)', "url(https://i.loli.net/2020/09/27/h86Nc4AIsmLb1Vi.jpg)", "url(https://i.loli.net/2021/09/23/LIqwG9c5xDQCY4Z.jpg)", "url(https://s2.loli.net/2022/11/06/XSB5YxF3ao2f7ZT.jpg)"]; | // var bg_links = ['url(https://i.loli.net/2020/01/19/31GwqBplCKDaMHW.jpg)', 'url(https://i.loli.net/2020/01/19/PpvFBOdT8DArt47.jpg)', "url(https://i.loli.net/2020/09/27/h86Nc4AIsmLb1Vi.jpg)", "url(https://i.loli.net/2021/09/23/LIqwG9c5xDQCY4Z.jpg)", "url(https://s2.loli.net/2022/11/06/XSB5YxF3ao2f7ZT.jpg)"]; | ||
$('body.skin-vector').css('background', | function weightedRandomSelection(items) { | ||
// Calculate the total weight of all items. | |||
const totalWeight = items.reduce((sum, [item, weight]) => sum + weight, 0); | |||
// Generate a random value between 0 and the total weight. | |||
const randomValue = Math.random() * totalWeight; | |||
// Iterate over the items, keeping track of the current weight. | |||
let currentWeight = 0; | |||
for (const [item, weight] of items) { | |||
currentWeight += weight; | |||
// If the current weight is greater than or equal to the random value, return the item. | |||
if (currentWeight >= randomValue) { | |||
return item; | |||
} | |||
} | |||
} | |||
const bg_links = [ | |||
('url(https://0v0.zjsnrwiki.com/static/bg_4.webp)', 0.16), | |||
('url(https://0v0.zjsnrwiki.com/static/bg_5.webp)', 0.16), | |||
('url(https://0v0.zjsnrwiki.com/static/bg_6.webp)', 0.16), | |||
('url(https://0v0.zjsnrwiki.com/static/bg_7.webp)', 0.16), | |||
('url(https://0v0.zjsnrwiki.com/static/bg_8a.webp)', 0.16), | |||
('url(https://0v0.zjsnrwiki.com/static/bg_8b.webp)', 0.16), | |||
]; | |||
const random_bg_link = weightedRandomSelection(bg_links); | |||
console.log(random_bg_link); | |||
$('body.skin-vector').css('background',random_bg_link[0]); | |||
$('body.skin-vector').css('background-position', 'centre'); | $('body.skin-vector').css('background-position', 'centre'); | ||
$('body.skin-vector').css('background-repeat', 'no-repeat'); | $('body.skin-vector').css('background-repeat', 'no-repeat'); | ||
| 第26行: | 第55行: | ||
$('body.skin-vector').css('background-attachment', 'fixed'); | $('body.skin-vector').css('background-attachment', 'fixed'); | ||
$('body.skin-citizen').css('background', | $('body.skin-citizen').css('background', random_bg_link[0]); | ||
$('body.skin-citizen').css('background-position', 'centre'); | $('body.skin-citizen').css('background-position', 'centre'); | ||
$('body.skin-citizen').css('background-repeat', 'no-repeat'); | $('body.skin-citizen').css('background-repeat', 'no-repeat'); | ||