Skip to content

Instantly share code, notes, and snippets.

@derac
Last active November 15, 2022 01:37
Show Gist options
  • Save derac/887efd8891caa026322b76249548931f to your computer and use it in GitHub Desktop.
Save derac/887efd8891caa026322b76249548931f to your computer and use it in GitHub Desktop.
workaround for the emoji menu after space-colon issue in google docs
// ==UserScript==
// @name Auto-close emoji menu
// @version 1.0
// @description Auto-close emoji menu
// @author You
// @match https://docs.google.com/document/d/*/edit
// @grant none
// ==/UserScript==
(function() {
'use strict';
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
waitForElm('.apps-search-popup-menu')
.then((elm) => {
var popup_menu = document.querySelector('.apps-search-popup-menu')
//identity an element to observe
const myListObserver = document.querySelector(".apps-search-popup-menu");
//a callback that runs when the observer is triggered
const observer = new MutationObserver(function(el) {
if (Array.isArray(el)) {
console.log(el[0].target.attributes.style)
}
else {
console.log(el.target.attributes.style)
}
});
//passing element to observer function, and `options`
observer.observe(myListObserver, {childList: false, attribute: true, attributeFilter:['style']});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment