昨天我发了个贴子说抽奖中了一台mac不知道干啥
这个东西我礼拜天去镇江的金山寺拜了个佛 晚上刚到家随便进了个直播间就中了
放家里真不知干啥,还不如抽了送给大家,把幸运传递下去
5.12号开奖吧,尽快送出去!
我看人也不少了,大家刷屏的话也是图个热闹,抽奖也会剔除重复楼层的,
还有就是记得点赞!!! 你别到时候没点赞我可就重新抽了!! 我要个点赞不过分把
提前说明邮费到付!!
抽奖到时候就用论坛佬友发的js抽奖工具!!!!
如果大家有什么更好的抽奖方式跟工具也可以说!做到公平公正
到时候开奖之后我会私聊你,并且公示出来,中奖的佬友到时候收到货之后希望也可以发个帖子证明一下确实收到了 省的到时候有人说我忽悠人哈
请勿频繁重复发帖!! 如果抽中始皇那肯定是黑幕了
忘了说了这个设备没有线。到时候记得自己淘宝几块钱买一根.
我是几万分之一中的 , 你们几百分之一,总该中奖了把
抽奖代码在这里,大家可以看看还有什么问题
async function fetchAndDrawLottery() {
// 获取当前页面的 URL
const currentUrl = new URL(window.location.href);
// 获取帖子 ID
const postId = currentUrl.pathname.match(/\/t\/topic\/(\d+)/)[1];
// 构建帖子 JSON 数据的 URL
const postJsonUrl = `/t/${postId}.json`;
try {
// 获取帖子 JSON 数据
const response = await fetch(postJsonUrl);
const data = await response.json();
// 检查帖子数据是否有效
if (!data || !data.post_stream || !data.post_stream.stream) {
console.error("无效的帖子数据!");
return;
}
// 创建数组用于记录每个用户的 ID 和权重
const userWeights = [];
// 填充用户权重数组
data.post_stream.stream.forEach(post => {
const userId = post.user_id;
const userWeight = userWeights.find(u => u.userId === userId);
if (!userWeight) {
userWeights.push({ userId, weight: 1 });
} else {
userWeight.weight++;
}
});
// 计算总权重
const totalWeight = userWeights.reduce((total, user) => total + user.weight, 0);
// 随机选择一个用户
let randomWeight = Math.floor(Math.random() * totalWeight);
let selectedUserId;
userWeights.some(user => {
if (randomWeight < user.weight) {
selectedUserId = user.userId;
return true;
}
randomWeight -= user.weight;
return false;
});
// 获取该用户的楼层列表
const userFloors = data.post_stream.stream
.filter(post => post.user_id === selectedUserId)
.map((post, index) => index + 1);
// 从该用户的楼层列表中随机选择一个楼层
const randomFloor = userFloors[Math.floor(Math.random() * userFloors.length)];
// 构建跳转 URL
const jumpUrl = currentUrl.origin + `/t/topic/${postId}/${randomFloor}`;
// 跳转到指定楼层
window.location.href = jumpUrl;
} catch (error) {
console.error("抽奖过程中出现错误:", error);
}
}
// 调用抽奖函数
fetchAndDrawLottery();
一开始我看错了,没点赞,重新抽
这一次抽了第一个也没点赞,继续抽第二个,抽奖过程如下