Skip to content

Instantly share code, notes, and snippets.

@fallaciousreasoning
Last active January 15, 2020 05:34
Show Gist options
  • Save fallaciousreasoning/3d0928be6f26778548de2d84778c3bb8 to your computer and use it in GitHub Desktop.
Save fallaciousreasoning/3d0928be6f26778548de2d84778c3bb8 to your computer and use it in GitHub Desktop.
A ViolentMonkey/GreaseMonkey/TamperMonkey script for opening mailto: links in Outlook.com
// ==UserScript==
// @name Outlook mailto: Handler
// @namespace Violentmonkey Scripts
// @match https://outlook.live.com/*
// @grant none
// @version 0.0.2.20190821021306
// @updateUrl https://gist.githubusercontent.com/fallaciousreasoning/3d0928be6f26778548de2d84778c3bb8/raw/mailto:outlook.com.js
// @description Let's Outlook.com open mailto: links
// ==/UserScript==
navigator.registerProtocolHandler("mailto",
"https://outlook.live.com/mail/0/deeplink/compose?mailto=%s",
"Outlook");
const isMailToHandler = () => {
const params = new URLSearchParams(window.location.search);
const mailto = params.get('mailto');
if (!mailto)
return false;
const sansScheme = mailto.split(':')[1];
const [to, queryString] = sansScheme.split('?');
const queryParams = new URLSearchParams(queryString);
queryParams.append('to', to);
// Convert keys to lower case (or Outlook doesn't recognise them).
for (const [key, value] of queryParams) {
queryParams.delete(key);
queryParams.set(key.toLowerCase(), value);
}
return queryParams.toString();
}
const mailToSearch = isMailToHandler();
if (mailToSearch) {
window.location.search = mailToSearch;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment