Close google docs tab UI automatically

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Close google docs tab UI automatically
// @version      2025-01-12
// @description  Close google docs tab UI automatically (Left arrow button on lefthand side of page) by automatically closing it
// @match        *://*.docs.google.com/document/*
// @license MIT
// @namespace https://greasyfork.org/users/1422626
// ==/UserScript==


var interval = 2; // ms, how often the loop should run
var maxTime = 5000; // ms, max time to try to run the loop for

var startTime = new Date().getTime();
var checkTimer = setInterval(TimeLoop, interval);
checkTimer();

function TimeLoop() {
    const warning = document.getElementsByClassName("div.goog-flat-button.goog-inline-block.goog-flat-button-disabled"); //class of the button
    if (warning !== undefined){ //see if it exists yet
        var button = document.getElementsByClassName('goog-inline-block docs-material-gm-select miniChapterSwitcherView miniChapterSwitcherCollapsed');
        var evt = new MouseEvent('click');
        button[0].dispatchEvent(evt);
        clearInterval(checkTimer)

    }

    if (warning !== undefined){ //see if it exists yet
        button[0].dispatchEvent(evt);
        clearInterval(checkTimer)
    }
    if (new Date().getTime() - startTime > maxTime) {
        clearInterval(checkTimer); //kill the timer if the button hasnt shown after maxTime milliseconds
    }
}