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 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Rewrite Microsoft Safe Links
  3. // @include https://outlook.office.com/*
  4. // @author Pieter Bos
  5. // @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
  6. // @license CC-BY-2.0
  7. // @version 1
  8. // @grant none
  9. // @run-at document-start
  10. // @namespace https://greasyfork.org/users/1167928
  11. // ==/UserScript==
  12.  
  13. const URL_PATTERN = new RegExp('^https://[a-zA-Z0-9]+\\.safelinks\\.protection\\.outlook\\.com/');
  14.  
  15. const config = { childList: true, subtree: true, characterData: false, attributes: false };
  16.  
  17. const onMutate = (mutationList, observer) => {
  18. for(const mutation of mutationList) {
  19. for(const addedNode of mutation.addedNodes) {
  20. for(const anchor of addedNode.querySelectorAll('a')) {
  21. try {
  22. if(!URL_PATTERN.test(anchor.href)) continue;
  23. const params = new URLSearchParams(new URL(anchor.href).search);
  24. if(!params.has('url')) continue;
  25.  
  26. if(anchor.textContent === anchor.href) anchor.textContent = params.get('url');
  27. anchor.href = params.get('url');
  28. } catch {}
  29. }
  30. }
  31. }
  32. };
  33.  
  34. const observer = new MutationObserver(onMutate);
  35. observer.observe(document, config);