-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
55 lines (49 loc) · 1.32 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const safelinksRegex =
/^https:\/\/[^\.]+\.safelinks\.protection\.outlook\.com\/\?/;
const urldefenseRegex = /https:\/\/urldefense.com\/.*?\/__(.*?)__;.*?\$/;
chrome.webRequest.onBeforeRequest.addListener(
function (details) {
var url = details.url;
if (url.includes("salesforce.com")) {
if (url.match(safelinksRegex)) {
url = unSafeLinks(url);
}
if (url.match(urldefenseRegex)) {
url = unUrlDefense(url);
}
url = replaceStars(url);
console.log("Salesforce link unwrapped: " + url);
displayNotification("Salesforce link unwrapped:", url);
}
return { redirectUrl: url };
},
{ urls: ["https://*.safelinks.protection.outlook.com/*"] },
["blocking"]
);
function unSafeLinks(url) {
url = url.replace(safelinksRegex, "");
var terms = url.split("&");
var i;
for (i = 0; i < terms.length; i++) {
var s = terms[i].split("=");
if (s[0] === "url") {
return decodeURIComponent(s[1]);
}
}
}
function unUrlDefense(url) {
return url.replace(urldefenseRegex, "$1");
}
function replaceStars(url) {
return url.replaceAll("*", "%");
}
function displayNotification(title, message) {
var opt = {
iconUrl: "images/cloud-128.png",
type: "basic",
title,
message,
priority: 1,
};
chrome.notifications.create(opt, function () {});
}