WhatsApp Web 输入法 ESC 键优化

修复 WhatsApp Web 中文输入法 ESC 键冲突问题

// ==UserScript==
// @name         WhatsApp Web 输入法 ESC 键优化
// @name:en      WhatsApp Web IME ESC Key Fix
// @namespace    https://greasyfork.org/zh-CN/users/3001-hanjian-wu
// @version      0.1
// @description  修复 WhatsApp Web 中文输入法 ESC 键冲突问题
// @description:en  Fix ESC key conflict with IME input in WhatsApp Web
// @author       RoyWU
// @match        https://web.whatsapp.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    
    document.addEventListener('keydown', function(event) {
        // 检查是否是 ESC 键
        if (event.key === 'Escape') {
            // 检查当前是否有 IME 输入
            const isIMEInput = event.isComposing || event.keyCode === 229;
            
            // 如果是 IME 输入状态,阻止事件传播
            if (isIMEInput) {
                event.stopPropagation();
                event.preventDefault();
            }
        }
    }, true); // 使用捕获阶段
})();