Fix Outlook Mac Hotkeys Hijacking

Disables Outlook from highjacking Mac keyboard shortcuts

目前為 2024-10-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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/*
// @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();
     }
   */
}