Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 从页面提取参与用户的函数
- function getValidUsers() {
- // 获取所有回复
- const replies = document.querySelectorAll('.cell[id^="r_"]');
- // 存储有效用户(剔除重复用户和楼主)
- const validUsers = new Map();
- const op = 'yuzo555';
- replies.forEach(reply => {
- const username = reply.querySelector('strong a').textContent;
- if(username !== op && !validUsers.has(username)) {
- validUsers.set(username, true);
- }
- });
- return Array.from(validUsers.keys());
- }
- // 抽奖函数
- function drawLuckyUsers(seeds) {
- let users = getValidUsers();
- const winners = [];
- // 使用每个种子抽取一位获奖者
- seeds.forEach(seed => {
- if(users.length === 0) return;
- // 用种子除以当前用户数取余
- const winnerIndex = seed % users.length;
- winners.push(users[winnerIndex]);
- // 移除已中奖用户,重新计算序号
- users = users.filter((_, index) => index !== winnerIndex);
- });
- return winners;
- }
- // 执行抽奖
- const seeds = [340253, 1073166, 342266, 1081258, 343249, 1084842, 346150, 1095713, 339188, 1071307];
- const winners = drawLuckyUsers(seeds);
- console.log('中奖用户:', winners);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement