Restore Revision Time Visual Text in Google Apps

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

当前为 2023-03-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Restore Revision Time Visual Text in Google Apps
// @version      1.0
// @description  Brings back visual last edit text in drive apps due to M3 migration by Google.
// @author       ZachTheDev and andersonaddo
// @match        https://docs.google.com/document*
// @match        https://docs.google.com/presentation*
// @match        https://docs.google.com/spreadsheets*
// @icon         https://cdn-icons-png.flaticon.com/512/1674/1674929.png
// @namespace gdocsrestoreupdatetimestamp
// ==/UserScript==

(function () {
  function addBackRevisionVisualText() {
    const revisionButtonElement = document.getElementById("docs-revisions-appbarbutton");
    var textFromRevisionButtonElement = revisionButtonElement.getAttribute("ariel-label");
    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(revisionVisualTextHTML);
    menubarElement.appendChild(fragmentForRevisionVisualTextHTML);
    const revisionVisualTextElement = document.getElementById("revisionVisualText");


    function callback() {
      console.log(revisionButtonElement.dataset.tooltip)
      textFromRevisionButtonElement = revisionButtonElement.getAttribute("data-tooltip");
      revisionVisualTextElement.innerHTML = textFromRevisionButtonElement;
    }

    const observer = new MutationObserver(callback);
    observer.observe(revisionButtonElement, {
      attributeFilter: ["tooltip", "data-tooltip"],
      attributeOldValue: true,
    });

    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();
})();