Restore Revision Time Visual Text in Google Apps

Brings back visual last edit text in drive apps due to M3 migration by Google.

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 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         Restore Revision Time Visual Text in Google Apps
// @version      1.2
// @description  Brings back visual last edit text in drive apps due to M3 migration by Google.
// @author       ZachTheDev
// @match        https://docs.google.com/document*
// @match        https://docs.google.com/presentation*
// @match        https://docs.google.com/spreadsheets*
// @namespace https://greasyfork.org/users/1038934
// ==/UserScript==

(function() {
    function addBackRevisionVisualText() {
        const escapeHTMLPolicy = trustedTypes.createPolicy("use-raw-string", {
            createHTML: (string) => string,
        });
        const revisionButtonElement = document.getElementById("docs-revisions-appbarbutton");
        var revisionTextFromButton = revisionButtonElement.getAttribute("data-tooltip");
        const menubarElement = document.getElementById("docs-menubar");
        const revisionVisualTextHTML = "<div id=\"revisionVisualText\" class=\"menu-button goog-control goog-inline-block\" role=\"menuitem\" style=\"background-color: transparent;text-decoration: underline;\" data-tooltip=\"Open version history\"></div>";
        const rangeForRevisionVisualTextHTML = document.createRange();
        const fragmentForRevisionVisualTextHTML = rangeForRevisionVisualTextHTML.createContextualFragment(escapeHTMLPolicy.createHTML(revisionVisualTextHTML));
        menubarElement.appendChild(fragmentForRevisionVisualTextHTML);
        const revisionVisualTextElement = document.getElementById("revisionVisualText");
        const setAttributeWatcher = revisionButtonElement.setAttribute;
        revisionButtonElement.setAttribute = (key, value) => {
            revisionTextFromButton = revisionButtonElement.getAttribute("data-tooltip");
            revisionVisualTextElement.innerHTML = escapeHTMLPolicy.createHTML(revisionTextFromButton);
            setAttributeWatcher.call(revisionButtonElement, key, value);
        };
        revisionVisualTextElement.addEventListener("mousedown", function (event) {
            revisionButtonElement.dispatchEvent(new MouseEvent("mousedown"));
            revisionButtonElement.classList.remove("jfk-button-hover");
            revisionButtonElement.dispatchEvent(new MouseEvent("mouseup"));
            event.stopPropagation(); // fixes bug where menus would open on hover after first click of the revisionVisualTextElement
        });
        revisionButtonElement.addEventListener("mouseenter", (event) => {revisionButtonElement.classList.add("jfk-button-hover");}, false);
    }
    addBackRevisionVisualText();
})();