Greasy Fork is available in English.
在指定网页上监测弹卡按钮的存在,并点击它
当前为
// ==UserScript==
// @name 小红书弹卡按钮监测
// @namespace http://xxxxxx.com
// @version 1.0
// @icon https://bkimg.cdn.bcebos.com/pic/f3d3572c11dfa9ec8a13fb131a9ae003918fa0ec6bd6
// @description 在指定网页上监测弹卡按钮的存在,并点击它
// @author tunan
// @match https://redlive.xiaohongshu.com/live_control
// @license MIT
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 获取用户保存的检测时间间隔,如果没有保存则使用默认值
let checkInterval = localStorage.getItem('checkInterval');
if (!checkInterval) {
checkInterval = 5; // 默认5秒
}
// 创建UI
const ui = document.createElement('div');
ui.innerHTML = `
<div style="position: fixed; bottom: 10px; right: 10px; background: white; padding: 10px; border: 1px solid #ccc;">
<label for="checkInterval">检测时间(秒):</label>
<input type="number" id="checkInterval" value="${checkInterval}">
</div>
`;
document.body.appendChild(ui);
// 获取UI元素
const checkIntervalInput = document.getElementById('checkInterval');
// 设置检测时间
checkIntervalInput.addEventListener('change', function() {
checkInterval = parseInt(checkIntervalInput.value);
localStorage.setItem('checkInterval', checkInterval); // 保存用户设置的检测时间
});
// 检测并点击弹卡按钮
function checkAndClickPopCardButton() {
console.log('开始检测弹卡按钮...');
const popCardButtons = document.querySelectorAll('.operation-item span[data-v-d95d4d32]');
for (const button of popCardButtons) {
if (button.textContent.trim() === '弹卡') {
console.log('找到弹卡按钮,尝试点击它。');
simulateMouseClick(button);
return;
}
}
console.log('未找到弹卡按钮。');
}
// 模拟鼠标点击元素
function simulateMouseClick(element) {
const event = document.createEvent('MouseEvent');
event.initEvent('click', true, true);
element.dispatchEvent(event);
}
// 定期检测弹卡按钮
setInterval(checkAndClickPopCardButton, checkInterval * 1000);
})();