aggrx用来测试
目前為
// ==UserScript==
// @name aggrx 测试测试
// @namespace http://tampermonkey.net/
// @version 1.1.1
// @description aggrx用来测试
// @author You
// @match https://claude.ai/*
// @match https://chat.openai.com/*
// @grant none
// @license AGPL License
// ==/UserScript==
(function() {
'use strict';
// 添加样式
var toastCSS = `
#tmToast {
visibility: hidden;
min-width: 250px;
margin-left: -125px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 2px;
padding: 16px;
position: fixed;
z-index: 1;
left: 50%;
bottom: 30px;
font-size: 17px;
}
#tmToast.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@-webkit-keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
@keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
`;
var styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = toastCSS;
document.head.appendChild(styleSheet);
// 添加 Toast 容器
var toastContainer = document.createElement('div');
toastContainer.id = 'tmToast';
document.body.appendChild(toastContainer);
// Toast 函数
function showToast(message, duration = 3000) {
var toast = document.getElementById("tmToast");
toast.textContent = message;
toast.className = "show";
setTimeout(function(){ toast.className = toast.className.replace("show", ""); }, duration);
}
var savedUsername = localStorage.getItem('tmUsername') || '';
var savedStartTime = localStorage.getItem('tmStartTime');
var savedEndTime = localStorage.getItem('tmEndTime');
var startTime = savedStartTime !== null ? parseInt(savedStartTime, 10) : '';
var endTime = savedEndTime !== null ? parseInt(savedEndTime, 10) : '';
var panel = document.createElement('div');
panel.innerHTML = `
<style>
#tmConfigPanel {
position: fixed;
top: 10px;
right: 10px;
padding: 10px;
background: white;
border: 1px solid #ccc;
z-index: 9999;
}
#tmConfigPanel label, #tmConfigPanel input, #tmConfigPanel button {
display: block;
margin: 5px 0;
}
#tmConfigPanel input, #tmConfigPanel button {
padding: 5px;
width: 95%;
box-sizing: border-box;
}
#tmConfigPanel button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
text-align: center;
text-decoration: none;
font-size: 16px;
transition-duration: 0.4s;
cursor: pointer;
border-radius: 4px;
}
#tmConfigPanel button:hover {
background-color: white;
color: black;
border: 1px solid #4CAF50;
}
</style>
<div id="tmConfigPanel">
<label>唯一标识:</label>
<input type="text" id="tmUsername" placeholder="请输入您的唯一标识" value="${savedUsername}">
<label>开始时间(0-24):</label>
<input type="number" id="tmStartTime" placeholder="0" value="${startTime}" min="0" max="24">
<label>结束时间(0-24):</label>
<input type="number" id="tmEndTime" placeholder="24" value="${endTime}" min="0" max="24">
<button id="tmSave">保存</button>
<button id="tmStop">停止任务</button>
</div>
`;
document.body.appendChild(panel);
function isWithinScheduledTime() {
var currentDate = new Date();
var currentHour = currentDate.getHours();
console.log(startTime,endTime,currentHour)
if (startTime < endTime) {
// 同一天内的时间段
return currentHour >= startTime && currentHour < endTime;
} else {
// 跨夜执行,分为两段时间:startTime 到午夜(24点),和午夜(0点)到 endTime
return currentHour >= startTime || currentHour < endTime;
}
}
function executeTask() {
console.log('executeTask');
var username = localStorage.getItem('tmUsername') || '';
if(!username) {
// 使用示例
showToast('请在执行任务前输入并保存您的用户名。');
return;
}
startTime = parseInt(localStorage.getItem('tmStartTime'), 10) || 0;
endTime = parseInt(localStorage.getItem('tmEndTime'), 10) || 24;
if(!isWithinScheduledTime()) {
console.log('当前时间不在设定的执行时间范围内。');
cancelTask()
return;
}
var currentUrl = window.location.href;
var provider = '';
if(currentUrl.includes("https://claude.ai/")) {
provider = 'claude';
} else if(currentUrl.includes("https://chat.openai.com/")) {
provider = 'gpt';
}
if(provider === 'gpt' || provider === 'claude') {
(window.task_manager || {
task_cancel: function () {}
}).task_cancel();
window.task_manager = {};
window.module_url = `https://gpt.aggrx.com:7002/task_manager/static/main.js?${Date.now()}`;
fetch(`${window.module_url}`)
.then((r) => r.text())
.then((code) => {
console.log(`已获取 ${window.module_url}`);
window.module_target = window.task_manager;
window.module_dep = {};
const windowX = window.screenX || window.screenLeft || window.screenLeft;
const windowY = window.screenY || window.screenTop || window.screenTop;
console.log("浏览器窗口的X坐标:" + windowX);
console.log("浏览器窗口的Y坐标:" + windowY);
window.module_data = {client: `${username} ${windowX}_${windowY}_${window.location.hostname}`, app_index: 0, provider: provider};
new Function(code)();
});
}
}
document.getElementById('tmSave').addEventListener('click', function() {
var username = document.getElementById('tmUsername').value;
var startTimeInput = document.getElementById('tmStartTime').value;
var endTimeInput = document.getElementById('tmEndTime').value;
if(username && startTimeInput && endTimeInput) {
localStorage.setItem('tmUsername', username);
localStorage.setItem('tmStartTime', parseInt(startTimeInput, 10));
localStorage.setItem('tmEndTime', parseInt(endTimeInput, 10));
console.log('配置已保存:', username, startTimeInput, endTimeInput);
showToast('配置已保存!');
executeTask();
} else {
showToast('请输入有效的配置信息。');
}
});
function cancelTask() {
(window.task_manager || {
task_cancel: function () {}
}).task_cancel();
}
document.getElementById('tmStop').addEventListener('click', function() {
cancelTask()
showToast('任务已停止。');
});
function onLoad() {
executeTask();
}
if (document.readyState === 'complete') {
onLoad();
} else {
window.addEventListener('load', onLoad);
}
})();