-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentScript.js
79 lines (67 loc) · 2.35 KB
/
contentScript.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
71
72
73
74
75
76
77
78
79
console.log('Content script loaded');
(function() {
console.log('Email Categorizer Content Script Loaded');
function processEmails() {
const emailItems = document.querySelectorAll('tr.zA');
emailItems.forEach((emailItem) => {
if (emailItem.getAttribute('data-processed')) return;
emailItem.setAttribute('data-processed', 'true');
const subjectElement = emailItem.querySelector('.bog');
const snippetElement = emailItem.querySelector('.y2');
const senderElement = emailItem.querySelector('.yP, .zF'); // Added this line
const subject = subjectElement ? subjectElement.innerText : '';
const snippet = snippetElement ? snippetElement.innerText : '';
const sender = senderElement ? senderElement.innerText : ''; // Added this line
const emailContent = `${snippet}`;
chrome.runtime.sendMessage(
{
action: 'categorizeEmail',
content: emailContent,
subject: subject,
sender: sender // Added this line
},
(response) => {
console.log('Categorization response:', response);
if (response && response.category) {
applyLabel(emailItem, response.category);
}
}
);
});
}
function applyLabel(emailItem, category) {
const labelSpan = document.createElement('span');
labelSpan.innerText = category;
labelSpan.className = 'email-category-label';
switch (category.toLowerCase()) {
case 'rejection':
labelSpan.style.backgroundColor = '#ff4c4c';
break;
case 'acceptance':
labelSpan.style.backgroundColor = '#4caf50';
break;
case 'interview':
labelSpan.style.backgroundColor = '#2196f3';
break;
case 'assessment':
labelSpan.style.backgroundColor = '#ff9800';
break;
case 'applicant':
labelSpan.style.backgroundColor = '#e91e63';
break;
case 'job alerts':
labelSpan.style.backgroundColor = '#00bcd4';
break;
case 'n':
labelSpan.style.backgroundColor = '#9c27b0';
break;
case 'not job-related':
labelSpan.style.backgroundColor = '#9e9e9e';
break;
default:
labelSpan.style.backgroundColor = '#9e9e9e';
}
emailItem.querySelector('.yW').appendChild(labelSpan);
}
setInterval(processEmails, 5000);
})();