ffactory / Outlook: Block Alt / Option Navigation

// ==UserScript==
// @name         Outlook: Block Alt / Option Navigation
// @namespace    http://tampermonkey.net/
// @version      2024-12-02
// @description  Intercept Alt/Option presses, keep focus on the Outlook editor
// @author       ffactory
// @updateURL https://openuserjs.org/meta/ffactory/Outlook_Block_Alt_Option_Navigation.meta.js
// @downloadURL https://openuserjs.org/install/ffactory/Outlook_Block_Alt_Option_Navigation.user.js
// @run-at       document-start
// @match        https://outlook.live.com/mail/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=live.com
// @grant        none
// @copyright    2024, ffactory (https://openuserjs.org/users/ffactory)
// @license      MIT
// ==/UserScript==

'use strict';

function suppress(event) {
  if (event.code == 'AltLeft') {
    console.log("Suppressed keyboard shortcut:", event.key);
    event.stopImmediatePropagation();
  }
}

function addListener(el) {
  console.log("Suppressing keyboard shortcuts on element");

  // Run during capturing phase to intercept the event before bubbling phase
  el.addEventListener(
    'keyup', suppress, true
  );
  el.addEventListener(
    'keydown', suppress, true
  );
}

addListener(document);