-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjn-rsvp-tm.js
88 lines (74 loc) · 2.81 KB
/
jn-rsvp-tm.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// ==UserScript==
// @name Bold First Two Syllables
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Bold the first two syllables (sort of) of every word in every HTML paragraph.
// @author Jose Nunez (@kuantif)
// @downloadURL https://github.com/janunezc/jn-rsvp-web-tampermonkey/blob/master/jn-rsvp-tm.js
// @match https://*.costaricamakers.com/*
// @match https://*.nunez-technologies.com/*
// @match https://*.c9eb.space/*
// @license MIT
// @grant none
// ==/UserScript==
(function() {
'use strict';
const boldFirstTwoSyllables = (word) => {
let syllables = 0;
let boldedWord = '';
for (let i = 0; i < word.length; i++) {
const char = word[i];
boldedWord += char;
if ('aeiouyAEIOUY'.includes(char) && (i === 0 || !'aeiouyAEIOUY'.includes(word[i - 1]))) {
syllables++;
}
if (syllables === 2) {
break;
}
}
return `<strong>${boldedWord}</strong>` + word.slice(boldedWord.length);
};
const processParagraphs = () => {
const paragraphs = document.querySelectorAll('body p');
paragraphs.forEach(paragraph => {
const words = paragraph.textContent.split(' ');
const boldedWords = words.map(boldFirstTwoSyllables);
paragraph.innerHTML = boldedWords.join(' ');
});
};
const restoreOriginalParagraphs = () => {
const paragraphs = document.querySelectorAll('body p');
paragraphs.forEach(paragraph => {
paragraph.innerHTML = paragraph.originalInnerHTML;
});
};
const addButton = () => {
const firstParagraph = document.querySelector('body p');
const button = document.createElement('button');
button.textContent = 'Fast Reading';
button.style.display = 'block';
button.style.marginBottom = '1rem';
let isBolded = false;
button.addEventListener('click', () => {
if (!isBolded) {
processParagraphs();
button.textContent = 'Back to Normal';
} else {
restoreOriginalParagraphs();
button.textContent = 'Fast Reading';
}
isBolded = !isBolded;
});
firstParagraph.parentNode.insertBefore(button, firstParagraph);
};
const storeOriginalParagraphs = () => {
const paragraphs = document.querySelectorAll('body p');
paragraphs.forEach(paragraph => {
paragraph.originalInnerHTML = paragraph.innerHTML;
});
};
setTimeout(() => {
storeOriginalParagraphs();
addButton();
}, 1000); // wait for 1 second before executing the storeOriginalParagraphs and addButton functions
})();