From cac1872890fae3256535a64a1712e36990b44b04 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 4 Aug 2021 22:52:04 +0200 Subject: Update the "Last edit" tooltip with a `MutationObserver` Use a `MutationObserver` to update the tooltip. This allows us to update the tooltip after the page and user script have fully loaded, and then the label gets populated. It also should allow us to capture updates to the label and update the tooltip accordingly. --- google-docs-last-edit-label.user.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/google-docs-last-edit-label.user.js b/google-docs-last-edit-label.user.js index 64b3f1d..9ae9ec5 100644 --- a/google-docs-last-edit-label.user.js +++ b/google-docs-last-edit-label.user.js @@ -3,7 +3,6 @@ // @description Show a tooltip when hovering over the last edit time label // @namespace com.teddywing // @version 0.0.1 -// @run-at document-idle // @match https://docs.google.com/* // ==/UserScript== @@ -23,5 +22,23 @@ // along with this program. If not, see . +var observer = new MutationObserver( + function(mutation_list) { + for (var i = 0; i < mutation_list.length; i++) { + var mutation = mutation_list[i]; + var last_edit_label = mutation.target; + + last_edit_label.setAttribute('title', last_edit_label.textContent); + + return; + } + } +); + var last_edit_label = document.querySelector('.docs-title-save-label-text'); -last_edit_label.setAttribute('title', last_edit_label.textContent); +observer.observe( + last_edit_label, + { + childList: true + } +); -- cgit v1.2.3