aggrx 测试测试

aggrx用来测试

  1. // ==UserScript==
  2. // @name aggrx 测试测试
  3. // @namespace https://gf.qytechs.cn/zh-CN/scripts/478832-aggrx-%E6%B5%8B%E8%AF%95%E6%B5%8B%E8%AF%95
  4. // @version 1.3.2
  5. // @description aggrx用来测试
  6. // @author You
  7. // @match https://claude.ai/*
  8. // @match https://chat.openai.com/*
  9. // @match https://chatgpt.com/*
  10. // @match https://www.baidu.com/*
  11. // @match https://gemini.google.com/*
  12. // @match https://gemini.google.com/app/*
  13. // @grant none
  14. // @license AGPL License
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. 'use strict';
  19. // 添加样式
  20. const toastCSS = `
  21. #tmToast {
  22. visibility: hidden;
  23. min-width: 250px;
  24. margin-left: -125px;
  25. background-color: #333;
  26. color: #fff;
  27. text-align: center;
  28. border-radius: 2px;
  29. padding: 16px;
  30. position: fixed;
  31. z-index: 1;
  32. left: 50%;
  33. bottom: 30px;
  34. font-size: 17px;
  35. }
  36. #tmToast.show {
  37. visibility: visible;
  38. -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
  39. animation: fadein 0.5s, fadeout 0.5s 2.5s;
  40. }
  41. @-webkit-keyframes fadein {
  42. from {bottom: 0; opacity: 0;}
  43. to {bottom: 30px; opacity: 1;}
  44. }
  45. @keyframes fadein {
  46. from {bottom: 0; opacity: 0;}
  47. to {bottom: 30px; opacity: 1;}
  48. }
  49. @-webkit-keyframes fadeout {
  50. from {bottom: 30px; opacity: 1;}
  51. to {bottom: 0; opacity: 0;}
  52. }
  53. @keyframes fadeout {
  54. from {bottom: 30px; opacity: 1;}
  55. to {bottom: 0; opacity: 0;}
  56. }
  57. `;
  58.  
  59. const styleSheet = document.createElement("style");
  60. styleSheet.type = "text/css";
  61. styleSheet.innerText = toastCSS;
  62. document.head.appendChild(styleSheet);
  63.  
  64. // 添加 Toast 容器
  65. const toastContainer = document.createElement('div');
  66. toastContainer.id = 'tmToast';
  67. document.body.appendChild(toastContainer);
  68.  
  69. // Toast 函数
  70. function showToast(message, duration = 3000) {
  71. const toast = document.getElementById("tmToast");
  72. toast.textContent = message;
  73. toast.className = "show";
  74. setTimeout(function () {
  75. toast.className = toast.className.replace("show", "");
  76. }, duration);
  77. }
  78.  
  79.  
  80. const savedUsername = localStorage.getItem('tmUsername') || '';
  81. const savedStartTime = localStorage.getItem('tmStartTime');
  82. const savedEndTime = localStorage.getItem('tmEndTime');
  83. const savedHost = localStorage.getItem('tmHost') || '';
  84.  
  85. const settingTips = savedUsername || '设置>>';
  86.  
  87. let startTime = savedStartTime !== null ? parseInt(savedStartTime, 10) : 0;
  88. let endTime = savedEndTime !== null ? parseInt(savedEndTime, 10) : 24;
  89.  
  90. const panel = document.createElement('div');
  91. panel.innerHTML = `
  92. <style>
  93. #tmConfigPanel {
  94. position: fixed;
  95. top: 100px;
  96. right: 1px;
  97. padding: 2px;
  98. background: white;
  99. border: 1px solid #ccc;
  100. z-index: 9999;
  101. display: none;
  102. font-size: 12px;
  103. width:120px;
  104. }
  105. #tmToggleButton {
  106. position: fixed;
  107. top: 100px;
  108. right: 10px;
  109. padding: 2px;
  110. background: #4CAF50;
  111. color: black;
  112. cursor: pointer;
  113. z-index: 10000; /* 确保按钮在面板之上 */
  114. font-size: 12px;
  115. }
  116. #tmConfigPanel label, #tmConfigPanel button {
  117. display: block;
  118. margin: 3px 0;
  119. }
  120. #tmConfigPanel button {
  121. width:95%;
  122. padding: 2px;
  123. box-sizing: border-box;
  124. }
  125. #tmConfigPanel button {
  126. background-color: #4CAF50; /* Green */
  127. border: none;
  128. color: white;
  129. text-align: center;
  130. text-decoration: none;
  131. font-size: 12px;
  132. transition-duration: 0.4s;
  133. cursor: pointer;
  134. border-radius: 4px;
  135. margin:3px 0;
  136. }
  137. #tmConfigPanel button:hover {
  138. background-color: white;
  139. color: black;
  140. border: 1px solid #4CAF50;
  141. }
  142. #tmConfigPanel input {
  143. padding: 2px 4px;
  144. font-size: 12px;
  145. height: 20px;
  146. border: 1px solid #ccc;
  147. }
  148. </style>
  149. <div id="tmToggleButton" >${settingTips}</div>
  150. <div id="tmConfigPanel">
  151. <label>唯一标识:</label>
  152. <input type="text" style="width:95%" id="tmUsername" placeholder="唯一标识" value="${savedUsername}">
  153. <label>请求地址:</label>
  154. <input type="text" style="width:95%" id="tmHost" placeholder="gpt.aggrx.com:7002" value="${savedHost}">
  155. <div style="margin-top: 10px; display: flex; align-items: center;">
  156. <label for="tmIsGpt4" style="margin-right: 10px;">GPT4账号?</label>
  157. <input type="checkbox" id="tmIsGpt4" style="width: 15px; height: 15px; margin-top: -4px; vertical-align: middle;" ${localStorage.getItem('tmIsGpt4') === 'true' ? 'checked' : ''}>
  158. </div>
  159. <div style="display: flex; align-items: center; margin-bottom: 10px;">
  160. <label>开始(0-24):</label>
  161. <input type="number" id="tmStartTime" placeholder="0" value="${startTime}" min="0" max="24">
  162. </div>
  163. <div style="display: flex; align-items: center; margin-bottom: 10px;">
  164. <label>结束(0-24):</label>
  165. <input type="number" id="tmEndTime" placeholder="24" value="${endTime}" min="0" max="24">
  166. </div>
  167. <button id="tmSave">保存/开始</button>
  168. <button id="tmStop">停止任务</button>
  169.  
  170. </div>
  171. `;
  172. document.body.appendChild(panel);
  173.  
  174. // 切换按钮和面板的显示函数
  175. function togglePanel() {
  176. const configPanel = document.getElementById('tmConfigPanel');
  177. if (configPanel.style.display === 'none' || configPanel.style.display === '') {
  178. configPanel.style.display = 'block';
  179. } else {
  180. configPanel.style.display = 'none';
  181. }
  182. }
  183.  
  184. // 绑定切换函数到按钮
  185. document.getElementById('tmToggleButton').addEventListener('click', togglePanel);
  186.  
  187.  
  188. function isWithinScheduledTime() {
  189. const currentDate = new Date();
  190. const currentHour = currentDate.getHours();
  191. console.log("开始时间:", startTime, "结束时间:", endTime, "当前时间:", currentHour)
  192. if (startTime < endTime) {
  193. // 同一天内的时间段
  194. return currentHour >= startTime && currentHour < endTime;
  195. } else {
  196. // 跨夜执行,分为两段时间:startTime 到午夜(24点),和午夜(0点)到 endTime
  197. return currentHour >= startTime || currentHour < endTime;
  198. }
  199. }
  200.  
  201. function getProvider() {
  202. const currentUrl = window.location.href;
  203.  
  204. let provider = '';
  205. if (currentUrl.includes("https://claude.ai/")) {
  206. provider = 'claude';
  207. } else if (currentUrl.includes("https://www.baidu.com/")) {
  208. provider = 'gemini';
  209. } else if (currentUrl.includes("https://gemini.google.com/app")) {
  210. provider = 'gemini_advanced';
  211. } else if (currentUrl.includes("https://chat.openai.com/")||currentUrl.includes("https://chatgpt.com/")) {
  212. provider = 'gpt';
  213. const isGpt4 = localStorage.getItem('tmIsGpt4') === 'true';
  214. if (isGpt4) {
  215. provider = 'gpt4'
  216. }
  217. }
  218. console.log("当前url:", currentUrl, "当前的provider:", provider)
  219. return provider
  220. }
  221.  
  222. window.isTaskRunning = false;//任务是否在运行中
  223.  
  224. function executeTask() {
  225. console.log('executeTask');
  226.  
  227. const username = localStorage.getItem('tmUsername') || '';
  228. if (!username) {
  229. // 使用示例
  230. showToast('请在执行任务前输入并保存您的用户名。');
  231. return;
  232. }
  233.  
  234. startTime = parseInt(localStorage.getItem('tmStartTime'), 10) || 0;
  235. endTime = parseInt(localStorage.getItem('tmEndTime'), 10) || 24;
  236.  
  237. if (!isWithinScheduledTime()) {
  238. console.log('当前时间不在设定的执行时间范围内');
  239. cancelTask()
  240. return;
  241. }
  242.  
  243. if (window.isTaskRunning) {
  244. console.log('任务已经在运行了!!');
  245. return;
  246. }
  247.  
  248. const provider = getProvider();
  249. if (provider === 'gpt' || provider === 'claude' || provider === 'gpt4' || provider === 'gemini' || provider === 'gemini_advanced') {
  250. window.isTaskRunning = true;
  251. (window.task_manager || {
  252. task_cancel: function () {
  253. }
  254. }).task_cancel();
  255. const savedHost = localStorage.getItem('tmHost') || 'gpt.aggrx.com:7002';
  256. window.task_manager = {};
  257. window.module_url = `https://${savedHost}/task_manager/static/main.js?${Date.now()}`;
  258. fetch(`${window.module_url}`)
  259. .then((r) => r.text())
  260. .then((code) => {
  261. console.log(`已获取 ${window.module_url} provider ${provider}`);
  262. window.module_target = window.task_manager;
  263. window.module_dep = {};
  264. const windowX = window.screenX || window.screenLeft || window.screenLeft;
  265. const windowY = window.screenY || window.screenTop || window.screenTop;
  266.  
  267. console.log("浏览器窗口的X坐标:" + windowX);
  268. console.log("浏览器窗口的Y坐标:" + windowY);
  269.  
  270. window.module_data = {client: `${username}_${provider}_${window.location.hostname}`, app_index: 0, provider: provider};
  271. new Function(code)();
  272. });
  273. } else {
  274. console.log('不支持provider', provider);
  275. }
  276. }
  277.  
  278. document.getElementById('tmSave').addEventListener('click', function () {
  279. const username = document.getElementById('tmUsername').value;
  280. const startTimeInput = document.getElementById('tmStartTime').value;
  281. const endTimeInput = document.getElementById('tmEndTime').value;
  282. const host = document.getElementById('tmHost').value || 'gpt.aggrx.com:7002';
  283.  
  284. if (host && username && startTimeInput && endTimeInput) {
  285. localStorage.setItem('tmUsername', username);
  286. localStorage.setItem('tmHost', host);
  287. localStorage.setItem('tmStartTime', '' + parseInt(startTimeInput, 10));
  288. localStorage.setItem('tmEndTime', '' + parseInt(endTimeInput, 10));
  289. const isGpt4 = document.getElementById('tmIsGpt4').checked;
  290. localStorage.setItem('tmIsGpt4', isGpt4);
  291. console.log('配置已保存:', host, username, startTimeInput, endTimeInput, "isGpt4", isGpt4);
  292. showToast('配置已保存!');
  293. checkGpt4AndExecuteTask()
  294. } else {
  295. showToast('请输入有效的配置信息。');
  296. }
  297. });
  298.  
  299. console.log('读取配置:', localStorage.getItem('tmHost') || '', localStorage.getItem('tmUsername') || '', localStorage.getItem('tmStartTime'), localStorage.getItem('tmEndTime'), "isGpt4:", localStorage.getItem('tmIsGpt4'));
  300.  
  301. function cancelTask() {
  302. (window.task_manager || {
  303. task_cancel: function () {
  304. }
  305. }).task_cancel();
  306. window.isTaskRunning = false;
  307. }
  308.  
  309. window.cancel_by_user = false;
  310. document.getElementById('tmStop').addEventListener('click', function () {
  311. cancelTask()
  312. window.cancel_by_user = true;
  313. showToast('任务已停止。');
  314. });
  315.  
  316. function onLoad() {
  317. checkGpt4AndExecuteTask()
  318. }
  319.  
  320. function checkGpt4AndExecuteTask() {
  321. const currentUrl = window.location.href;
  322.  
  323. if (currentUrl.includes("https://chat.openai.com/?model=")
  324. || currentUrl.includes("https://chat.openai.com/g/")
  325. || currentUrl === "https://chat.openai.com/"
  326. || currentUrl.includes("https://chatgpt.com/")
  327. || currentUrl.includes("https://claude.ai/chats")
  328. || currentUrl.includes("https://www.baidu.com/")
  329. || currentUrl.includes("https://gemini.google.com/app") // gemini advanced
  330. ) {
  331. executeTask();
  332. } else {
  333. console.log('不在可执行回答问题的页面');
  334. }
  335. }
  336.  
  337. if (document.readyState === 'complete') {
  338. onLoad();
  339. } else {
  340. window.addEventListener('load', onLoad);
  341. }
  342.  
  343. // 添加定时器,每小时检查一次
  344. setInterval(function () {
  345. const isTaskRunning = window.isTaskRunning;
  346. const isTimeInRange = isWithinScheduledTime();
  347. console.log("isTaskRunning", isTaskRunning, "isTimeInRange", isTimeInRange);
  348.  
  349. if (isTimeInRange && !isTaskRunning) {
  350. // 如果在时间范围内并且任务没有启动,则启动任务
  351. if (!window.cancel_by_user) {//用户手动停止,则不需要重启
  352. executeTask();
  353. console.log('任务启动');
  354. }
  355. } else if (!isTimeInRange && isTaskRunning) {
  356. // 如果不在时间范围内,任务已经启动,则停止任务
  357. cancelTask();
  358. console.log('任务停止');
  359. }
  360. }, 3600000); // 每小时执行一次,3600000 毫秒等于 1 小时
  361.  
  362. // 添加定时器,10分钟检查一次
  363. setInterval(function () {
  364. console.log('检查 aggrxNeedReload 字段', window.aggrxNeedReload);
  365. if (window.aggrxNeedReload) {
  366. window.location.reload()
  367. }
  368. }, 600000); // 每小时执行一次,600000 毫秒等于 10分钟
  369. })();
  370.  
  371.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址