-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhateDetect.js
27 lines (26 loc) · 1.09 KB
/
hateDetect.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
function markSelectedText(replacementText, backgroundColor, analysis) {
var sel, range;
if (window.getSelection) {
sel = window.getSelection();
if (sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
let markNode = document.createElement("mark");
markNode.setAttribute('title', analysis);
let textNode = document.createTextNode(replacementText);
markNode.appendChild(textNode);
markNode.style.backgroundColor = backgroundColor;
range.insertNode(markNode);
}
} else if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
range.text = replacementText;
}
}
chrome.storage.local.get('selectionText', function (selectionText) {
chrome.storage.local.get('backgroundColor', function (backgroundColor) {
chrome.storage.local.get('analysis', function (analysis) {
markSelectedText(selectionText.selectionText, backgroundColor.backgroundColor, analysis.analysis);
});
});
});