Greasy Fork is available in English.

Keep Kaggle Notebook Alive

Keep the Kaggle Notebook alive by simulating user activity

질문, 리뷰하거나, 이 스크립트를 신고하세요.
  1. // ==UserScript==
  2. // @name Keep Kaggle Notebook Alive
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Keep the Kaggle Notebook alive by simulating user activity
  6. // @author liuweiqing
  7. // @match https://www.kaggle.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. "use strict";
  14.  
  15. // 每隔5分钟模拟一次点击事件,以保持Kaggle Notebook的活动状态
  16. function keepAlive() {
  17. console.log("Keeping the Kaggle Notebook alive...");
  18. const addButton = document.querySelector('button[aria-label="Add cell"]');
  19. if (addButton) {
  20. addButton.click(); // 模拟点击添加单元格按钮
  21. }
  22. const runButton = document.querySelector(
  23. 'button[aria-label="Run current cell"]'
  24. );
  25. if (runButton) {
  26. runButton.click(); // 模拟点击运行单元格按钮
  27. }
  28. const cutButton = document.querySelector('button[aria-label="Cut cell"]');
  29. if (cutButton) {
  30. cutButton.click(); // 模拟点击删除单元格按钮
  31. }
  32.  
  33. // 随机生成几分钟的间隔
  34. const randomInterval =
  35. Math.floor(Math.random() * (100000 - 50000 + 1)) + 240000;
  36. console.log(`Next execution in ${randomInterval} milliseconds.`);
  37.  
  38. // 重新设置定时器
  39. setTimeout(keepAlive, randomInterval);
  40. }
  41.  
  42. // 首次调用
  43. keepAlive();
  44. // 300000 毫秒 = 5 分钟
  45. // 这种形式已经无法触发任何按键了
  46. // const ctrlEnterEvent = new KeyboardEvent("keydown", {
  47. // bubbles: true,
  48. // cancelable: true,
  49. // key: "Enter",
  50. // code: "Enter",
  51. // location: 0,
  52. // ctrlKey: true, // 表示 Ctrl 键被按下
  53. // repeat: false,
  54. // });
  55. // document.dispatchEvent(EnterEvent);
  56. })();