-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgmail_safe_compose.js
More file actions
70 lines (60 loc) · 2.36 KB
/
gmail_safe_compose.js
File metadata and controls
70 lines (60 loc) · 2.36 KB
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
(function () {
const GSC_STYLE = '__GSC__';
const GSC_POLLING_DELAY = 500;
if (typeof String.prototype.endsWith !== 'function') {
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
}
if (typeof HTMLElement.prototype.highlight !== 'function') {
HTMLElement.prototype.highlight = function () {
if (this.className.indexOf(GSC_STYLE) === -1) {
this.className += ' ' + GSC_STYLE;
}
};
}
if (typeof HTMLElement.prototype.unhighlight !== 'function') {
HTMLElement.prototype.unhighlight = function () {
if (this.className.indexOf(GSC_STYLE) !== -1) {
this.className = this.className.replace(' ' + GSC_STYLE, '');
}
};
}
var composeWindows = [];
var highlightEmailAddressesOutsideOfSenderDomain = function () {
for (var i = 0; i < composeWindows.length; i++) {
var composeWindow = composeWindows[i];
var from = composeWindow.querySelector("input[name=from]").value;
var senderDomain = from.replace(/.*@/, '@');
var emailSpans = composeWindow.querySelectorAll('span[email]');
for (var j = 0; j < emailSpans.length; j++) {
var emailSpan = emailSpans[j];
var childDiv = emailSpan.querySelector('div');
if (emailSpan.getAttribute('email').endsWith(senderDomain)) {
emailSpan.unhighlight();
if (childDiv) {
childDiv.unhighlight();
}
}
else {
emailSpan.highlight();
if (childDiv) {
childDiv.highlight();
}
}
}
}
window.setTimeout(highlightEmailAddressesOutsideOfSenderDomain, GSC_POLLING_DELAY);
};
window.setTimeout(highlightEmailAddressesOutsideOfSenderDomain, GSC_POLLING_DELAY);
document.addEventListener('DOMNodeInserted', function (event) {
var source = event.srcElement;
if (!source.getElementsByTagName) {
return;
}
var form = source.querySelector('form');
if (form && form.from) {
composeWindows.push(source);
}
});
})();