-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
140 lines (130 loc) · 5.39 KB
/
Copy pathscript.js
File metadata and controls
140 lines (130 loc) · 5.39 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//watch arrays in data.js
(function(){
'use strict';
//function which defines a part of speech
button.addEventListener('click',function(){
const text = inputField.value;//capturing text inside input field
//clearing output field from previous output
let outputField = document.querySelector('#output');
outputField.innerHTML = '';
const sentences = text.split(separators).filter(Boolean);//spliting text by regular regex and deleting the empty elements
const wordArrays = sentences.map(sentence => sentence.split(' '));//spliting sentences into words
//function for comparing words with arrays
const condition = (partOfSpeech) => (word) => (compareWith) => {
const cleanWord = word.replace(/^[^\wА-Яа-яіІїЇєЄ]+|[^\wА-Яа-яіІїЇєЄ]+$/g, '').toLowerCase();//clearing words from dots, comas etc.
let truly = null;
//comparing words with arrays
switch (compareWith) {
case 'ending':
if(partOfSpeech.some(element => cleanWord.endsWith(element) && (element.length < cleanWord.length))){
truly = true;
};
break;
case 'whole':
if(partOfSpeech.includes(cleanWord)){
truly = true;
};
break;
case 'prefix':
if(partOfSpeech.some(element => cleanWord.startsWith(element) && (element.length < cleanWord.length))){
truly = true;
};
break;
};
return truly;
};
//function for outputing words into output field and console; assign classes to words
const output = (word) => (myClass) => {
if(myClass === 'undefined'){
console.log(`word "${word}" is undefined`);
outputField.innerHTML += `<span class=${myClass}>${word} </span>`
}
else{
console.log(`word "${word}" is ${myClass}`);
outputField.innerHTML += `<span class=${myClass}>${word} </span>`
}
};
//defining a part of speech of word
wordArrays.forEach((words) => {
words.forEach((word) => {
switch (true) {
case !isNaN(parseFloat(word)):
output (word)('numerator');
break;
case condition (prepositions)(word)('whole'):
output (word)('preposition');
break;
case condition (pronouns)(word)('whole'):
output (word)('pronoun');
break;
case condition (verbs)(word)('whole'):
output (word)('verb');
break;
case condition (adverbs)(word)('whole'):
output (word)('adverb');
break;
case condition (particles)(word)('whole'):
output (word)('particle');
break;
case condition (conjunctives)(word)('whole'):
output (word)('conjunctive');
break;
case condition (numerators)(word)('whole'):
output (word)('numerator');
break;
case condition (adverbsPref)(word)('prefix'):
output (word)('adverb');
break;
case condition (numeratorsPref)(word)('prefix'):
output (word)('numerator');
break;
case condition (pronounsPref)(word)('prefix'):
output (word)('pronoun');
break;
case condition (adjectivesEnds)(word)('ending'):
output (word)('adjective');
break;
case condition (prepositionsEnds)(word)('ending'):
output (word)('preposition');
break;
case condition (pronounsEnds)(word)('ending'):
output (word)('pronoun');
break;
case condition (numeratorsEnds)(word)('ending'):
output (word)('numerator');
break;
case condition (adverbsEnds)(word)('ending'):
output (word)('adverb');
break;
case condition (verbsEnds)(word)('ending'):
output (word)('verb');
break;
case condition (nounsEnds)(word)('ending'):
output (word)('noun');
break;
default:
output (word)('undefined');
break;
}
});
});
});
//function which activates the function above, when the key "enter" is pressed
inputField.addEventListener('keypress', function(event) {
if (event.keyCode === 13) {
button.click();
}
});
//changing page theme
select.addEventListener('change', function() {
if (this.value === 'light') {
contents.forEach(element => {
element.classList.add('light-mode');
});
} else {
contents.forEach(element => {
element.classList.remove('light-mode');
});
}
});
})()