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

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

MediaWiki:Common.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
第22行: 第22行:
function weightedRandomSelection(items) {
function weightedRandomSelection(items) {
   // Calculate the total weight of all items.
   // Calculate the total weight of all items.
   const totalWeight = items.reduce((sum, [item, weight]) => sum + weight, 0);
   var totalWeight = 0;
  for (var i = 0; i < items.length; i++) {
    totalWeight += items[i][1];
  }


   // Generate a random value between 0 and the total weight.
   // Generate a random value between 0 and the total weight.
   const randomValue = Math.random() * totalWeight;
   var randomValue = Math.random() * totalWeight;


   // Iterate over the items, keeping track of the current weight.
   // Iterate over the items, keeping track of the current weight.
   let currentWeight = 0;
   var currentWeight = 0;
   for (const [item, weight] of items) {
   for (i = 0; i < items.length; i++) {
     currentWeight += weight;
     currentWeight += items[i][1];


     // If the current weight is greater than or equal to the random value, return the item.
     // If the current weight is greater than or equal to the random value, return the item.
     if (currentWeight >= randomValue) {
     if (currentWeight >= randomValue) {
       return item;
       return items[i][0];
     }
     }
   }
   }
  // If we reach here, it means that the random value was greater than the total weight, which should never happen.
  throw new Error("Random value was greater than total weight.");
}
}


const bg_links = [
var bg_links = [
   ('url(https://0v0.zjsnrwiki.com/static/bg_4.webp)', 0.16),
   ('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_5.webp)', 0.16),
第47行: 第53行:
   ('url(https://0v0.zjsnrwiki.com/static/bg_8b.webp)', 0.16),
   ('url(https://0v0.zjsnrwiki.com/static/bg_8b.webp)', 0.16),
];
];
const random_bg_link = weightedRandomSelection(bg_links);
var random_bg_link = weightedRandomSelection(bg_links);
console.log(random_bg_link);
console.log(random_bg_link);
$('body.skin-vector').css('background',random_bg_link[0]);
$('body.skin-vector').css('background',random_bg_link[0]);