slashP / Delete/cancel/save shortcuts in map maker

// ==UserScript==
// @name         Delete/cancel/save shortcuts in map maker
// @namespace    http://tampermonkey.net/
// @version      0.1
// @author       slashP
// @match        https://www.geoguessr.com/*
// @icon         https://www.google.com/s2/favicons?domain=geoguessr.com
// @description  Shift-d for delete, s for Save and c for Cancel. Delete key also works.
// @license      MIT
// @grant        none
// ==/UserScript==

(function () {
  'use strict';
  const tryAddActions = () => {
    setTimeout(() => {
      if (new RegExp('^https:\/\/www.geoguessr.com\/map-maker').test(window.location.href)) {
        // shift+d = delete
        // shift+c = cancel
        // shift+s = save
        document.onkeydown = function (e) {
          if (e.shiftKey) {
            const key = e.key?.toLowerCase();
            switch (key) {
              case "d": document.querySelector(".streetview-panel__header .button--danger")?.click();
                break;
              case "s": document.querySelector(".streetview-panel__controls .button--primary")?.click();
                break;
              case "c": document.querySelector(".streetview-panel__controls .button--secondary")?.click();
                break;
              default: break;
            }
          }
          else if (e.key === "Delete") {
            document.querySelector(".streetview-panel__header .button--danger")?.click();
          }
        };

        document.on
      }
    }, 250);
  }

  let lastUrl = location.href;
  new MutationObserver(() => {
    const url = location.href;
    if (url !== lastUrl) {
      lastUrl = url;
      tryAddActions();
    }
  }).observe(document, { subtree: true, childList: true });
  tryAddActions();
})();