-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
24 lines (21 loc) · 1004 Bytes
/
main.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
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
try{
var elements = document.querySelectorAll('body p, body h1, body h2, body h3, body h4, body h5, body h6, body span, body a');
elements.forEach(element => {
const textContent = element.textContent;
if (textContent !== null) {
const regex = new RegExp('hate speech', 'gi');
if (textContent.match(regex)) {
element.innerHTML = element.innerHTML.replace(regex, '<span style="background-color: yellow; color: black">*censored*</span>');
if (element.tagName.toLowerCase() === 'a')
element.setAttribute('href', element.getAttribute('href'));
}
}
});
const button = document.getElementById('block-button');
button.textContent = 'Blocked!';
}
catch (error){
console.log(error);
}
});