diff options
author | Teddy Wing | 2021-08-04 22:52:04 +0200 |
---|---|---|
committer | Teddy Wing | 2021-08-04 22:52:04 +0200 |
commit | cac1872890fae3256535a64a1712e36990b44b04 (patch) | |
tree | ad729029c961b4b09fae0358b30613b96b0fa1c4 /google-docs-last-edit-label.user.js | |
parent | b29b2ad1ca4d95a2f57ce567b05ee576737aff05 (diff) | |
download | google-docs-last-edit-label-cac1872890fae3256535a64a1712e36990b44b04.tar.bz2 |
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.
Diffstat (limited to 'google-docs-last-edit-label.user.js')
-rw-r--r-- | google-docs-last-edit-label.user.js | 21 |
1 files 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 <https://www.gnu.org/licenses/>. +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 + } +); |