获取淘宝直播弹幕信息并发送详情
当前为
// ==UserScript==
// @name 淘宝弹幕助手
// @namespace http://tampermonkey.net/
// @version 8.0
// @description 获取淘宝直播弹幕信息并发送详情
// @match https://liveplatform.taobao.com/restful/index/live/control/*
// @icon https://cdn.52ym.vip/temp/a0whr-l6z8y-001.ico
// @grant none
// @license MIT
// ==/UserScript==
const TIME = 3000;
const platformMap = new Map([
['liveplatform.taobao.com', handleTaoBaoBarrage]
]);
let barrageIds = []; // 存储已处理的弹幕ID
function handleRequest(username, content, id) {
// 构造弹幕数据对象
let data = {
nickname: username,
content: content
};
console.log(data);
// 将已处理的弹幕ID添加到列表中
barrageIds.push(id);
if (barrageIds.length > 300) {
barrageIds.splice(0, 100);
}
}
function handleTaoBaoBarrage() {
let barrageContainer = document.querySelector('.alpw-container > div.alpw-comment-item:last-child');
console.log("current barrageContainer:",barrageContainer);
if (!barrageContainer) {
return; // Exit if the barrage container element is not found
}
let barrageElements = barrageContainer.querySelectorAll('div.alpw-comment-item');
for (let i = 0; i < barrageElements.length; i++) {
let barrageElement = barrageElements[i];
let usernameElement = barrageElement.querySelector('div.alpw-userinfo > div.alpw-left > div.alpw-username > div.alpw-username-text');
let contentElement = barrageElement.querySelector('div.alpw-comment-content');
// 检查弹幕元素是否存在
if (!usernameElement || !contentElement) {
continue; // Skip if either username or content element is not found
}
let username = usernameElement.textContent.trim();
let content = contentElement.textContent.trim();
let id = username + content;
// 检查是否已处理过该弹幕
if (barrageIds.includes(id)) {
continue;
}
handleRequest(username, content, id);
}
}
(function () {
setTimeout(()=>{
const currUrl = window.location.href;
console.log("开启直播了..................",currUrl) ;
platformMap.forEach((value, key) => {
if (currUrl.indexOf(key) !== -1) {
setInterval(value, TIME);
}
});
},10000)
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址