Rewrite Microsoft Safe Links

Rewrites links starting with "https://*.safelinks.protection.outlook.com" to link to the website immediately. This feature comes from "Microsoft Defender for Office 365". Also disables any scanning for potential phishing sites, see also https://learn.microsoft.com/en-us/microsoft-365/security/office-365-security/safe-links-about?view=o365-worldwide

当前为 2023-09-07 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Rewrite Microsoft Safe Links
// @include     https://outlook.office.com/*
// @author      Pieter Bos
// @description Rewrites links starting with "https://*.safelinks.protection.outlook.com" to link to the website immediately. This feature comes from "Microsoft Defender for Office 365". Also disables any scanning for potential phishing sites, see also https://learn.microsoft.com/en-us/microsoft-365/security/office-365-security/safe-links-about?view=o365-worldwide
// @license     CC-BY-2.0
// @version     1
// @grant       none
// @run-at      document-start
// @namespace https://greasyfork.org/users/1167928
// ==/UserScript==

const URL_PATTERN = new RegExp('^https://[a-zA-Z0-9]+\\.safelinks\\.protection\\.outlook\\.com/');

const config = { childList: true, subtree: true, characterData: false, attributes: false };

const onMutate = (mutationList, observer) => {
  for(const mutation of mutationList) {
    for(const addedNode of mutation.addedNodes) {
      for(const anchor of addedNode.querySelectorAll('a')) {
        try {
          if(!URL_PATTERN.test(anchor.href)) continue;
          const params = new URLSearchParams(new URL(anchor.href).search);
          if(!params.has('url')) continue;

          if(anchor.textContent === anchor.href) anchor.textContent = params.get('url');
          anchor.href = params.get('url');
        } catch {}
      }
    }
  }
};

const observer = new MutationObserver(onMutate);
observer.observe(document, config);