Close google docs tab UI automatically

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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
    }
}