// ==UserScript== // @name Linux.do 自动浏览助手 // @namespace https://linux.do/ // @version 2.5.0 // @description 自动浏览帖子、滚动查看所有回复、随机点赞、避免重复浏览、可限定每帖浏览楼层数、Credit积分展示 // @author Assistant // @match https://linux.do/* // @downloadURL https://raw.githubusercontent.com/liasica/linuxdo/feature/src/linuxdo-automation.user.js // @updateURL https://raw.githubusercontent.com/liasica/linuxdo/feature/src/linuxdo-automation.user.js // @grant GM_setValue // @grant GM_getValue // @grant GM_addStyle // @grant GM_xmlhttpRequest // @grant unsafeWindow // @connect credit.linux.do // @run-at document-idle // ==/UserScript== (function() { 'use strict'; // 为当前标签页生成唯一ID(用于防多开检测) // 必须按“浏览器标签页”稳定,不能每次页面加载都随机:脚本靠整页跳转翻话题, // 若跳转后 ID 变了,锁里存的旧 ID 永远对不上自己,会被误判成“其他标签页在运行”而拒绝自启。 // sessionStorage 恰好按标签页隔离且整页跳转后保留:同一标签页翻页 ID 不变,新开标签页 ID 必然不同 const TAB_ID = (() => { try { let id = sessionStorage.getItem('linuxdo_tab_id'); if (!id) { id = Math.random().toString(36).slice(2, 11); sessionStorage.setItem('linuxdo_tab_id', id); } return id; } catch (e) { // sessionStorage 不可用时退回随机 ID(仅影响防多开的准确性,不影响功能) return Math.random().toString(36).slice(2, 11); } })(); // ==================== 配置参数 ==================== // 速度预设(进一步调整避免429错误) const SPEED_PRESETS = { slow: { name: '慢速', scrollStep: 300, scrollInterval: 2500, loadWaitTime: 4000, minReadTime: 2000, maxReadTime: 4000, noNewContentRetry: 4 }, normal: { name: '正常', scrollStep: 400, scrollInterval: 1500, loadWaitTime: 2500, minReadTime: 800, maxReadTime: 1500, noNewContentRetry: 3 }, fast: { name: '快速', scrollStep: 500, scrollInterval: 800, loadWaitTime: 1500, minReadTime: 300, maxReadTime: 800, noNewContentRetry: 3 }, turbo: { name: '极速', scrollStep: 600, scrollInterval: 400, loadWaitTime: 1000, minReadTime: 100, maxReadTime: 300, noNewContentRetry: 2 } }; // 当前速度设置(延迟初始化,等Storage类定义后再读取) let currentSpeed = 'normal'; // 列表选择设置 const LIST_OPTIONS = { latest: { name: '最新', path: '/latest' }, new: { name: '新帖', path: '/new' }, unread: { name: '未读', path: '/unread' } }; let currentList = 'latest'; // 点赞开关 let enableLike = true; // 点赞概率预设 const LIKE_CHANCE_PRESETS = { low: { name: '低', value: 0.05 }, // 5% medium: { name: '中', value: 0.15 }, // 15% high: { name: '高', value: 0.25 }, // 25% veryHigh: { name: '极高', value: 0.40 } // 40% }; let currentLikeChance = 'medium'; // 楼层限制:每帖只浏览前 N 楼就换下一帖,0 表示不限 let floorLimit = 0; // 楼层限制的计数口径:开启后已读楼层滚过不计数,只数上次阅读位置之后的新楼层 let floorLimitUnreadOnly = false; const CONFIG = { // 动态从速度预设获取 get scrollStep() { return SPEED_PRESETS[currentSpeed].scrollStep; }, get scrollInterval() { return SPEED_PRESETS[currentSpeed].scrollInterval; }, get loadWaitTime() { return SPEED_PRESETS[currentSpeed].loadWaitTime; }, get minReadTime() { return SPEED_PRESETS[currentSpeed].minReadTime; }, get maxReadTime() { return SPEED_PRESETS[currentSpeed].maxReadTime; }, get noNewContentRetry() { return SPEED_PRESETS[currentSpeed].noNewContentRetry; }, // 点赞设置(动态从预设获取) get likeChance() { return LIKE_CHANCE_PRESETS[currentLikeChance].value; }, minLikeInterval: 2000, // 最小点赞间隔 (ms) // 会话设置 maxLikesPerSession: 50, // 每次会话最大点赞数 maxTopicsPerSession: 50, // 每次会话最大浏览话题数 // 返回列表设置 returnToListDelay: 1000, // 返回列表前延迟 (ms) // 时间线「返回」按钮的最长等待时间 (ms),等不到就留在原地读 backButtonWaitTime: 2500, // 调试(默认关闭,避免给所有用户刷 console;需要时用 GM_setValue('debug', true) 开启) debug: false }; function setSpeed(preset) { if (SPEED_PRESETS[preset]) { currentSpeed = preset; Storage.set('speed_preset', preset); log(`速度设置为: ${SPEED_PRESETS[preset].name}`); } } function setList(listType) { if (LIST_OPTIONS[listType]) { currentList = listType; Storage.set('list_type', listType); log(`列表设置为: ${LIST_OPTIONS[listType].name}`); } } function setEnableLike(enabled, updateUI = true) { enableLike = enabled; Storage.set('enable_like', enabled); log(`随机点赞: ${enabled ? '已开启' : '已关闭'}`); // 更新UI按钮状态 if (updateUI) { document.querySelectorAll('.like-btn[data-like]').forEach(btn => { btn.classList.remove('active'); if ((btn.dataset.like === 'true') === enabled) { btn.classList.add('active'); } }); // 点赞关闭时概率选项没有意义,整行收起 const chanceRow = document.getElementById('like-chance-row'); if (chanceRow) chanceRow.classList.toggle('hidden', !enabled); } } // 处理点赞限制:点赞走 API 直连(sendLikeRequest),命中 429/rate_limit 时调用, // 直接关掉点赞开关避免继续触发风控(API 点赞不弹 UI 对话框,故无需检测或关闭弹窗) function handleLikeLimit() { log('已达到点赞上限,自动关闭点赞功能'); setEnableLike(false, true); } function setLikeChance(preset) { if (LIKE_CHANCE_PRESETS[preset]) { currentLikeChance = preset; Storage.set('like_chance', preset); const percent = Math.round(LIKE_CHANCE_PRESETS[preset].value * 100); log(`点赞概率设置为: ${LIKE_CHANCE_PRESETS[preset].name} (${percent}%)`); } } function setFloorLimit(value) { const n = Math.max(0, Math.floor(Number(value) || 0)); floorLimit = n; Storage.set('floor_limit', n); log(`楼层限制设置为: ${n > 0 ? `前 ${n} 楼` : '不限'}`); } function setFloorLimitUnreadOnly(enabled) { floorLimitUnreadOnly = enabled; Storage.set('floor_limit_unread_only', enabled); log(`楼层限制口径: ${enabled ? '只计未读楼层' : '按楼层号'}`); } // ==================== 工具函数 ==================== function log(...args) { if (CONFIG.debug) { console.log(`[LinuxDo自动化|${TAB_ID}]`, new Date().toLocaleTimeString(), ...args); } } function randomDelay(min, max) { const delay = Math.floor(Math.random() * (max - min + 1)) + min; return new Promise(resolve => setTimeout(resolve, delay)); } function randomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } // 登录状态三态检测:true=已登录,false=未登录,null=无法判定(页面未就绪或 Cloudflare 挑战页) // 优先读取 #data-preloaded(服务端直出,脚本注入时必然存在), // 避免与 Ember 渲染 #current-user 竞速导致误判(脚本注入时 header 尚未渲染) function getLoginState() { const preloaded = document.querySelector('#data-preloaded'); if (preloaded) { // 新版 Discourse 把预加载数据放进