Advertisement
Guest User

抽奖代码

a guest
Dec 13th, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 从页面提取参与用户的函数
  2. function getValidUsers() {
  3.   // 获取所有回复
  4.   const replies = document.querySelectorAll('.cell[id^="r_"]');
  5.  
  6.   // 存储有效用户(剔除重复用户和楼主)
  7.   const validUsers = new Map();
  8.   const op = 'yuzo555';
  9.  
  10.   replies.forEach(reply => {
  11.     const username = reply.querySelector('strong a').textContent;
  12.     if(username !== op && !validUsers.has(username)) {
  13.       validUsers.set(username, true);
  14.     }
  15.   });
  16.  
  17.   return Array.from(validUsers.keys());
  18. }
  19.  
  20. // 抽奖函数
  21. function drawLuckyUsers(seeds) {
  22.   let users = getValidUsers();
  23.   const winners = [];
  24.  
  25.   // 使用每个种子抽取一位获奖者
  26.   seeds.forEach(seed => {
  27.     if(users.length === 0) return;
  28.    
  29.     // 用种子除以当前用户数取余
  30.     const winnerIndex = seed % users.length;
  31.     winners.push(users[winnerIndex]);
  32.    
  33.     // 移除已中奖用户,重新计算序号
  34.     users = users.filter((_, index) => index !== winnerIndex);
  35.   });
  36.  
  37.   return winners;
  38. }
  39.  
  40. // 执行抽奖
  41. const seeds = [340253, 1073166, 342266, 1081258, 343249, 1084842, 346150, 1095713, 339188, 1071307];
  42. const winners = drawLuckyUsers(seeds);
  43. console.log('中奖用户:', winners);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement