Saved place note: Ctrl+Enter to submit

Ctrl+Enter to submit on the popup for adding a note to a saved place.

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         Saved place note: Ctrl+Enter to submit
// @description  Ctrl+Enter to submit on the popup for adding a note to a saved place.
// @namespace    https://github.com/nate-kean/
// @version      20251020
// @author       Nate Kean
// @match        https://www.google.com/maps*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// @license      MIT
// ==/UserScript==

(async function() {
    function delay(ms) {
        return new Promise((resolve) => setTimeout(resolve, ms));
    }

    async function waitForElement(selector, pollingRateMs=100, parent=document) {
        let el;
        while (true) {
            el = parent.querySelector(selector);
            if (el) return el;
            await delay(pollingRateMs);
        }
    }

    async function elementGone(selector, pollingRateMs=100, parent=document) {
        let el;
        while (true) {
            el = parent.querySelector(selector);
            if (!el) return;
            await delay(pollingRateMs);
        }
    }


    while (true) {
        const el = await waitForElement("textarea.sbPorb.gRsCne.azQIhc");
        el.addEventListener("keypress", (evt) => {
            if (evt.keyCode === 10 && evt.ctrlKey) {
                document.querySelector("button.okDpye.PpaGLb.mta2Ab").click();
            }
        });
        await elementGone("textarea.sbPorb.gRsCne.azQIhc");
    }
})();