-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
85 lines (77 loc) · 3.04 KB
/
Copy pathcontent.js
File metadata and controls
85 lines (77 loc) · 3.04 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Inform the background page that
* this tab should have a page-action
*/
chrome.runtime.sendMessage({
from: 'content',
subject: 'showPageAction'
});
/*
* Send a message to the background script to signal that we want the
* background to trigger an update to the email's body that would remove
* any applied highlighting.
*
* @return None.
*/
function getOriginalHTML() {
console.log("Now grabbing original html...");
chrome.storage.sync.get(['originalHtml'], function(result) {
msgBody = document.querySelector('div[aria-label="Message Body"]');
html = msgBody.innerHTML;
console.log("HTML being replaced: " + html);
if(html.includes("</span>")) {
chrome.runtime.sendMessage({from: 'content', subject: 'triggerReplacement', original: result.originalHtml});
}
});
}
/*
* Listen for messages from the popup
*/
chrome.runtime.onMessage.addListener(function(msg, sender, response) {
console.log("Message sent to content script");
console.log(msg);
msgBody = document.querySelector('div[aria-label="Message Body"]');
if(msgBody === null) {
throw new Error("Unable to locate DOM element used for email body");
}
let domInfo = {
textWithoutMarkup: msgBody.innerText,
textWithMarkup: msgBody.innerHTML
};
if((msg.from === 'popup') &&
(msg.subject === 'analyzeTone' || msg.subject === 'cleanText')) {
response(domInfo);
}
else if((msg.from === "popup") && (msg.subject === "EmailBodyUpdate")) {
msgBody.innerHTML = msg.coloredText;
let toneNotes = document.getElementsByClassName("toneNote");
for (let i = 0; i < toneNotes.length; i++) {
toneNotes[i].style.visibility = "hidden";
toneNotes[i].style.width = "120px";
toneNotes[i].style.backgroundColor = "black";
toneNotes[i].style.color = "#fff";
toneNotes[i].style.textAlign = "center";
toneNotes[i].style.borderRadius = "6px";
toneNotes[i].style.position = "absolute";
toneNotes[i].style.zIndex = "1";
}
let analyzedTextBuckets = document.getElementsByClassName("analyzedText");
for (let i = 0; i < analyzedTextBuckets.length; i++) {
analyzedTextBuckets[i].onmouseover = function(event) {
event.currentTarget.nextElementSibling.style.visibility = "visible";
};
analyzedTextBuckets[i].onmouseout = function(event) {
event.currentTarget.nextElementSibling.style.visibility = "hidden";
};
}
let divReplacements = document.getElementsByClassName("rp");
for (let i = 0; i < divReplacements; i++) {
divReplacements[i].style.display = "block";
}
}
else if((msg.from === "popup") && (msg.subject === "attachCleaningHandler")) {
console.log("About to attach event listener");
msgBody.addEventListener("click", getOriginalHTML);
console.log("Event listener to clean should now be attached");
}
});