forked from cmda-minor-web/human-centered-design-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword.js
55 lines (45 loc) · 1.87 KB
/
word.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
const testDialog = document.querySelectorAll('main p')
const splitTest = testDialog[3].textContent.split(' ');
const dialog = testDialog[3].textContent
// console.log(splitTest);
// setTimeout(setColor(), 3000);
// splitTest.forEach(element => {
// setTimeout(setColor(element), 3000)
// // element.style.color = "green";
// // setTimeOut
// })
function loopThroughSplittedText(splitTest, dialog) {
let newDialog = '';
for (var i = 0; i < splitTest.length; i++) {
(function (i) {
setTimeout(function () {
// let str = dialog.split(' ')
// let newDialog = ''
// function checkWord(word, check, p) {
// let rightWord = ''
// let paragraph = p
// word.forEach(element => {
// if (element === check) {
// rightWord = element
// paragraph = p.replace(rightWord, "<span class='testClass'>" + rightWord + "</span>");
// return paragraph
// }
// })
// return paragraph;
// }
const newWord = "<span class='testClass'>" + splitTest[i] + "</span>"
// console.log('something new', newWord)
dialog = dialog.replace(splitTest[i], "<span class='testClass'>" + splitTest[i] + "</span>");
// newDialog = checkWord(str, splitTest[i], dialog);
const oldDialog = testDialog[3]
oldDialog.innerHTML = dialog
// console.log(oldDialog.innerHTML)
}, 500 * i);
// return newDialog
})(i);
// return newDialog
};
return newDialog
}
loopThroughSplittedText(splitTest, dialog);
// const newDialog = loopThroughSplittedText(splitTest, dialog);