-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
139 lines (126 loc) · 5.37 KB
/
index.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Undo Office 365 - Decoders & More</title>
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png">
<link href="https://cdn.jcu.edu.au/cookbook/3.2.2/css/cookbook.min.css" rel="stylesheet" integrity="sha512-FO5oTaibfzeCU3JDP4wazeEiKH7dwN78KTVguJWPv8LRfO8hH5LTh8NCV4YpVB0TZ9rlQiNyrqcfu5xNlvvSiw==" crossorigin="anonymous">
<link href="https://cdn.jcu.edu.au/cookbook/3.2.2/css/fonts.min.css" rel="stylesheet" integrity="sha512-Zs0rFYewwr7t9jnNGZHTOvfgs1rq+KsnKPCgElX7AsJlawkJmfvuKlQHv8TBN++3NAvSRnEumRdFseu10KjpNQ==" crossorigin="anonymous">
<link href="https://cdn.jcu.edu.au/cookbook/3.2.2/css/materialdesignicons.min.css" rel="stylesheet" integrity="sha512-0PPiSTgirm6/hBvwdqz2WKOXDgP/jXs1cPdfgWzE+bZPZgYIcElYpfVKe/SvAgMsAWT6ibi+f6bPlUGRbKjUqQ==" crossorigin="anonymous">
<style>
.border-5 {
border-width: 5px !important;
}
textarea {
width: 100%;
height: 100px;
border: 3px solid #999;
font-family
}
#content {
max-height: 100px;
overflow-y: scroll;
color: var(--gray);
}
</style>
</head>
<body class="py-3">
<div class="container">
<div class="row">
<div class="col">
<div class="border-bottom mb-3 pb-3">
<h1>Office 365 Decoder Tools</h1>
<p class="lead mb-0">Can't read a URL or an email? All tools operate locally within your browser; no data is sent to the server. Use your browser's <em>View Source</em> feature to check the underlying JavaScript code.</p>
</div>
<div class="border-bottom border-5 mb-3 pb-3">
<div class="row mb-2">
<div class="col-12 col-lg-2 lead"><label for="safelink">SafeLinks URL</label></div>
<div class="col">
<textarea class="text-monospace" autofocus id="safelink"></textarea>
<a href="javascript:clearUrl()" class="float-right text-monospace lead">[clear]</a>
</div>
</div>
<div class="row">
<div class="col-12 col-lg-2 lead"><label for="targetUrl">Decoded URL</label></div>
<div class="col">
<textarea class="text-monospace" id="targetUrl">Waiting...</textarea>
</div>
<div class="col">
<a class="text-break" id="targetUrlLink" href="#" target="_blank" rel="noreferrer noopener">Waiting...</a> <span class="mdi mdi-open-in-new" title="Link opens in a new window"></span>
</div>
</div>
</div>
<div class="border-bottom border-5 mb-3 pb-3">
<div class="row mb-3 pb-3 border-bottom">
<div class="col-12 col-lg-2 lead">Email Content</div>
<div class="col">
<div class="py-2" id="content" contenteditable="true">Paste here</div>
</div>
</div>
<div class="row">
<div class="col-12 col-lg-2 lead">Email Output</div>
<div class="col">
<div id="contentOutput">Waiting...</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
function extractUrl(safelink) {
const queryString = safelink.split("?")[1]
if (queryString) {
for (let param of queryString.split("&")) {
const pair = param.split("=")
if (pair[0] == "url") {
return decodeURIComponent(pair[1])
}
}
}
return safelink
}
// Safelink decoder
function clearUrl() {
document.getElementById("safelink").value = ""
document.getElementById("targetUrl").value = document.getElementById("targetUrlLink").href = document.getElementById("targetUrlLink").innerHTML = "Waiting..."
}
function decodeSafelink() {
const safelink = document.getElementById("safelink").value
if (!safelink.length) return
const targetUrl = extractUrl(safelink)
if (targetUrl) {
document.getElementById("targetUrl").value = document.getElementById("targetUrlLink").href = document.getElementById("targetUrlLink").innerHTML = targetUrl
} else {
document.getElementById("targetUrl").value = "Error: couldn't find target URL"
}
}
decodeSafelink()
document.getElementById("safelink").onchange = () => setTimeout(decodeSafelink, 20)
document.getElementById("safelink").onpaste = decodeSafelink
document.getElementById("targetUrl").onclick = function() {
this.focus()
this.select()
}
// Email reader
const urlRe = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%=-]*>))/gi
function selectThis() {
const selection = window.getSelection()
const range = document.createRange()
range.selectNodeContents(this)
selection.removeAllRanges()
selection.addRange(range)
}
document.getElementById("content").onclick = selectThis
document.getElementById("content").onpaste = (event) => {
const paste = (event.clipboardData || window.clipboardData).getData('text/html')
const content = paste
.replace(/ data-saferedirecturl=".*?"/gi, '') // Remove unnecessary attribute
.replace(/<wbr>/gi, '') // Remove breaks from visible URLs in content
.replace(/<span class="il">(.*?)<\/span>/gi, '$1') // Remove search highlight spans
.replace(urlRe, match => extractUrl(match))
document.getElementById("contentOutput").innerHTML = content
}
</script>
</body>
</html>