Outlook Mail 邊框調整,添加快捷鍵

邊框調整,添加快捷鍵(Del鍵刪除信件,方向鍵左右上下一封信)

当前为 2025-07-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         Outlook Mail 邊框調整,添加快捷鍵
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  邊框調整,添加快捷鍵(Del鍵刪除信件,方向鍵左右上下一封信)
// @author       Shanlan
// @match        https://outlook.office.com/mail/*
// @match        https://outlook.office365.com/mail/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

setTimeout(function () {
    const InputName = document.getElementsByClassName("Yd48r")[0];
    if (InputName) InputName.setAttribute('data-min-width', '198'); // 左邊條寬度縮小
    const InputName2 = document.getElementsByClassName("h2KSz")[2];
    if (InputName2) InputName2.setAttribute('data-min-width', '102'); // 日期條寬度縮小
}, 3000);

// 左鍵切換前一個
document.addEventListener("keydown", function(event) {
    if (event.keyCode === 37) { // Left
        var btn = document.querySelector('button[title="開啟前一個項目"]');
        if (btn) btn.click();
    }
});

// 右鍵切換下一個
document.addEventListener("keydown", function(event) {
    if (event.keyCode === 39) { // Right
        var btn = document.querySelector('button[title="開啟下一個項目"]');
        if (btn) btn.click();
    }
});

// 新增:Del鍵觸發刪除,但在輸入框或可編輯區域時不生效
document.addEventListener("keydown", function(event) {
    if (event.key === "Delete") {
        const tgt = event.target;
        // 如果焦點在 INPUT、TEXTAREA 或任何 contenteditable 元素內,就跳過
        if (tgt.tagName === "INPUT" || tgt.tagName === "TEXTAREA" || tgt.isContentEditable) {
            return;
        }
        var btn = document.querySelector('button[name="刪除"], button[aria-label="刪除"]');
        if (btn && !btn.disabled && btn.getAttribute("aria-disabled") !== "true") {
            btn.click();
        }
    }
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址