Fix underscores in Outlook

Stops underscores from being converted into italics in the Outlook message editor.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Fix underscores in Outlook
// @namespace    http://tampermonkey.net/
// @author       yotann
// @version      0.1
// @license      CC-PDDC
// @description  Stops underscores from being converted into italics in the Outlook message editor.
// @match        https://outlook.office.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function hookPrototype(prototype, overrides) {
        // Set the prototype of the overrides, so `super` refers to an unmodified copy of the original prototype.
        Object.setPrototypeOf(overrides, Object.create(Object.getPrototypeOf(prototype), Object.getOwnPropertyDescriptors(prototype)));
        Object.defineProperties(prototype, Object.getOwnPropertyDescriptors(overrides));
    }

    // Javascript modules are lazily loaded using webpack chunks.
    // Detect when a new chunk is loaded, so we can find the module that includes MarkdownPlugin.
    hookPrototype(globalThis.webpackChunkOwa, {
        push(array) {
            const moduleConstructors = array[1];
            Object.entries(moduleConstructors).forEach(([id, originalModuleConstructor]) => {
                moduleConstructors[id] = function(module, exports, exporter) {
                    originalModuleConstructor.apply(this, arguments);
                    if (exports.hasOwnProperty('MarkdownPlugin')) {
                        console.log('Patching MarkdownPlugin');
                        hookPrototype(exports.MarkdownPlugin.prototype, {
                            initialize(editor) {
                                super.initialize(editor);
                                this.options.italic = false; // "_"
                                // this.options.bold = false; // "*"
                                // this.options.strikethrough = false; // "~"
                                // this.options.codeFormat = false; // "`"
                            }
                        });
                    }
                };
            });
            super.push(array);
        }
    });
})();