赞
踩
// ==UserScript==
// @name 福袋自动发放-蛋疼
// @namespace [url=http://example.com/]http://example.com/[/url]
// @version 1.0
// @description Automatically starts an activity on a specific webpage with a labeled toggle switch and a default loop interval of 606 seconds, displaying countdown for the next execution time. Countdown stops when the toggle switch is turned off. The page is refreshed when the toggle switch is turned off.
// @match [url=https://buyin.jinritemai.com/dashboard/live/control]https://buyin.jinritemai.com/dashboard/live/control[/url]
// @grant none
// ==/UserScript==
(
function
() {
'use strict'
;
var
intervalId;
// 用于存储循环执行的计时器ID
var
countdownIntervalId;
// 用于存储倒计时的计时器ID
// 创建一个包含标签和开关的容器元素
var
container = document.createElement(
'div'
);
container.style.position =
'fixed'
;
container.style.top =
'80px'
;
// 距离顶部的距离
container.style.left =
'10px'
;
// 距离左侧的距离
// 创建一个包含标签的 div 元素
var
labelContainer = document.createElement(
'div'
);
labelContainer.style.display =
'inline-block'
;
// 设置为行内块级元素以保证标签可见
// 创建一个标签元素
var
label = document.createElement(
'label'
);
label.textContent =
'自动福袋开关'
;
// 在标签中添加文字
// 创建一个开关元素
var
toggleSwitch = document.createElement(
'input'
);
toggleSwitch.type =
'checkbox'
;
// 将标签添加到标签容器
labelContainer.appendChild(label);
// 将标签容器和开关添加到容器
container.appendChild(labelContainer);
container.appendChild(toggleSwitch);
// 创建一个元素来显示下次执行时间的倒计时
var
countdownElement = document.createElement(
'div'
);
countdownElement.style.marginTop =
'10px'
;
// 上边距,使其与开关有一定间隔
container.appendChild(countdownElement);
// 将容器添加到页面
document.body.appendChild(container);
var
intervalDuration = 606000;
// 循环执行的间隔时间,单位:毫秒(606秒)
// 更新下次执行时间的倒计时
function
updateCountdown() {
var
countdownTime = intervalDuration / 1000;
// 下次执行的时间间隔,单位:秒
countdownIntervalId = setInterval(
function
() {
countdownTime--;
if
(countdownTime <= 0) {
countdownTime = intervalDuration / 1000;
// 重置倒计时时间
}
var
minutes = Math.floor(countdownTime / 60);
var
seconds = countdownTime % 60;
countdownElement.textContent =
'下次执行时间:'
+ minutes +
' 分 '
+ seconds +
' 秒'
;
}, 1000);
}
// 添加事件监听器以根据开关状态执行或停止脚本
toggleSwitch.addEventListener(
'change'
,
function
() {
if
(toggleSwitch.checked) {
// 启用脚本的自动操作逻辑,设定循环间隔为 606 秒
intervalId = setInterval(startAutoOperation, intervalDuration);
startAutoOperation();
// 立即执行一次
updateCountdown();
// 更新下次执行时间的倒计时
}
else
{
// 停止脚本的自动操作逻辑,清除计时器和倒计时定时器
clearInterval(intervalId);
clearInterval(countdownIntervalId);
// 清除倒计时定时器
stopAutoOperation();
countdownElement.textContent =
''
;
// 停止时清空倒计时
// 关闭开关时刷新页面
window.location.reload();
}
// 在开关状态切换时立即启动或停止倒计时
updateCountdown();
});
// 自动操作的逻辑函数(示例步骤,你需要在这里添加你的具体操作)
function
startAutoOperation() {
// 步骤1:点击超级福袋按钮
var
xpathExpression =
"//div[@class='index-module__tool___1D3Kc']/p[contains(text(), '超级福袋')]"
;
var
superLuckyBagElement = document.evaluate(xpathExpression, document,
null
, XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
if
(superLuckyBagElement) {
superLuckyBagElement.click();
// 步骤2:延迟1秒后点击下拉框元素
setTimeout(
function
() {
var
dropdownElement = document.querySelector(
".buyin-select-selector"
);
if
(dropdownElement) {
simulateMouseDown(dropdownElement);
// 步骤3:延迟1秒后选择指定的选项
setTimeout(
function
() {
var
optionElement = document.querySelector(
".buyin-select-item[title='活动待开始']"
);
if
(optionElement) {
optionElement.click();
// 步骤4:延迟1秒后模拟点击查询按钮
setTimeout(
function
() {
var
queryButton = document.querySelector(
"button.buyin-btn-primary"
);
if
(queryButton) {
simulateClick(queryButton);
// 步骤5:延迟1秒后点击第一个"开始活动"按钮
setTimeout(
function
() {
var
startButton = document.querySelector(
"button.buyin-btn-dashed"
);
if
(startButton) {
simulateClick(startButton);
// 步骤6:延迟1秒后点击关闭按钮
setTimeout(
function
() {
var
closeButton = document.querySelector(
"svg[data-icon='close']"
);
if
(closeButton) {
simulateClick(closeButton);
}
else
{
console.log(
"未找到关闭按钮元素。"
);
}
}, 1000);
// 1秒的等待时间
}
}, 1000);
// 1秒的等待时间
}
}, 1000);
// 1秒的等待时间
}
}, 1000);
// 1秒的等待时间
}
}, 1000);
// 1秒的等待时间
}
}
// 模拟mousedown事件
function
simulateMouseDown(element) {
var
event =
new
MouseEvent(
'mousedown'
, {
bubbles:
true
,
cancelable:
true
,
view: window
});
element.dispatchEvent(event);
}
// 模拟点击事件
function
simulateClick(element) {
var
event =
new
MouseEvent(
'click'
, {
bubbles:
true
,
cancelable:
true
,
view: window
});
element.dispatchEvent(event);
}
// 停止自动操作的逻辑函数
function
stopAutoOperation() {
// 在这里添加停止自动操作的逻辑,如果需要的话
// ...
}
})();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。