您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
获取直播弹幕信息并发送详情
当前为
// ==UserScript== // @name 弹幕 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 获取直播弹幕信息并发送详情 // @match https://liveplatform.taobao.com/* // @icon https://cdn.52ym.vip/temp/a0whr-l6z8y-001.ico // @grant none // @license MIT // ==/UserScript== const TIME = 3000; const platformMap = new Map([ ['taobao', handleTaoBaoBarrage] ]); let barrageIds = []; // 存储已处理的弹幕ID let requestData = { "rommId": 0,//直播间ID "username":"",//用户 "content":"",//评论 "onlineUserCount":0,//在线人数 "isSub":false,//是否关注 } //发送弹幕消息 function handleRequest(params) { // 构造弹幕数据对象 let data = { nickname: params.username, content: params.content }; console.log(data); // 将已处理的弹幕ID添加到列表中 barrageIds.push(params.username+params.content); if (barrageIds.length > 300) { barrageIds.splice(0, 100); } httpRequest({ method:"post", url:"http://127.0.0.1:8000/api/live/comment/push/", data:params, async:true, },(res)=>{ console.log('res:',res) },(err)=>{ console.log("err:",err) }) } //查询直播间ID function getQueryName(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) { return decodeURI(r[2]); } return null; } function getOnlineCount() { } let xmlHttp="" //推送数据 function httpRequest(requestObj,successFun,failFun) { let { url:httpUrl, method, data, async } = requestObj xmlHttp = checkBrowser(xmlHttp); //请求方式, 转换为大写 var httpMethod = (method || "Get").toUpperCase(); //post请求时参数处理 if (httpMethod === "POST") requestData = JSON.stringify(data) xmlHttp.onreadystatechange = function () { if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { // 请求成功的回调函数 successFun(JSON.parse(xmlHttp.responseText)); } else { //请求失败的回调函数 failFun(xmlHttp.responseText); } } // 发送请求 sendRequest(httpUrl, requestData, httpMethod, async ); } /** * 校验浏览器创建xmlHttp对象 * @param xmlHttp */ function checkBrowser(xmlHttp) { //创建 XMLHttpRequest 对象,老版本的 Internet Explorer (IE5 和 IE6) //使用 ActiveX 对象:xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") if (window.XMLHttpRequest) { //code for all new browsers xmlHttp = new XMLHttpRequest; } else if (window.ActiveXObject) { //code for IE5 and IE6 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } // console.log(xmlHttp) return xmlHttp; } /** * 发送请求 * @param xmlHttp * @param requestData */ function sendRequest(httpUrl, requestData, httpMethod, async) { if (httpMethod === "GET") { xmlHttp.open("GET", httpUrl, async); xmlHttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xmlHttp.send(null); } else if (httpMethod === "POST") { xmlHttp.open("POST", httpUrl, async); xmlHttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xmlHttp.setRequestHeader("Access-Control-Allow-Origin", "*"); // 用来解决跨域 xmlHttp.send(requestData); } } //处理弹幕消息 function handleTaoBaoBarrage() { let barrageContainer = document.querySelector('#rc-tabs-1-panel-AssistantCommentCard > div.alpw-container > div > div:last-child'); if (!barrageContainer) { return; // Exit if the barrage container element is not found } let usernameElement = barrageContainer.querySelector('div.alpw-userinfo > div > div > div.alpw-username-text'); let usernickElement = barrageContainer.querySelector('div.alpw-userinfo > div > div > div.alpw-username-nick') let contentElement = barrageContainer.querySelector('div.alpw-comment-content'); let username = usernameElement.textContent.trim()+usernickElement.textContent.trim(); let content = contentElement.textContent.trim(); // 检查是否已处理过该弹幕 if (barrageIds.includes((username+content))) { return; } const roomId = getQueryName("liveId"); let is_sub=false; if(content.indexOf("关注了主播")!==-1){ is_sub=true } requestData = { "roomId":roomId, "username":username,//用户 "content":content,//评论 "onlineCount": 0,//在线人数 "isSub":is_sub,//是否关注 } handleRequest(requestData); } (function () { setTimeout(()=>{ const currUrl = window.location.href; platformMap.forEach((value, key) => { if (currUrl.indexOf(key) !== -1) { setInterval(value, TIME); } }); },5000) })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址