-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
76 lines (64 loc) · 2.32 KB
/
content.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
const toxicComments = [];
let currentFontSize = 60;
const storage = chrome.storage;
async function analyzeParagraph(paragraph) {
console.log('analyzing paragraph:', paragraph.innerText.trim());
chrome.runtime.sendMessage({
method: 'analyzeParagraph',
paragraph: paragraph.innerText.trim()
}, function (response) {
console.log('response received:', response);
if (response.isToxic) {
// If the paragraph is deemed toxic, highlight it in yellow
paragraph.style.backgroundColor = '#FBFF49';
paragraph.style.color = 'black';
paragraph.style.fontSize = '100px';
paragraph.style.fontWeight = 'bold';
paragraph.style.fontSize = '60px';
paragraph.style.lineHeight = '68px';
paragraph.style.padding = '12px';
toxicComments.push(paragraph.innerText.trim());
console.log("pushed paragraph", paragraph.innerText.trim())
paragraph.classList.add('bounce');
}
});
}
// Get all paragraphs on the page
const paragraphs = document.querySelectorAll('p,span')
// Loop through the paragraphs and analyze each one for toxicity
for (let i = 0; i < paragraphs.length; i++) {
const paragraph = paragraphs[i];
const text = paragraph.innerText.trim();
if (text.length > 0) {
analyzeParagraph(paragraph);
}
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.method === 'setFontSize') {
const paragraphs = document.getElementsByTagName('p');
for (let i = 0; i < paragraphs.length; i++) {
const paragraph = paragraphs[i].innerText.trim();
if (toxicComments.includes(paragraph)) {
paragraphs[i].style.fontSize = `${request.fontSize}px`;
currentFontSize = request.fontSize;
paragraphs[i].style.lineHeight = `${currentFontSize * 1.1}px`;
}
}
}
});
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.method == "getSelection") {
sendResponse({ selection: window.getSelection().toString() });
} else {
sendResponse({});
}
});
function saveComment(comment) {
chrome.storage.sync.get('savedComments', function (data) {
const savedComments = data.savedComments || [];
savedComments.push(comment);
chrome.storage.sync.set({ savedComments }, function () {
chrome.runtime.sendMessage({ method: 'updatePopup' });
});
});
}