const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36';
async function handleRequest(tid, num, seedParam, maxFloor) {
if (!tid || isNaN(num)) {
console.error('请提供有效的帖子 ID 和抽奖人数');
return;
}
console.log(`Fetching OP for TID: ${tid}`);
const op = await getOp(tid);
console.log(`OP: ${op}`);
console.log(`Fetching all users for TID: ${tid}`);
const uniqueUserList = await getAllUser(tid, maxFloor);
console.log(`Unique Users: ${uniqueUserList.join(', ')}`);
const filteredUserList = uniqueUserList.filter(user => user !== op);
console.log(`Filtered Users: ${filteredUserList.join(', ')}`);
const userCount = filteredUserList.length;
console.log(`User Count: ${userCount}`);
const seed = seedParam !== null ? seedParam : userCount.toString();
console.log(`Seed: ${seed}`);
console.log(`Max Floor: ${maxFloor}`);
const combinedSeed = `${seed}-${maxFloor}`;
console.log(`Combined Seed: ${combinedSeed}`);
const shuffledList = shuffle(filteredUserList, combinedSeed);
console.log(`Shuffled Users: ${shuffledList.join(', ')}`);
const result = `符合条件的用户共有 ${filteredUserList.length} 人
抽奖结果:
${shuffledList.slice(0, num).join('\n')}`;
console.log(result);
}
async function getOp(tid) {
const url = `https://ex.noerr.eu.org/amp/t/${tid}`;
console.log(`Fetching OP URL: ${url}`);
const response = await fetch(url, { headers: { 'User-Agent': UA } });
if (!response.ok) {
console.log(`Failed to fetch OP: ${response.status} ${response.statusText}`);
return null;
}
const text = await response.text();
const match = /<div class="topic_author">[\s\S]*?<amp-img[^>]+alt="([^"]+)"[\s\S]*?<\/div>/.exec(text);
console.log(`OP Match: ${match ? match[1] : null}`);
return match ? match[1].trim() : null;
}
async function getUserList(url, startIndex, endIndex) {
console.log(`Fetching User List URL: ${url}`);
const response = await fetch(url, { headers: { 'User-Agent': UA } });
if (!response.ok) {
console.log(`Failed to fetch User List: ${response.status} ${response.statusText}`);
return [];
}
const text = await response.text();
const replyItemRegex = /<div class="reply_item">([\s\S]*?)<\/div>/g;
let replyItemMatch;
const users = [];
let currentIndex = startIndex || 0;
while ((replyItemMatch = replyItemRegex.exec(text)) !== null) {
if (endIndex !== undefined && currentIndex >= endIndex) {
break;
}
const replyItem = replyItemMatch[1];
const altRegex = /<amp-img[^>]+alt="([^"]+)"[^>]*>/g;
const altMatch = altRegex.exec(replyItem);
if (altMatch) {
users.push(altMatch[1]);
}
currentIndex++;
}
console.log(`Matches: ${users.join(', ')}`);
return users;
}
async function getAllPages(tid) {
const url = `https://ex.noerr.eu.org/amp/t/${tid}`;
console.log(`Fetching All Pages URL: ${url}`);
const response = await fetch(url, { headers: { 'User-Agent': UA } });
if (!response.ok) {
console.log(`Failed to fetch All Pages: ${response.status} ${response.statusText}`);
return [];
}
const text = await response.text();
const pageCountMatch = /\u5171 (\d+) \u9875/.exec(text);
const pageCount = pageCountMatch ? parseInt(pageCountMatch[1], 10) : 1;
console.log(`Page Count: ${pageCount}`);
const pages = [];
for (let i = 1; i <= pageCount; i++) {
pages.push(`${url}/${i}`);
}
return pages;
}
async function getAllUser(tid, maxFloor) {
const pages = await getAllPages(tid);
console.log(`Pages: ${pages.join(', ')}`);
let allUsers = [];
let currentFloor = 0;
for (let page of pages) {
const startIndex = currentFloor;
const endIndex = maxFloor !== undefined ? maxFloor : undefined;
const users = await getUserList(page, startIndex, endIndex);
allUsers = allUsers.concat(users);
currentFloor += users.length;
if (endIndex !== undefined && currentFloor >= endIndex) {
break;
}
}
const uniqueUsers = [];
const seen = new Set();
for (const user of allUsers) {
if (!seen.has(user)) {
uniqueUsers.push(user);
seen.add(user);
}
}
console.log(`Unique Users: ${uniqueUsers.join(', ')}`);
return uniqueUsers;
}
function shuffle(array, seed) {
const rng = lcg(seed);
console.log(`Shuffling with Seed: ${seed}`);
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(rng() * (i + 1));
console.log(`Shuffling: i=${i}, j=${j}`);
if (array[i] !== undefined && array[j] !== undefined) {
[array[i], array[j]] = [array[j], array[i]];
} else {
console.log(`Error: array[i] or array[j] is undefined. i=${i}, j=${j}, array[i]=${array[i]}, array[j]=${array[j]}`);
}
}
return array;
}
function lcg(seed) {
let state = hashCode(seed);
console.log(`LCG State: ${state}`);
const a = 1664525;
const c = 1013904223;
const m = Math.pow(2, 32);
return function() {
state = (a * state + c) % m;
console.log(`LCG Next: ${state / m}`);
return state / m;
}
}
function hashCode(str) {
l

et hash = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash |= 0;
}
return Math.abs(hash);
}
// Example usage:
handleRequest('123456', 3, seed123, 10);
这里的 '123456' 是帖子 ID ,3 是抽奖人数,'seed123' 是种子(可选),10 是最大楼层(可选)。
在 V2EX 网站里用浏览器 consele 运行就可以
为了方便 v 友进行类似抽奖我糊了一个 cloudflare work 来使用直接请求 https://v2ex.240801.xyz/?tid=12345&num=10&seed=12345&maxFloor=11(大佬别打,刚装上访问不了可能 cf 路由没设置好)这里的参数说明为 tid 为帖子 id num 为中奖人数 seed 为随机数种子 maxFloor 为最高楼层

