This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
62 lines (57 loc) · 2 KB
/
sketch.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
let text;
let words;
let container;
let bad;
let essay;
function setup() {
noCanvas();
words = createElement("textarea").attribute("placeholder", "Type all the words you don't want in the essay").style("width", "12vw").style("height", "25vh").style("font-family", "sans-serif").value("I\nme\nmy\nmine\nwe\nus\nour\nours\nyou\nyour\nyours\nin conclusion\nthis shows that\nso\nbut");
text = createElement("textarea").attribute("placeholder", "Copy/paste your essay here").changed(search).style("width", "32vw").style("height", "25vh").style("font-family", "sans-serif");
container = createDiv();
}
function search() {
container.elt.innerHTML = "";
bad = words.value().split("\n");
for (let i = 0; i < bad.length; i++) {
bad[i] = bad[i].toLowerCase();
}
essay = text.value().split("\n")
for (let i = 0; i < essay.length; i++) {
essay[i] = essay[i].split(" ");
}
createElement("br").parent(container);
for (let i = 0; i < essay.length; i++) {
for (let j = 0; j < essay[i].length; j++) {
if (checkall(i, j)[0]) {
createSpan(essay[i][j] + " ").style("color", "rgb(235, 51, 51)").style("font-family", "sans-serif").parent(container);
} else {
createSpan(essay[i][j] + " ").style("color", "rgb(51, 51, 51)").style("font-family", "sans-serif").parent(container);
}
}
createElement("br").parent(container);
}
}
function wordAgainstPhrase(word1, word2, phrase) {
console.log(bad[phrase].split(" ").length);
if (essay[word1][word2].toLowerCase() == bad[phrase].toLowerCase()) {
return true;
} else if (bad[phrase].split(" ") > 1) {
let pts = 0;
for (let i = 0; i < bad[phrase].split(" ").length; i++) {
if (essay[word1][word2+i] !== bad[phrase].split(" ")[i]) {
return false;
}
}
return true;
} else {
return false;
}
}
function checkall(word1, word2) {
for (let i = 0; i < bad.length; i++) {
if (wordAgainstPhrase(word1, word2, i)) {
return [true, bad[i].split(" ").length];
}
}
return [false];
}