-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
56 lines (50 loc) · 2.02 KB
/
content.js
File metadata and controls
56 lines (50 loc) · 2.02 KB
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
function boldFirstCharacters() {
const elements = document.querySelectorAll('p, blockquote, span');
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
if (element.innerText.trim().length < 100) {
continue; // Skip elements with less than 40 characters
}
element.style.fontFamily = "Calibri";
element.style.fontWeight = 300;
const childNodes = element.childNodes;
for (let j = 0; j < childNodes.length; j++) {
const node = childNodes[j];
if (node.nodeType === Node.TEXT_NODE && node.parentNode.tagName !== 'A') {
const words = node.textContent.trim().split(/\s+/);
for (let k = 0; k < words.length; k++) {
const word = words[k];
if (word.length <= 2) {
continue; // Skip words with 2 or fewer characters
}
let numCharsToBold = Math.min(Math.floor(word.length / 2), 5);
if (numCharsToBold < 2) {
numCharsToBold = 1;
}
const firstChars = word.substring(0, numCharsToBold);
const remainingChars = word.substring(numCharsToBold);
words[k] = `<strong>${firstChars}</strong>${remainingChars}`;
}
const newNode = document.createElement('span');
newNode.innerHTML = words.join(' ');
node.parentNode.replaceChild(newNode, node);
}
}
// element.style.textAlign = 'justify'; // Justify the text in the element
const strongElements = element.querySelectorAll('strong');
for (let l = 0; l < strongElements.length; l++) {
strongElements[l].style.fontWeight = 600;
}
}
}
document.addEventListener("DOMContentLoaded", function() {
boldFirstCharacters();
});
// Add event listener for chat-container element
const chatContainer = document.querySelector('.chat-container');
if (chatContainer) {
chatContainer.addEventListener('click', function() {
boldFirstCharacters();
});
}
boldFirstCharacters();