Last active
December 11, 2025 10:26
-
-
Save wjx0912/cccc1b48caa3a525e79604ea8d6f79cf to your computer and use it in GitHub Desktop.
v2ex dau refresh (闷声发大财就行了,不要宣传,不要宣传,不要宣传)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function fetch_wrap (url) { | |
| try { | |
| const html = await (await fetch(url, { | |
| 'method': 'GET', | |
| 'credentials': 'same-origin' // 确保请求携带当前浏览器的 cookies | |
| })).text() | |
| return html | |
| } catch (error) { | |
| console.error('Error fetch_wrap:', error) | |
| return '' | |
| } | |
| } | |
| // 刷dau相关的函数 | |
| function formatDate (date) { | |
| const pad = (n) => n.toString().padStart(2, '0') | |
| return [ | |
| date.getFullYear(), | |
| pad(date.getMonth() + 1), | |
| pad(date.getDate()) | |
| ].join('-') + ' ' + | |
| [ | |
| pad(date.getHours()), | |
| pad(date.getMinutes()), | |
| pad(date.getSeconds()) | |
| ].join(':') | |
| } | |
| async function get_dau (username) { | |
| try { | |
| const html = await fetch_wrap('https://www.v2ex.com/member/' + username) | |
| const match = html.match(/今日活跃度排名\s*<a[^>]*>(\d+)<\/a>/) | |
| if (match) { | |
| dau = parseInt(match[1], 10) | |
| console.log('当前活跃度排名: ', dau) | |
| return dau | |
| } | |
| } catch (error) { | |
| console.error('Error refreshing DAU:', error) | |
| } | |
| return 0 | |
| } | |
| async function refresh (username, threshold, sleep) { | |
| while (true) { | |
| const dau = await get_dau(username) | |
| if (dau <= threshold) { | |
| console.log(`活跃度排名已达到 ${dau},停止刷新。`) | |
| break | |
| } | |
| console.log(formatDate(new Date()) + `:当前用户 ${username} 活跃度为 ${dau},未达到阈值 ${threshold},休眠${sleep}秒继续刷新...`) | |
| await new Promise(resolve => setTimeout(resolve, sleep * 1000)) | |
| } | |
| } | |
| // 自动签到相关的函数 | |
| // 参考 https://github.com/abusizhishen/chrome_ext_v2ex/blob/main/script/background.js | |
| function extractMissionURL (str) { | |
| // 正则表达式,匹配 '/mission/daily/redeem?once=' 后面的数字 | |
| const regex = /\/mission\/daily\/redeem\?once=(\d+)/ | |
| // 使用正则表达式匹配 | |
| const match = str.match(regex) | |
| if (match) { | |
| // 返回匹配到的 URL 和数字 | |
| return { | |
| url: match[0], // 匹配到的完整 URL,如 '/mission/daily/redeem?once=80870' | |
| onceValue: match[1] // 匹配到的数字部分,如 '80870' | |
| } | |
| } else { | |
| // 如果没有匹配到,返回 null | |
| return null | |
| } | |
| } | |
| async function auto_sign () { | |
| try { | |
| // 休眠3秒 | |
| await new Promise(resolve => setTimeout(resolve, 3000)) | |
| const html = await fetch_wrap('https://www.v2ex.com/mission/daily') | |
| let result = extractMissionURL(html) | |
| if (result) { | |
| const url = 'https://www.v2ex.com' + result.url // 拼接完整的 URL | |
| // 调用函数进行金币领取 | |
| const html = await fetch_wrap(url) | |
| if (html) { | |
| console.log('签到成功') | |
| return | |
| } | |
| } else { | |
| console.log('已签到') | |
| return | |
| } | |
| } catch (error) { | |
| console.error('Error auto sign:', error) | |
| } | |
| console.log('签到失败') | |
| } | |
| ////////////////////////////////////////////////////////////// | |
| // 用户执行 | |
| ////////////////////////////////////////////////////////////// | |
| // 第一个参数是用户名,第二个参数是需要的活跃度阈值,第三个参数是休眠时间值越大越好以免意外封号(单位秒) | |
| // dau排行榜: https://www.v2ex.com/top/dau | |
| refresh('datadump', 10, 60) | |
| // auto_sign() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment