-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGMX-Mail-deref-decoder.user.js
70 lines (60 loc) · 2.13 KB
/
GMX-Mail-deref-decoder.user.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// ==UserScript==
// @name URL Decoder and Rewriter Tampermonkey Script
// @namespace http://your-namespace-here
// @version 0.1
// @description Decodes and rewrites URLs on the current webpage using Tampermonkey script
// @author Your Name
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function decodeAndRewriteUrl(url) {
const regexMail = /https:\/\/deref-mail\.com\/mail\/client\/([a-zA-Z0-9-_]{11})\/dereferrer\/\?redirectUrl=(.+)/;
const regexGMX = /https:\/\/deref-gmx\.net\/mail\/client\/([a-zA-Z0-9-_]{11})\/dereferrer\/\?redirectUrl=(.+)/;
const matchMail = url.match(regexMail);
const matchGMX = url.match(regexGMX);
if (matchMail && matchMail[2]) {
const strippedUrl = matchMail[2];
const decodedUrl = decodeURIComponent(strippedUrl);
return decodedUrl;
}
if (matchGMX && matchGMX[2]) {
const strippedUrl = matchGMX[2];
const decodedUrl = decodeURIComponent(strippedUrl);
return decodedUrl;
}
return null;
}
function injectScript(frame) {
const script = document.createElement('script');
script.textContent = `
(function() {
const links = document.querySelectorAll('a');
for (const link of links) {
const decodedUrl = decodeAndRewriteUrl(link.href);
if (decodedUrl) {
link.href = decodedUrl;
}
}
})();
`;
frame.contentDocument.head.appendChild(script);
}
function handleFrames() {
const frames = document.querySelectorAll('iframe');
for (const frame of frames) {
injectScript(frame);
}
}
// Handle the top-level document
const links = document.querySelectorAll('a');
for (const link of links) {
const decodedUrl = decodeAndRewriteUrl(link.href);
if (decodedUrl) {
link.href = decodedUrl;
}
}
// Handle frames
handleFrames();
})();