打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

舰R百科是靠无数志愿编辑者持续地建设更新完善的。编辑非常简单,无需代码知识,请勇于更新页面!
编辑入门 | 资助百科 | 留言讨论页 | 微博@舰R百科 | 百科编辑讨论Q群:366818861

MediaWiki:Common.js:修订间差异

MediaWiki界面页面
Donnyjie留言 | 贡献
无编辑摘要
无编辑摘要
第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', bg_links[Math.floor(Math.random()*bg_links.length)]);
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', bg_links[Math.floor(Math.random()*bg_links.length)]);
$('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');