-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontentScript.js
47 lines (43 loc) · 1.34 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
let cussWords = [];
// Function to fetch and parse cuss words from CSV file.
function fetchCussWords() {
return fetch(chrome.runtime.getURL("cuss_words.csv"))
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.text();
})
.then(data => {
const lines = data.split('\n');
cussWords = lines.map(line => line.trim()).filter(line => line !== '');
})
.catch(error => {
console.error('Error fetching cuss words:', error);
});
}
// Function to apply a blur effect to the cuss words
function blurCussWords(textNode) {
cussWords.forEach(word => {
const regex = new RegExp(`\\b${word}\\b`, 'gi');
textNode.nodeValue = textNode.nodeValue.replace(regex, match => {
return '*'.repeat(match.length);
});
});
}
// Traverse all text nodes in the document and blur the cuss words
function traverseAndBlur(node) {
if (node.nodeType === Node.TEXT_NODE) {
blurCussWords(node);
} else {
node.childNodes.forEach(childNode => traverseAndBlur(childNode));
}
}
// Start processing the webpage after fetching cuss words
fetchCussWords().then(() => {
chrome.storage.local.get(['extensionActive'], function (result) {
if (result.extensionActive !== false) {
traverseAndBlur(document.body);
}
});
});