Close google docs tab UI automatically

Close google docs tab UI automatically (Left arrow button on lefthand side of page) by automatically closing it

目前为 2025-01-13 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Close google docs tab UI automatically
  3. // @version 2025-01-12
  4. // @description Close google docs tab UI automatically (Left arrow button on lefthand side of page) by automatically closing it
  5. // @match *://*.docs.google.com/document/*
  6. // @license MIT
  7. // @namespace https://greasyfork.org/users/1422626
  8. // ==/UserScript==
  9.  
  10.  
  11. var interval = 2; // ms, how often the loop should run
  12. var maxTime = 5000; // ms, max time to try to run the loop for
  13.  
  14. var startTime = new Date().getTime();
  15. var checkTimer = setInterval(TimeLoop, interval);
  16. checkTimer();
  17.  
  18. function TimeLoop() {
  19. const warning = document.getElementsByClassName("div.goog-flat-button.goog-inline-block.goog-flat-button-disabled"); //class of the button
  20. if (warning !== undefined){ //see if it exists yet
  21. var button = document.getElementsByClassName('goog-inline-block docs-material-gm-select miniChapterSwitcherView miniChapterSwitcherCollapsed');
  22. var evt = new MouseEvent('click');
  23. button[0].dispatchEvent(evt);
  24. clearInterval(checkTimer)
  25.  
  26. }
  27.  
  28. if (warning !== undefined){ //see if it exists yet
  29. button[0].dispatchEvent(evt);
  30. clearInterval(checkTimer)
  31. }
  32. if (new Date().getTime() - startTime > maxTime) {
  33. clearInterval(checkTimer); //kill the timer if the button hasnt shown after maxTime milliseconds
  34. }
  35. }