-
Notifications
You must be signed in to change notification settings - Fork 9
/
content_script.js
46 lines (37 loc) · 1.56 KB
/
content_script.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
// Function to execute the 20-20-20 rule
function executeTwentyTwentyTwentyRule() {
// Get all the elements on the page
const elements = document.getElementsByTagName('*');
// Iterate through each element
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
// Apply the rule to text elements
if (element instanceof Text) {
const text = element.textContent;
// Split the text into words
const words = text.split(' ');
// Iterate through each word
for (let j = 0; j < words.length; j++) {
const word = words[j];
// Apply the rule to words longer than 3 characters
if (word.length > 3) {
// Replace the word with the modified word
words[j] = word.substring(0, 3) + '-' + word.substring(3);
}
}
// Join the modified words back into a single string
const modifiedText = words.join(' ');
// Replace the original text with the modified text
element.textContent = modifiedText;
}
}
}
// Listen for changes to the eye protection state
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message.type === "enableEyeProtection") {
executeTwentyTwentyTwentyRule();
} else if (message.type === "disableEyeProtection") {
}
});
// Execute the 20-20-20 rule when the page finishes loading
window.addEventListener('load', executeTwentyTwentyTwentyRule);