// ==UserScript== // @name 微博评论点赞助手 // @namespace http://tampermonkey.net/ // @version 1.2 // @description 支持自定义选择微博、随机评论的自动互动工具 // @author Your Name // @match https://*.weibo.com/* // @grant GM_xmlhttpRequest // @grant GM_notification // @connect weibo.com // ==/UserScript== (function () { "use strict"; // 在createComment函数顶部添加 const timestamp = Date.now(); const dynamicRid = `0_0_50_${timestamp}_0_0_0`; // 动态获取当前域名 const currentDomain = window.location.hostname; // 精心设计的20条自然评论 const COMMENTS = [ "肖战的演技真的越来越棒了!期待新作品~", "战战今天又帅出新高度了!", "每次看到肖战的舞台都心跳加速!", "哥哥的自拍可以多来点吗?看不够呀!", "肖战的歌声太治愈了,循环播放中!", "为战战的敬业精神点赞!", "这个造型也太适合肖战了吧!", "永远支持正能量偶像肖战!", "战战的笑容就是我每天的动力!", "肖战的新剧什么时候播呀?等不及了!", "哥哥要注意身体呀,别太辛苦了~", "肖战的古装造型永远的神!", "今天也是为战战疯狂打call的一天!", "战战的采访总是充满智慧!", "肖战的公益行动太暖心了!", "哥哥的穿搭可以出个教程吗?", "战战的台词功底进步好大!", "肖战就是品质的保证!", "每天都要来超话看看战战~", "肖战值得所有的美好!永远支持你!", ]; function getCsrfToken() { console.log( "xxx:", document.cookie.match(/(^|; )XSRF-TOKEN=([^;]+)/)?.[2] || "" ); return document.cookie.match(/(^|; )XSRF-TOKEN=([^;]+)/)?.[2] || ""; } // console("xxx:",getCsrfToken()); function buildHeaders() { const token = getCsrfToken(); console.log("[DEBUG] CSRF Token:", token); // 确认令牌获取 return { "X-XSRF-TOKEN": getCsrfToken(), Cookie: document.cookie, Referer: location.href, "Content-Type": "application/x-www-form-urlencoded", }; } function buildLikeHeaders() { const token = getCsrfToken(); console.log("[DEBUG] CSRF Token:", token); // 确认令牌获取 return { "X-XSRF-TOKEN": getCsrfToken(), Cookie: document.cookie, Referer: location.href, "Content-Type": "buildLikeHeaders", }; } // 添加悬浮控制按钮 function addControlPanel() { const panel = document.createElement("div"); panel.style = ` position: fixed; right: 220px; top: 20px; z-index: 99999; background: rgba(255,255,255,0.9); padding: 15px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); `; const btn = document.createElement("button"); btn.innerHTML = "启动评论点赞(28个后会自动停止,10分钟后重新执行"; btn.style = ` padding: 8px 15px; background: #ff8200; color: white; border: none; border-radius: 4px; cursor: pointer; `; btn.onclick = initProcess; panel.appendChild(btn); document.body.appendChild(panel); } // 获取当前页面UID function getCurrentUID() { const match = window.location.href.match(/\/(u|profile)\/(\d+)/); return match ? match[2] : null; } // 获取微博列表 async function getWeiboList(uid) { return new Promise((resolve) => { GM_xmlhttpRequest({ method: "GET", url: `https://${currentDomain}/ajax/statuses/mymblog?uid=${uid}&page=1&feature=0`, headers: buildHeaders(), onload: function (response) { const data = JSON.parse(response.responseText); resolve(data.data?.list || []); }, onerror: () => resolve([]), }); }); } async function createComment(weiboId) { const randomComment = COMMENTS[Math.floor(Math.random() * COMMENTS.length)]; return new Promise((resolve) => { GM_xmlhttpRequest({ method: "POST", url: `https://${currentDomain}/ajax/comments/create`, headers: buildHeaders(), data: new URLSearchParams({ // 使用标准参数编码 id: weiboId, comment: randomComment, pic_id: "", is_repost: 0, comment_ori: 0, is_comment: 0, mark: "followtopweibo", rid: dynamicRid, }).toString(), onload: function (response) { const data = JSON.parse(response.responseText); data.ok ? resolve(data.data.rootid) : resolve(null); }, }); }); } async function likeObject(rootId) { return new Promise(resolve => { GM_xmlhttpRequest({ method: "POST", url: `https://${currentDomain}/ajax/statuses/updateLike`, headers: { ...buildLikeHeaders(), "Content-Type": "application/json" // ✅ 必须明确指定 }, data: JSON.stringify({ object_id: rootId, object_type: "comment", mark: "followtopweibo", // ✅ 新增必要参数 rid: `0_0_50_${Date.now()}_0_0_0` // ✅ 动态rid }), onload: function(response) { try { const data = JSON.parse(response.responseText); console.log('[DEBUG] 点赞响应:', data); resolve(data.ok === 1); // ✅ 严格验证ok=1 } catch (e) { console.error('点赞响应解析失败:', e); resolve(false); } }, onerror: () => resolve(false) }); }); } async function executeInteraction(weiboId) { try { const rootId = await createComment(weiboId); if (!rootId) return false; // ✅ 添加点赞结果验证 const likeSuccess = await likeObject(rootId); return likeSuccess; } catch (e) { console.warn('操作失败:', e); return false; } } // 主流程控制 async function initProcess() { const uid = getCurrentUID(); if (!uid) { alert("请先进入微博用户主页!"); return; } const input = prompt("请输入要操作的微博序号(可填入1~20):"); const index = parseInt(input) - 1; if (isNaN(index)) return; const weiboList = await getWeiboList(uid); if (index < 0 || index >= weiboList.length) { alert("无效的微博序号!"); return; } const targetWeibo = weiboList[index]; GM_notification({ title: "操作启动", text: `已选择微博:${targetWeibo.text_raw.substr(0, 20)}...`, timeout: 3000, }); let successCount = 0; const INTERVAL = 1000; // 每次操作间隔 const BATCH_SIZE = 28; // 每轮次数 const CYCLE_DELAY = 600000; // 循环间隔10分钟 async function runBatch() { for (let i = 0; i < BATCH_SIZE; i++) { if (await executeInteraction(targetWeibo.id)) successCount++; await new Promise((r) => setTimeout(r, INTERVAL + Math.random() * 500)); } GM_notification({ title: "批次完成", text: `成功操作 ${successCount} 次,10分钟后继续`, timeout: 5000, }); setTimeout(runBatch, CYCLE_DELAY); } runBatch(); } // 初始化界面 window.addEventListener("load", () => { setTimeout(addControlPanel, 3500); }); })();