colab 保持活跃 / make colab keep alive

make colab keep alive

  1. // ==UserScript==
  2. // @name colab 保持活跃 / make colab keep alive
  3. // @name:zh colab 保持活跃
  4. // @name:en colab keep alive
  5. // @name:zh-CN 使 colab 保持活跃
  6. // @name:ja colab アクティブに保存
  7. // @namespace https://colab.research.google.com
  8. // @version 2.0
  9. // @description:zh 让colab 保存活跃
  10. // @description:en make colab keep alive
  11. // @description:zh-CN 让 colab 保存活跃
  12. // @description:ja Google colab アクティブに保存
  13. // @author Epool, WangZha
  14. // @match *://colab.research.google.com/*
  15. // @grant none
  16. // @license MIT
  17. // @description make colab keep alive
  18. // ==/UserScript==
  19.  
  20. // 定义保持活跃的行为
  21. var timeOutIds = []
  22. function keep_active() {
  23. 'use strict';
  24.  
  25. // 定义行为
  26. function ClickConnect(){
  27. colab.config
  28. console.log("Connnect Clicked - Start");
  29. document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click();
  30. console.log("Connnect Clicked - End");
  31. }
  32.  
  33. // 设置随机行为时间
  34. var max = 120490
  35. var min = 60010
  36. var randomTime = [];
  37. var currentIndex = 0;
  38. var nextInterval
  39.  
  40. function runInterval() {
  41. // 执行你的操作
  42. ClickConnect();
  43.  
  44. // 添加下一个随机时间
  45. randomTime.push(parseInt(Math.random()*(max-min+1)+min,10))
  46.  
  47. // 下一个调用的时间间隔为时间序列中的下一个值
  48. nextInterval = randomTime[currentIndex];
  49. console.log(`下一次行动${nextInterval}`)
  50.  
  51. // 更新索引
  52. currentIndex++;
  53.  
  54. // 使用 setTimeout 函数递归调用,以达到动态更改时间间隔的目的
  55. timeOutIds.push(setTimeout(runInterval, nextInterval));
  56. }
  57.  
  58. // 第一次调用使用时间序列中的第一个值
  59. timeOutIds.push(setTimeout(runInterval, 5000));
  60. }
  61.  
  62. // 创建 button 元素
  63. var button = document.createElement('button');
  64. button.id = 'floating-button';
  65. button.innerText = '保持活跃';
  66.  
  67. // 创建 style 标签,设置样式
  68. var style = document.createElement('style');
  69. style.innerHTML = `
  70. #floating-button {
  71. position: fixed;
  72. bottom: 20px;
  73. right: 20px;
  74. width: 75px;
  75. height: 35px;
  76. background-color: #ccc;
  77. color: #fff;
  78. border-radius: 23%;
  79. text-align: center;
  80. line-height: 20px;
  81. cursor: pointer;
  82. z-index: 999;
  83. }
  84.  
  85. #floating-button.active {
  86. background-color: #007bff;
  87. }
  88. `;
  89.  
  90. // 添加按钮事件监听器和 run 函数
  91. var isActive = false;
  92.  
  93. button.addEventListener('mousedown', function(event) {
  94. var offsetX = event.clientX - button.offsetLeft;
  95. var offsetY = event.clientY - button.offsetTop;
  96.  
  97. function moveButton(event) {
  98. button.style.left = (event.clientX - offsetX) + 'px';
  99. button.style.top = (event.clientY - offsetY) + 'px';
  100. }
  101.  
  102. document.addEventListener('mousemove', moveButton);
  103.  
  104. button.addEventListener('mouseup', function() {
  105. document.removeEventListener('mousemove', moveButton);
  106. });
  107. });
  108.  
  109. button.addEventListener('click', function() {
  110. isActive = !isActive;
  111. if (isActive) {
  112. button.classList.add('active');
  113. keep_active();
  114. } else {
  115. button.classList.remove('active');
  116. timeOutIds.forEach(function(id){clearTimeout(id);})
  117. console.log(`清楚任务${timeOutIds}`)
  118. timeOutIds = []
  119. }
  120. });
  121.  
  122. // 添加元素到工具栏
  123. setTimeout(function(){
  124. var topToolbar = document.getElementById('top-toolbar')
  125. console.log(topToolbar)
  126. if (topToolbar){
  127. console.log("开始添加元素")
  128. topToolbar.appendChild(button);
  129. document.head.appendChild(style);
  130. console.log("添加完成")
  131. }
  132. },5000);

QingJ © 2025

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