|
// ==UserScript== |
|
// @name ms-teams-links |
|
// @namespace https://github.com/d-rk |
|
// @version 0.2 |
|
// @description replace links to MS Teams in Google Calendar/Mail with msteams:// protocol |
|
// @author Dirk Wilden <[email protected]> |
|
// @match https://calendar.google.com/* |
|
// @match https://mail.google.com/* |
|
// @icon data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎯</text></svg> |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
(function() { |
|
'use strict'; |
|
|
|
function getParameterByName(name, url) { |
|
name = name.replace(/[\[\]]/g, '\\$&'); |
|
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), |
|
results = regex.exec(url); |
|
if (!results) return null; |
|
if (!results[2]) return ''; |
|
return decodeURIComponent(results[2].replace(/\+/g, ' ')); |
|
} |
|
|
|
function modifyLinks() { |
|
|
|
document.querySelectorAll("a[target=_blank]").forEach(linkElement => { |
|
|
|
if (linkElement.href.includes("teams.microsoft.com")) { |
|
linkElement.href = linkElement.href.replace("https", "msteams"); |
|
delete linkElement.dataset.saferedirecturl; |
|
return; |
|
} |
|
|
|
|
|
if (!linkElement.href.startsWith("https://www.google.com/url?q=")) { |
|
return; |
|
} |
|
|
|
const q = getParameterByName('q', linkElement.href); |
|
|
|
if (q !== null) { |
|
if (q.startsWith("https://teams.microsoft.com")) { |
|
linkElement.href = q.replace("https", "msteams"); |
|
} |
|
} |
|
}); |
|
} |
|
|
|
let observer = new MutationObserver((mutations) => { |
|
mutations.forEach((mutation) => { |
|
let oldValue = mutation.oldValue; |
|
let newValue = mutation.target.textContent; |
|
if (oldValue !== newValue) { |
|
modifyLinks(); |
|
} |
|
}); |
|
}); |
|
|
|
observer.observe(document.body, { |
|
characterDataOldValue: false, |
|
characterData: false, |
|
subtree: true, |
|
childList: true |
|
}); |
|
})(); |