Fix Outlook Mac Hotkeys Hijacking

Disables Outlook from highjacking Mac keyboard shortcuts

当前为 2024-11-19 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           Fix Outlook Mac Hotkeys Hijacking
// @description    Disables Outlook from highjacking Mac keyboard shortcuts
// @copyright      2024, phonique (https://github.com/phonique/userscript-stop-outlook-hijack/)
// @homepageURL    https://github.com/phonique/userscript-stop-outlook-hijack
// @version        0.1.0
// @run-at         document-start
// @match          https://outlook.office.com/*
// @match          https://outlook.office365.com.mcas.ms/mail/*
// @grant          none
// @license        MPL-2.0
// @namespace https://greasyfork.org/users/1381446
// ==/UserScript==

// event codes for arrow keys.
var eventCodes = ["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"];

// Possible events: keypress, keyup, keydown
// currently Outlook seems to only require keydown and keyup.
// Only `keypress` is not enough to disable Alt-key hijacking.


// We enable useCapture here, because we want to capture the event while
// it's trickling down the DOM and then ignore other Listeners that hijack
// our default Alt functionality with our cancelBubble() and
// stopImmediatePropagation() calls.

window.addEventListener('keydown', handler, true); // useCapture true, i.e. we are capturing the event while it's trickling down
window.addEventListener('keyup', handler, true); // useCapture true
// window.addEventListener('keypress', handler, true); // we don't currently need this.

function handler (e) {
     // alert("eventCode: " + e.code + " eventKey: " + e.key); // debug here

     // If you want to completely disable Alt hijacking, not just in textboxes
     // uncomment the next and also comment out (or remove) the line following it.
     // if (e.code === "AltRight" || e.code === "AltLeft" || e.key === "Alt") {
     if ((e.code === "AltRight" || e.code === "AltLeft" || e.key === "Alt") && typeof(document.activeElement.role) !== 'undefined' && document.activeElement.role == 'textbox') {
         e.cancelBubble = true;
         e.stopImmediatePropagation();
     }
   /* // including previous UX-fixes
     if (eventCodes.indexOf(e.code) != -1 && e.shiftKey && e.altKey) {
         e.cancelBubble = true;
         e.stopImmediatePropagation();
     }
     if (eventCodes.indexOf(e.code) != -1 && e.altKey) {
         e.cancelBubble = true;
         e.stopImmediatePropagation();
     }
     if (eventCodes.indexOf(e.code) != -1 && e.shiftKey && e.metaKey) {
         e.cancelBubble = true;
         e.stopImmediatePropagation();
     }
     if (eventCodes.indexOf(e.code) != -1 && e.shiftKey && e.ctrlKey) {
         e.cancelBubble = true;
         e.stopImmediatePropagation();
     }
   */
}