如果想在 V2EX 获得更好的推广效果,欢迎了解 PRO 会员机制:
https://www.v2ex.com/pro/about

如果你经常使用铜币置顶主题,持有 V2EX Solana Token 会在每日签到时获得额外铜币:
https://www.v2ex.com/solana
zzerd
V2EX  ›  推广

自已家的赣南脐橙开卖,给 v 友抽几箱

  •  
  •   zzerd · Nov 22, 2024 · 23996 views
    This topic created in 714 days ago, the information mentioned may be changed or developed.

    抽奖规则和去年一样取上证指数和最后指定日期最高楼。上一年的帖子/996196

    今年取 2024-11-22 上证指数收盘价作为随机数种子,有效抽奖用户为 2024-11-22 帖子回复最高楼层前的所有所有人

    去年的抽奖代码没有去重所有回复多个的用户中的概率高一点点,今年我用 ai 糊了一下。代码如下

    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://www.v2ex.com/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://www.v2ex.com/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
    ![]( https://i.v2ex.co/VlpwI4y5.jpeg)
    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=='))拉群

    Supplement 1  ·  Nov 22, 2024

    今年的橙子我也还没吃上,这图都是前段时间家时机人拍的现在橙子应该黄一些了。

    为啥这次的代码块没有高亮。。。代码看起来多,是因为ai 写的取回复用户数没用v站的api,下面是去除相关爬虫代码后的代码:https://gist.github.com/zzerding/d80d25149a74c0dd96516d949e9e52b7

    cloudflare work我会改为api形式代码后续在上面的gist里更新

    晚上12点以后可根据规则自行开奖

    Supplement 2  ·  Nov 22, 2024

    统一回复一下:

    橙子大约9分甜一分酸,每个人的口感不一样可以进群问问去年的v友

    可以发顺丰。晚上熬夜开的团图片先错了,里面有顺丰的商品链接大约江西周边9省53r/5kg

    好了不摸鱼了领导催进度了

    Supplement 3  ·  Nov 23, 2024

    感谢大家的支持,因为是现摘发货一天也就发300斤,受天气影响22号下单的会在24或者25号发完,先下单的先发,介意的可以申请退款。

    抽奖

    使用node自行开奖

    看到515楼我知道这个正则表达式取用户非常不可靠(但是当前代码好像没有注入成功),所以改用v2ex api。 使用方式

    恭喜以下用户

    @AchieveHF @xwh @ruiy @kuzhan 可以回复联系方式或者带主页截图找我领奖

    545 replies  •  2025-11-24 08:52:04 +08:00
    1  2  3  4  5  6  
    ❮ ❯
    xianxiancr2
    xianxiancr2
    Nov 22, 2024
    101
    分子+1
    guogews
    guogews
    Nov 22, 2024
    102
    争当分子
    bcys
    bcys
    Nov 22, 2024
    103
    重在参与
    ashrkq
    ashrkq
    Nov 22, 2024
    104
    重在参与
    spemoon
    spemoon
    Nov 22, 2024
    105
    祝大卖
    ropon
    ropon
    Nov 22, 2024
    106
    中奖
    coderth
    coderth
    Nov 22, 2024
    107
    重在参与~
    yunmeng
    yunmeng
    Nov 22, 2024
    108
    重在参与
    loren0912
    loren0912
    Nov 22, 2024
    109
    期待,跟贴冲!
    benzalus
    benzalus
    Nov 22, 2024
    110
    好奇,op 选邮政快递的原因是网点问题么
    BALLACK
    BALLACK
    Nov 22, 2024
    111
    支持
    xianchen926
    xianchen926
    Nov 22, 2024
    112
    江西人想吃老家的橙子了🍊
    inAsx2bVwc4CQT8G
    inAsx2bVwc4CQT8G
    Nov 22, 2024
    113
    试试
    alct
    alct
    Nov 22, 2024 via iPhone
    114
    支持一下支持一下
    immit
    immit
    Nov 22, 2024
    115
    分母,试试
    WANHOO
    WANHOO
    Nov 22, 2024
    116
    重在参与!
    4912941
    4912941
    Nov 22, 2024
    117
    分子
    jimdra
    jimdra
    Nov 22, 2024
    118
    牛啊
    yangJunKing
    yangJunKing
    Nov 22, 2024
    119
    分子
    GeekHao
    GeekHao
    Nov 22, 2024
    120
    +1
    Alison1113
    Alison1113
    Nov 22, 2024
    121
    好吃吗?想问问,想买
    Latin
    Latin
    Nov 22, 2024
    122
    永远不中体
    fengfisher3
    fengfisher3
    Nov 22, 2024
    123
    虽然每次都抽不中,所以,我在别的地方买了。
    Maxwells8
    Maxwells8
    Nov 22, 2024
    124
    码选之人
    MondaySmile
    MondaySmile
    Nov 22, 2024
    125
    分母
    starlin
    starlin
    Nov 22, 2024
    126
    重在参与
    Jason0803
    Jason0803
    Nov 22, 2024
    127
    分子
    coderzhangsan
    coderzhangsan
    Nov 22, 2024
    128
    支持
    xhadmin
    xhadmin
    Nov 22, 2024
    129
    重在参与!
    liyinhe
    liyinhe
    Nov 22, 2024
    130
    分母加一,重在参与!
    supersadmin
    supersadmin
    Nov 22, 2024
    131
    +1
    sanshiliu
    sanshiliu
    Nov 22, 2024
    132
    做个分母
    null00
    null00
    Nov 22, 2024
    133
    重在参与
    duandage0812
    duandage0812
    Nov 22, 2024
    134
    重在参与~
    juzidong
    juzidong
    Nov 22, 2024
    135
    分子
    ldyisbest
    ldyisbest
    Nov 22, 2024
    136
    支持
    mingliao
    mingliao
    Nov 22, 2024
    137
    冲
    ala2008
    ala2008
    Nov 22, 2024
    138
    前女友家也有,哭
    a2519862329
    a2519862329
    Nov 22, 2024
    139
    +1
    kylinC
    kylinC
    Nov 22, 2024
    140
    +1
    srddpzbx
    srddpzbx
    Nov 22, 2024
    141
    祝我敬享甜橙!
    yoyo989899
    yoyo989899
    Nov 22, 2024
    142
    重在参与!
    yngby
    yngby
    Nov 22, 2024
    143
    重在参与
    imch1n
    imch1n
    Nov 22, 2024
    144
    文字支持一下
    Isaaccccccc
    Isaaccccccc
    Nov 22, 2024
    145
    支持一下
    kunkunzhang
    kunkunzhang
    Nov 22, 2024
    146
    你们都是分母,我是分子
    c4dfan
    c4dfan
    Nov 22, 2024
    147
    隔壁省的来凑个分母。。。。
    shinelamla
    shinelamla
    Nov 22, 2024
    148
    说不定中了呢!
    nicholaswan
    nicholaswan
    Nov 22, 2024
    149
    参与
    luckyr
    luckyr
    Nov 22, 2024
    150
    参与一个
    incubus
    incubus
    Nov 22, 2024
    151
    参与一下
    ivanchou
    ivanchou
    Nov 22, 2024
    152
    当分母 祝楼主大卖
    uniqueFlynn
    uniqueFlynn
    Nov 22, 2024
    153
    已买,抽个玩玩
    Danmen123
    Danmen123
    Nov 22, 2024
    154
    试试
    chenliangngng
    chenliangngng
    Nov 22, 2024
    155
    拉低概率
    plusliang
    plusliang
    Nov 22, 2024
    156
    重在参与!
    Kyecox
    Kyecox
    Nov 22, 2024
    157
    进行一个分母的当
    Petercao008
    Petercao008
    Nov 22, 2024
    158
    分母+1
    Javers
    Javers
    Nov 22, 2024
    159
    分母+1
    whqijy
    whqijy
    Nov 22, 2024
    160
    分子+1
    Dizzy226
    Dizzy226
    Nov 22, 2024
    161
    试试运气
    xavi818
    xavi818
    Nov 22, 2024
    162
    支持一下
    forevam
    forevam
    Nov 22, 2024
    163
    尝试中奖 重在参与!
    ylrshui
    ylrshui
    Nov 22, 2024
    164
    看看运气+1
    wwwtarzan
    wwwtarzan
    Nov 22, 2024
    165
    分子
    yahaoo
    yahaoo
    Nov 22, 2024
    166
    1
    Evovil
    Evovil
    Nov 22, 2024
    167
    参与参与
    ammeto
    ammeto
    Nov 22, 2024
    168
    支持一下
    whythings
    whythings
    Nov 22, 2024
    169
    支持一下
    zhangsimon
    zhangsimon
    Nov 22, 2024
    170
    我是分子,预祝大卖!
    Lilithia
    Lilithia
    Nov 22, 2024
    171
    让我尝尝!
    xyqy
    xyqy
    Nov 22, 2024
    172
    重在参与!支持一下
    zerowxxyf
    zerowxxyf
    Nov 22, 2024
    173
    参与
    WayTooExplore
    WayTooExplore
    Nov 22, 2024
    174
    参与
    o0OoO0o
    o0OoO0o
    Nov 22, 2024
    175
    分母
    xiaopenyou
    xiaopenyou
    Nov 22, 2024
    176
    支持一下
    ABrother
    ABrother
    Nov 22, 2024
    177
    参与一下
    Lexin914
    Lexin914
    Nov 22, 2024
    178
    支持一下
    youngzhaojia
    youngzhaojia
    Nov 22, 2024
    179
    支持一下
    willxiang
    willxiang
    Nov 22, 2024
    180
    重在参与!
    qingchangaas
    qingchangaas
    Nov 22, 2024
    181
    支持一下
    Moierby
    Moierby
    Nov 22, 2024
    182
    老板生意兴隆
    nevermoreluo
    nevermoreluo
    Nov 22, 2024
    183
    试试
    zhangyq008
    zhangyq008
    Nov 22, 2024
    184
    重在参与
    hack2012
    hack2012
    Nov 22, 2024
    185
    真的假的
    t298
    t298
    Nov 22, 2024
    186
    我来组成头部
    bananaplan
    bananaplan
    Nov 22, 2024
    187
    我第一回评论吧
    Picmen
    Picmen
    Nov 22, 2024
    188
    我来组成分子
    huyoa
    huyoa
    Nov 22, 2024
    189
    天命分子!!!
    lvyouchn
    lvyouchn
    Nov 22, 2024
    190
    支持一下
    suwia
    suwia
    Nov 22, 2024
    191
    重在参与!
    RLinux
    RLinux
    Nov 22, 2024
    192
    +1
    sb
    sb
    Nov 22, 2024
    193
    测试中奖
    niuxinghua
    niuxinghua
    Nov 22, 2024
    194
    参与下
    lovelive1024
    lovelive1024
    Nov 22, 2024
    195
    已经买了同事家的脐橙,今年的品质挺不错了
    dishuibaby
    dishuibaby
    Nov 22, 2024
    196
    参与快乐
    nanbobo
    nanbobo
    Nov 22, 2024
    197
    重在参与!
    erlkingrui999
    erlkingrui999
    Nov 22, 2024
    198
    分母来也
    webertyan
    webertyan
    Nov 22, 2024
    199
    参与!
    rabitzn
    rabitzn
    Nov 22, 2024
    200
    这个不错 参与一下
    1  2  3  4  5  6  
    ❮ ❯
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1442 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 257ms · UTC 23:21 · PVG 07:21 · LAX 15:21 · JFK 18:21
    ♥ Do have faith in what you're doing.