ps 甜度不用担心,今年我们县的都甜。现摘现发没有清洗打腊,只要老家不下雨一般下单第二天就发货。室温 20 度以内还是很耐放的两三个星期没啥问题。有个卖橙子的微信群想加的加我微信 console.log(atob('enF3MjAwOA=='))拉群
为啥这次的代码块没有高亮。。。代码看起来多,是因为ai 写的取回复用户数没用v站的api,下面是去除相关爬虫代码后的代码:https://gist.github.com/zzerding/d80d25149a74c0dd96516d949e9e52b7
好了不摸鱼了领导催进度了
看到515楼我知道这个正则表达式取用户非常不可靠(但是当前代码好像没有注入成功),所以改用v2ex api。 使用方式
201
sds7ss 2024-11-22 10:41:55 +08:00
分母+1
|
202
flyation 2024-11-22 10:42:09 +08:00
碰运气!
|
203
cyhulk 2024-11-22 10:42:43 +08:00
必须分子
|
205
pridealloverme 2024-11-22 10:43:58 +08:00
争取分子
|
206
Aeolusire 2024-11-22 10:46:34 +08:00
碰碰运气
|
207
yangmabi 2024-11-22 10:47:30 +08:00
分母
|
208
xiaoxixi 2024-11-22 10:48:26 +08:00
我分母一下
|
209
vipfts 2024-11-22 10:48:43 +08:00
|
210
zhengxiexie2 2024-11-22 10:48:49 +08:00
分母+1
|
211
weirking 2024-11-22 10:50:05 +08:00
重在参与!
|
212
kangwei 2024-11-22 10:50:21 +08:00
重在参与
|
213
AkiseAru 2024-11-22 10:51:33 +08:00
非常好橙子
|
214
huan90s 2024-11-22 10:53:21 +08:00
分母,中不了就买一箱
|
215
jyootai 2024-11-22 10:53:54 +08:00
分子来了
|
216
delonglimin 2024-11-22 10:54:53 +08:00
我一定会吃上
|
217
codersun123 2024-11-22 10:55:46 +08:00
我爱 VC
|
218
sjqmmd 2024-11-22 10:56:01 +08:00
重在参与!
|
219
lessMonologue 2024-11-22 10:56:27 +08:00
支持一下!
|
220
codingbody 2024-11-22 10:56:31 +08:00
参与一下
|
221
tracyliu 2024-11-22 10:57:15 +08:00
做个分母 重在参与
|
222
czkm1320 2024-11-22 10:58:18 +08:00
分母哈哈
|
223
yansideyu 2024-11-22 10:59:35 +08:00
万一中了呢
|
224
Regened 2024-11-22 11:00:38 +08:00
成为分母
|
225
annet 2024-11-22 11:01:03 +08:00
重在参与!
|
226
COW 2024-11-22 11:01:14 +08:00 via Android
参与下
|
227
dreampet 2024-11-22 11:01:16 +08:00
分母+1
|
228
zhangpulin 2024-11-22 11:02:14 +08:00
分母还是分子
|
229
lixiaobai913 2024-11-22 11:03:18 +08:00
尝试中奖 体会 v 友的开心
|
230
geeppeng233 2024-11-22 11:03:36 +08:00
已经买了一箱了,这个再支持一下
|
231
wangzh 2024-11-22 11:04:53 +08:00
已下单
|
232
zhaolin191544 2024-11-22 11:05:34 +08:00
参与一下
|
233
mscsky 2024-11-22 11:06:25 +08:00
还能参加吗
|
234
HMYQ 2024-11-22 11:06:40 +08:00 via Android
成为分母
|
235
9527000 2024-11-22 11:07:32 +08:00
参与
|
236
AchieveHF 2024-11-22 11:10:15 +08:00
有果冻橙吗
|
237
bey0nd 2024-11-22 11:12:44 +08:00
后排
|
238
huxKKK 2024-11-22 11:13:33 +08:00
踊跃参与!
|
239
zard999 2024-11-22 11:16:03 +08:00
重在参与
|
240
kingwang 2024-11-22 11:19:36 +08:00
重在参与
|
241
rangerxo 2024-11-22 11:19:54 +08:00
先来一箱试试口感
|
242
xdlailai 2024-11-22 11:20:27 +08:00
参与下
|
243
jasmineJo 2024-11-22 11:20:39 +08:00
重在参与!
|
244
CoCoCorina 2024-11-22 11:21:02 +08:00
try
|
245
wyshp 2024-11-22 11:21:59 +08:00
重在参与,祝橙子大卖,财源滚滚来~
|
246
qhx1018 2024-11-22 11:22:38 +08:00
做个分母
|
247
suilin 2024-11-22 11:26:54 +08:00
参与
|
248
Zz09 2024-11-22 11:27:15 +08:00
分母+1
|
249
2Inception 2024-11-22 11:27:58 +08:00
参与一下,需要补点维 C
|
250
hulalalla 2024-11-22 11:29:01 +08:00
做个分母
|
251
AmItheRobot 2024-11-22 11:29:53 +08:00
来个分母
|
252
axo 2024-11-22 11:30:08 +08:00
分母分母
|
253
h1t 2024-11-22 11:30:09 +08:00
分母+1
|
254
lada05 2024-11-22 11:30:22 +08:00
严谨啊
|
255
renyijiu 2024-11-22 11:30:39 +08:00
支持一下
|
256
5ibug 2024-11-22 11:30:55 +08:00
分母
|
257
shl1n 2024-11-22 11:31:25 +08:00
股市失意,v 站得意。
|
258
sparkssssssss 2024-11-22 11:32:29 +08:00
分母+1
|
259
codebs 2024-11-22 11:34:42 +08:00
我来组成分母
|
260
mingself 2024-11-22 11:35:26 +08:00
我是大学生
|
261
ooTwToo 2024-11-22 11:38:46 +08:00
好吃真好吃
|
262
wujb07 2024-11-22 11:38:48 +08:00
参与一下
|
263
L4Linux 2024-11-22 11:39:22 +08:00
祝自己好运
|
264
Ljxtt 2024-11-22 11:40:14 +08:00 via Android
分子加一
|
265
yang12345 2024-11-22 11:41:44 +08:00
买了一份 zc 一下
|
266
kin7 2024-11-22 11:43:21 +08:00
做个分子,感谢 OP
|
267
airwalkers 2024-11-22 11:43:22 +08:00
楼主好人
|
268
Kevin2 2024-11-22 11:43:22 +08:00 via Android
做个分母
|
269
skykk1op 2024-11-22 11:46:27 +08:00
做个分母
|
270
niko12138 2024-11-22 11:47:12 +08:00
重在参与!
|
271
Alwaysonline 2024-11-22 11:47:52 +08:00
试试运气+1
|
272
yxlian 2024-11-22 11:50:17 +08:00
冲冲冲!
|
273
ravour 2024-11-22 11:50:25 +08:00 via iPhone
重在参与
|
274
Absofknglutely 2024-11-22 11:52:03 +08:00
来来来
|
275
Godzilla123 2024-11-22 11:54:29 +08:00
重在参与!
|
276
shoalyu 2024-11-22 11:58:02 +08:00
分母+1
|
277
anychuan 2024-11-22 11:59:24 +08:00
+1
|
278
t1o1 2024-11-22 11:59:26 +08:00
参与一下
|
279
GG668v26Fd55CP5W 2024-11-22 12:00:31 +08:00 via iPhone
我要来十箱
|
280
SKYNE 2024-11-22 12:09:14 +08:00
重在参与
|
281
nodejx 2024-11-22 12:10:49 +08:00
参与下
|
282
pengjl 2024-11-22 12:16:47 +08:00
分子+1
|
283
parallx 2024-11-22 12:18:46 +08:00
分母+1
|
284
echodone 2024-11-22 12:20:28 +08:00
重在参与~
|
285
songjiaxin2008 2024-11-22 12:23:59 +08:00
参与一下~
|
286
wikilab 2024-11-22 12:24:50 +08:00 via Android
参与一下
|
287
lastrush 2024-11-22 12:25:35 +08:00
1
|
288
8888888888 2024-11-22 12:26:31 +08:00 via iPhone
让我试试 我明天一个橙子
|
289
zzdgfv 2024-11-22 12:28:42 +08:00
参与一下
|
290
soap0X 2024-11-22 12:28:53 +08:00 via Android
参加下
|
291
Muyiafan 2024-11-22 12:29:48 +08:00
分母+1
|
292
keepme 2024-11-22 12:30:27 +08:00
提前谢谢
|
293
ywl19891989 2024-11-22 12:36:42 +08:00
分母+1
|
294
Feedmo 2024-11-22 12:42:54 +08:00
代码加点注释,我一个后端怎么看得懂🤣
|
295
leeside 2024-11-22 12:50:53 +08:00 via iPhone
分母 重在参与
|
296
charisna 2024-11-22 12:52:30 +08:00
参与一下
|
297
6c9fd 2024-11-22 12:55:40 +08:00
试试
|
298
typetest 2024-11-22 12:56:04 +08:00
分子++
|
299
iThink 2024-11-22 12:59:44 +08:00
重在参与
|
300
pwli 2024-11-22 13:02:40 +08:00
分子
|