写了个 surge 脚本, hifini 自动定时签到 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
SimonOne
V2EX    分享创造

写了个 surge 脚本, hifini 自动定时签到

  •  
  •   SimonOne 2024-05-13 14:11:31 +08:00 2132 次点击
    这是一个创建于 518 天前的主题,其中的信息可能已经有所发展或是发生改变。

    不懂 js 的苦手写的难受死了(其实除了 abap 别的也不会)。

    花了一晚上,主要时间浪费在“网络请求是异步的,必须等到前一个函数获取 sign 后才能开始下一个函数签到”,但是我没有用 js 异步的经验,一直在 google 怎么样能让上一个函数异步完成拿到 sign 后再签到。

    贴出来给大家看下,要是有大哥能帮忙优化下就更好了。

    const jobName = "hifini.com 签到" const cookie = $persistentStore.read("hifiniDailyBonusCookie") const recentSignDate = $persistentStore.read("hifiniDailyBonusRecentSignDate") const today = new Date() const mOnth= today.getMonth() + 1 const signDate = `${today.getFullYear()}${month}${today.getDate()}` // 获取 sign function hifiniGetSign() { return new Promise(resolve => { console.log("获取签到的 sign") // 获取签到的 sign const request = { url: "https://www.hifini.com/", headers: { "Cookie": cookie, "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" } } $httpClient.get(request, (error, response, data) => { console.log("发送请求") if (response.status == 200) { var regex = /var sign = \"(\w+)";/ var match = regex.exec(data); if (match !== null) { var sign = match[1] console.log(`已取得 sign=${sign}`) resolve(sign) } else { console.log(`未通过正则表达式${regex}找到匹配的 sign`) $done() } } else { console.log(`获取 sign 失败,返回码${response.status}`) $done() } }) }) } // 签到 function hifiniSign(sign) { if (signDate !== recentSignDate) { console.log("本机今天尚未签到,开始签到请求") const request = { url: "https://www.hifini.com/sg_sign.htm", headers: { "Accept-Language": "zh-Hans,zh-CN;q=0.9,zh;q=0.8", "Content-Type": "application/x-www-form-urlencoded; charset=", "Cookie": cookie, "x-requested-with": "XMLHttpRequest", "Referer": "https://www.hifini.com/", "Sec-Ch-Ua": "\"Chromium\";v=\"124\", \"Google Chrome\";v=\"124\", \"Not-A.Brand\";v=\"99\"", "Sec-Ch-Ua-Mobile": "?0", "Sec-Ch-Ua-Platform": "\"macOS\"", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" }, body: `sign=${sign}` } $httpClient.post(request, (error, response, data) => { console.log("发送签到请求") if (response.status == 200) { if (data == null) { console.log("请求成功,返回空") const title = jobName const subTitle = "请求成功,返回空,检查下" $notification.post(title, subTitle, "") } else { if (JSON.parse(data).code == 0) { const title = jobName const subTitle = "签到成功" const detail = JSON.parse(data).message console.log(detail) $persistentStore.write(signDate, "hifiniDailyBonusRecentSignDate") $notification.post(title, subTitle, detail) } else if (JSON.parse(data).code == -1) { const title = jobName const subTitle = "签到跳过" const detail = JSON.parse(data).message console.log(detail) $persistentStore.write(signDate, "hifiniDailyBonusRecentSignDate") $notification.post(title, subTitle, detail) } else { const title = jobName const subTitle = "签到失败" console.log(detail) const detail = `error: ${error}, response: ${response}, data: ${data}` $notification.post(title, subTitle, detail) } } } else { console.log(`请求失败,返回码${response.status}`) const title = jobName const subTitle = `请求失败,返回码${response.status}` $notification.post(title, subTitle, "") } $done() }) } else { console.log("今天已经签过") const title = jobName const subTitle = "签到跳过" const detail = "今天已经签过啦!" $notification.post(title, subTitle, detail) $done() } } hifiniGetSign().then(sign => { hifiniSign(sign) }) 
    5 条回复    2025-07-09 22:42:08 +08:00
    RangerWolf
        1
    RangerWolf  
       2024-05-14 09:14:33 +08:00   1
    脚本没用上,但是发现了一个宝藏网站,感谢 op
    jpyl0423
        2
    jpyl0423  
       2024-05-14 10:27:50 +08:00
    我本来想用 python 写一个放到青龙面板的,太懒一直没写,直接用 lz 的吧
    blankmiss
        3
    blankmiss  
       2024-05-14 16:54:13 +08:00
    有验证码 模拟登录 很麻烦
    SimonOne
        4
    SimonOne  
    OP
       2024-05-14 19:41:33 +08:00
    @blankmiss #3 所以改成半自动的,登录上了,拿到 cookie ,偶尔 cookie 失效了就再手动取下。
    ambroserencn
        5
    ambroserencn  
       96 天前
    网站闭站了,心痛!我还有钱在里面呢……
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1465 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 16:44 PVG 00:44 LAX 09:44 JFK 12:44
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86